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

Unified Diff: third_party/WebKit/Source/devtools/front_end/cm/comment.js

Issue 2862603003: Revert of DevTools: Roll CodeMirror to 5.25.1
Patch Set: Created 3 years, 8 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
Index: third_party/WebKit/Source/devtools/front_end/cm/comment.js
diff --git a/third_party/WebKit/Source/devtools/front_end/cm/comment.js b/third_party/WebKit/Source/devtools/front_end/cm/comment.js
index 568e639dcd3d46d28e3d20888ca332b1522c2f4f..2c4f975d08f59cc3f2e5d4d5a9933ef2c1ec5cc8 100644
--- a/third_party/WebKit/Source/devtools/front_end/cm/comment.js
+++ b/third_party/WebKit/Source/devtools/front_end/cm/comment.js
@@ -46,17 +46,12 @@
// Rough heuristic to try and detect lines that are part of multi-line string
function probablyInsideString(cm, pos, line) {
- return /\bstring\b/.test(cm.getTokenTypeAt(Pos(pos.line, 0))) && !/^[\'\"\`]/.test(line)
+ return /\bstring\b/.test(cm.getTokenTypeAt(Pos(pos.line, 0))) && !/^[\'\"`]/.test(line)
}
- function getMode(cm, pos) {
- var mode = cm.getMode()
- return mode.useInnerComments === false || !mode.innerMode ? mode : cm.getModeAt(pos)
- }
-
CodeMirror.defineExtension("lineComment", function(from, to, options) {
if (!options) options = noOptions;
- var self = this, mode = getMode(self, from);
+ var self = this, mode = self.getModeAt(from);
var firstLine = self.getLine(from.line);
if (firstLine == null || probablyInsideString(self, from, firstLine)) return;
@@ -100,7 +95,7 @@
CodeMirror.defineExtension("blockComment", function(from, to, options) {
if (!options) options = noOptions;
- var self = this, mode = getMode(self, from);
+ var self = this, mode = self.getModeAt(from);
var startString = options.blockCommentStart || mode.blockCommentStart;
var endString = options.blockCommentEnd || mode.blockCommentEnd;
if (!startString || !endString) {
@@ -108,7 +103,6 @@
self.lineComment(from, to, options);
return;
}
- if (/\bcomment\b/.test(self.getTokenTypeAt(Pos(from.line, 0)))) return
var end = Math.min(to.line, self.lastLine());
if (end != from.line && to.ch == 0 && nonWS.test(self.getLine(end))) --end;
@@ -134,7 +128,7 @@
CodeMirror.defineExtension("uncomment", function(from, to, options) {
if (!options) options = noOptions;
- var self = this, mode = getMode(self, from);
+ var self = this, mode = self.getModeAt(from);
var end = Math.min(to.ch != 0 || to.line == from.line ? to.line : to.line - 1, self.lastLine()), start = Math.min(from.line, end);
// Try finding line comments
@@ -146,7 +140,7 @@
var line = self.getLine(i);
var found = line.indexOf(lineString);
if (found > -1 && !/comment/.test(self.getTokenTypeAt(Pos(i, found + 1)))) found = -1;
- if (found == -1 && nonWS.test(line)) break lineComment;
+ if (found == -1 && (i != end || i == start) && nonWS.test(line)) break lineComment;
if (found > -1 && nonWS.test(line.slice(0, found))) break lineComment;
lines.push(line);
}
@@ -168,19 +162,15 @@
var endString = options.blockCommentEnd || mode.blockCommentEnd;
if (!startString || !endString) return false;
var lead = options.blockCommentLead || mode.blockCommentLead;
- var startLine = self.getLine(start), open = startLine.indexOf(startString)
- if (open == -1) return false
- var endLine = end == start ? startLine : self.getLine(end)
- var close = endLine.indexOf(endString, end == start ? open + startString.length : 0);
+ var startLine = self.getLine(start), endLine = end == start ? startLine : self.getLine(end);
+ var open = startLine.indexOf(startString), close = endLine.lastIndexOf(endString);
if (close == -1 && start != end) {
endLine = self.getLine(--end);
- close = endLine.indexOf(endString);
- }
- var insideStart = Pos(start, open + 1), insideEnd = Pos(end, close + 1)
- if (close == -1 ||
- !/comment/.test(self.getTokenTypeAt(insideStart)) ||
- !/comment/.test(self.getTokenTypeAt(insideEnd)) ||
- self.getRange(insideStart, insideEnd, "\n").indexOf(endString) > -1)
+ close = endLine.lastIndexOf(endString);
+ }
+ if (open == -1 || close == -1 ||
+ !/comment/.test(self.getTokenTypeAt(Pos(start, open + 1))) ||
+ !/comment/.test(self.getTokenTypeAt(Pos(end, close + 1))))
return false;
// Avoid killing block comments completely outside the selection.

Powered by Google App Engine
This is Rietveld 408576698