OLD | NEW |
1 // CodeMirror, copyright (c) by Marijn Haverbeke and others | 1 // CodeMirror, copyright (c) by Marijn Haverbeke and others |
2 // Distributed under an MIT license: http://codemirror.net/LICENSE | 2 // Distributed under an MIT license: http://codemirror.net/LICENSE |
3 | 3 |
4 (function(mod) { | 4 (function(mod) { |
5 if (typeof exports == "object" && typeof module == "object") // CommonJS | 5 if (typeof exports == "object" && typeof module == "object") // CommonJS |
6 mod(require("../../lib/codemirror")); | 6 mod(require("../../lib/codemirror")); |
7 else if (typeof define == "function" && define.amd) // AMD | 7 else if (typeof define == "function" && define.amd) // AMD |
8 define(["../../lib/codemirror"], mod); | 8 define(["../../lib/codemirror"], mod); |
9 else // Plain browser env | 9 else // Plain browser env |
10 mod(CodeMirror); | 10 mod(CodeMirror); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 } else { | 102 } else { |
103 self.replaceRange(endString, to); | 103 self.replaceRange(endString, to); |
104 self.replaceRange(startString, from); | 104 self.replaceRange(startString, from); |
105 } | 105 } |
106 }); | 106 }); |
107 }); | 107 }); |
108 | 108 |
109 CodeMirror.defineExtension("uncomment", function(from, to, options) { | 109 CodeMirror.defineExtension("uncomment", function(from, to, options) { |
110 if (!options) options = noOptions; | 110 if (!options) options = noOptions; |
111 var self = this, mode = self.getModeAt(from); | 111 var self = this, mode = self.getModeAt(from); |
112 var end = Math.min(to.line, self.lastLine()), start = Math.min(from.line, en
d); | 112 var end = Math.min(to.ch != 0 || to.line == from.line ? to.line : to.line -
1, self.lastLine()), start = Math.min(from.line, end); |
113 | 113 |
114 // Try finding line comments | 114 // Try finding line comments |
115 var lineString = options.lineComment || mode.lineComment, lines = []; | 115 var lineString = options.lineComment || mode.lineComment, lines = []; |
116 var pad = options.padding == null ? " " : options.padding, didSomething; | 116 var pad = options.padding == null ? " " : options.padding, didSomething; |
117 lineComment: { | 117 lineComment: { |
118 if (!lineString) break lineComment; | 118 if (!lineString) break lineComment; |
119 for (var i = start; i <= end; ++i) { | 119 for (var i = start; i <= end; ++i) { |
120 var line = self.getLine(i); | 120 var line = self.getLine(i); |
121 var found = line.indexOf(lineString); | 121 var found = line.indexOf(lineString); |
122 if (found > -1 && !/comment/.test(self.getTokenTypeAt(Pos(i, found + 1))
)) found = -1; | 122 if (found > -1 && !/comment/.test(self.getTokenTypeAt(Pos(i, found + 1))
)) found = -1; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 var line = self.getLine(i), found = line.indexOf(lead); | 174 var line = self.getLine(i), found = line.indexOf(lead); |
175 if (found == -1 || nonWS.test(line.slice(0, found))) continue; | 175 if (found == -1 || nonWS.test(line.slice(0, found))) continue; |
176 var foundEnd = found + lead.length; | 176 var foundEnd = found + lead.length; |
177 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; |
178 self.replaceRange("", Pos(i, found), Pos(i, foundEnd)); | 178 self.replaceRange("", Pos(i, found), Pos(i, foundEnd)); |
179 } | 179 } |
180 }); | 180 }); |
181 return true; | 181 return true; |
182 }); | 182 }); |
183 }); | 183 }); |
OLD | NEW |