OLD | NEW |
| 1 // CodeMirror, copyright (c) by Marijn Haverbeke and others |
| 2 // Distributed under an MIT license: http://codemirror.net/LICENSE |
| 3 |
1 (function(mod) { | 4 (function(mod) { |
2 if (typeof exports == "object" && typeof module == "object") // CommonJS | 5 if (typeof exports == "object" && typeof module == "object") // CommonJS |
3 mod(require("../../lib/codemirror")); | 6 mod(require("../../lib/codemirror")); |
4 else if (typeof define == "function" && define.amd) // AMD | 7 else if (typeof define == "function" && define.amd) // AMD |
5 define(["../../lib/codemirror"], mod); | 8 define(["../../lib/codemirror"], mod); |
6 else // Plain browser env | 9 else // Plain browser env |
7 mod(CodeMirror); | 10 mod(CodeMirror); |
8 })(function(CodeMirror) { | 11 })(function(CodeMirror) { |
9 "use strict"; | 12 "use strict"; |
10 | 13 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 var open = startLine.indexOf(startString), close = endLine.lastIndexOf(endSt
ring); | 146 var open = startLine.indexOf(startString), close = endLine.lastIndexOf(endSt
ring); |
144 if (close == -1 && start != end) { | 147 if (close == -1 && start != end) { |
145 endLine = self.getLine(--end); | 148 endLine = self.getLine(--end); |
146 close = endLine.lastIndexOf(endString); | 149 close = endLine.lastIndexOf(endString); |
147 } | 150 } |
148 if (open == -1 || close == -1 || | 151 if (open == -1 || close == -1 || |
149 !/comment/.test(self.getTokenTypeAt(Pos(start, open + 1))) || | 152 !/comment/.test(self.getTokenTypeAt(Pos(start, open + 1))) || |
150 !/comment/.test(self.getTokenTypeAt(Pos(end, close + 1)))) | 153 !/comment/.test(self.getTokenTypeAt(Pos(end, close + 1)))) |
151 return false; | 154 return false; |
152 | 155 |
| 156 // Avoid killing block comments completely outside the selection. |
| 157 // Positions of the last startString before the start of the selection, and
the first endString after it. |
| 158 var lastStart = startLine.lastIndexOf(startString, from.ch); |
| 159 var firstEnd = lastStart == -1 ? -1 : startLine.slice(0, from.ch).indexOf(en
dString, lastStart + startString.length); |
| 160 if (lastStart != -1 && firstEnd != -1) return false; |
| 161 // Positions of the first endString after the end of the selection, and the
last startString before it. |
| 162 firstEnd = endLine.indexOf(endString, to.ch); |
| 163 var almostLastStart = endLine.slice(to.ch).lastIndexOf(startString, firstEnd
- to.ch); |
| 164 lastStart = (firstEnd == -1 || almostLastStart == -1) ? -1 : to.ch + almostL
astStart; |
| 165 if (firstEnd != -1 && lastStart != -1) return false; |
| 166 |
153 self.operation(function() { | 167 self.operation(function() { |
154 self.replaceRange("", Pos(end, close - (pad && endLine.slice(close - pad.l
ength, close) == pad ? pad.length : 0)), | 168 self.replaceRange("", Pos(end, close - (pad && endLine.slice(close - pad.l
ength, close) == pad ? pad.length : 0)), |
155 Pos(end, close + endString.length)); | 169 Pos(end, close + endString.length)); |
156 var openEnd = open + startString.length; | 170 var openEnd = open + startString.length; |
157 if (pad && startLine.slice(openEnd, openEnd + pad.length) == pad) openEnd
+= pad.length; | 171 if (pad && startLine.slice(openEnd, openEnd + pad.length) == pad) openEnd
+= pad.length; |
158 self.replaceRange("", Pos(start, open), Pos(start, openEnd)); | 172 self.replaceRange("", Pos(start, open), Pos(start, openEnd)); |
159 if (lead) for (var i = start + 1; i <= end; ++i) { | 173 if (lead) for (var i = start + 1; i <= end; ++i) { |
160 var line = self.getLine(i), found = line.indexOf(lead); | 174 var line = self.getLine(i), found = line.indexOf(lead); |
161 if (found == -1 || nonWS.test(line.slice(0, found))) continue; | 175 if (found == -1 || nonWS.test(line.slice(0, found))) continue; |
162 var foundEnd = found + lead.length; | 176 var foundEnd = found + lead.length; |
163 if (pad && line.slice(foundEnd, foundEnd + pad.length) == pad) foundEnd
+= pad.length; | 177 if (pad && line.slice(foundEnd, foundEnd + pad.length) == pad) foundEnd
+= pad.length; |
164 self.replaceRange("", Pos(i, found), Pos(i, foundEnd)); | 178 self.replaceRange("", Pos(i, found), Pos(i, foundEnd)); |
165 } | 179 } |
166 }); | 180 }); |
167 return true; | 181 return true; |
168 }); | 182 }); |
169 }); | 183 }); |
OLD | NEW |