Index: Source/devtools/front_end/cm/comment.js |
diff --git a/Source/devtools/front_end/cm/comment.js b/Source/devtools/front_end/cm/comment.js |
index 1eb9a05c5d454d35603968e4b98a3dac17610f28..cb78340231d6a36068f749402eb6b8224a3a4eac 100644 |
--- a/Source/devtools/front_end/cm/comment.js |
+++ b/Source/devtools/front_end/cm/comment.js |
@@ -1,3 +1,6 @@ |
+// CodeMirror, copyright (c) by Marijn Haverbeke and others |
+// Distributed under an MIT license: http://codemirror.net/LICENSE |
+ |
(function(mod) { |
if (typeof exports == "object" && typeof module == "object") // CommonJS |
mod(require("../../lib/codemirror")); |
@@ -150,6 +153,17 @@ |
!/comment/.test(self.getTokenTypeAt(Pos(end, close + 1)))) |
return false; |
+ // Avoid killing block comments completely outside the selection. |
+ // Positions of the last startString before the start of the selection, and the first endString after it. |
+ var lastStart = startLine.lastIndexOf(startString, from.ch); |
+ var firstEnd = lastStart == -1 ? -1 : startLine.slice(0, from.ch).indexOf(endString, lastStart + startString.length); |
+ if (lastStart != -1 && firstEnd != -1) return false; |
+ // Positions of the first endString after the end of the selection, and the last startString before it. |
+ firstEnd = endLine.indexOf(endString, to.ch); |
+ var almostLastStart = endLine.slice(to.ch).lastIndexOf(startString, firstEnd - to.ch); |
+ lastStart = (firstEnd == -1 || almostLastStart == -1) ? -1 : to.ch + almostLastStart; |
+ if (firstEnd != -1 && lastStart != -1) return false; |
+ |
self.operation(function() { |
self.replaceRange("", Pos(end, close - (pad && endLine.slice(close - pad.length, close) == pad ? pad.length : 0)), |
Pos(end, close + endString.length)); |