Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1169)

Unified Diff: Source/devtools/front_end/cm/markselection.js

Issue 216973004: DevTools: roll CodeMirror to v4.0.3 (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: support autocomplete with multiselections Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/devtools/front_end/cm/headlesscodemirror.js ('k') | Source/devtools/front_end/cm/matchbrackets.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/devtools/front_end/cm/markselection.js
diff --git a/Source/devtools/front_end/cm/markselection.js b/Source/devtools/front_end/cm/markselection.js
index c97776e492dda6ecd3d321b4407fec7bbe61a25a..ae0d393143845f055178aa1fefdd63038e66eed4 100644
--- a/Source/devtools/front_end/cm/markselection.js
+++ b/Source/devtools/front_end/cm/markselection.js
@@ -4,7 +4,14 @@
// selected text the CSS class given as option value, or
// "CodeMirror-selectedtext" when the value is not a string.
-(function() {
+(function(mod) {
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
+ mod(require("../../lib/codemirror"));
+ else if (typeof define == "function" && define.amd) // AMD
+ define(["../../lib/codemirror"], mod);
+ else // Plain browser env
+ mod(CodeMirror);
+})(function(CodeMirror) {
"use strict";
CodeMirror.defineOption("styleSelectedText", false, function(cm, val, old) {
@@ -34,10 +41,7 @@
var CHUNK_SIZE = 8;
var Pos = CodeMirror.Pos;
-
- function cmp(pos1, pos2) {
- return pos1.line - pos2.line || pos1.ch - pos2.ch;
- }
+ var cmp = CodeMirror.cmpPos;
function coverRange(cm, from, to, addAt) {
if (cmp(from, to) == 0) return;
@@ -63,13 +67,16 @@
function reset(cm) {
clear(cm);
- var from = cm.getCursor("start"), to = cm.getCursor("end");
- coverRange(cm, from, to);
+ var ranges = cm.listSelections();
+ for (var i = 0; i < ranges.length; i++)
+ coverRange(cm, ranges[i].from(), ranges[i].to());
}
function update(cm) {
+ if (!cm.somethingSelected()) return clear(cm);
+ if (cm.listSelections().length > 1) return reset(cm);
+
var from = cm.getCursor("start"), to = cm.getCursor("end");
- if (cmp(from, to) == 0) return clear(cm);
var array = cm.state.markedSelection;
if (!array.length) return coverRange(cm, from, to);
@@ -105,4 +112,4 @@
}
}
}
-})();
+});
« no previous file with comments | « Source/devtools/front_end/cm/headlesscodemirror.js ('k') | Source/devtools/front_end/cm/matchbrackets.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698