OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 var prefix = this._lines[range.startLine].substring(0, range.startColumn
); | 153 var prefix = this._lines[range.startLine].substring(0, range.startColumn
); |
154 var suffix = this._lines[range.startLine].substring(range.startColumn); | 154 var suffix = this._lines[range.startLine].substring(range.startColumn); |
155 | 155 |
156 var postCaret = prefix.length; | 156 var postCaret = prefix.length; |
157 // Insert text. | 157 // Insert text. |
158 if (newLines.length === 1) { | 158 if (newLines.length === 1) { |
159 this._setLine(range.startLine, prefix + newLines[0] + suffix); | 159 this._setLine(range.startLine, prefix + newLines[0] + suffix); |
160 postCaret += newLines[0].length; | 160 postCaret += newLines[0].length; |
161 } else { | 161 } else { |
162 this._setLine(range.startLine, prefix + newLines[0]); | 162 this._setLine(range.startLine, prefix + newLines[0]); |
163 | 163 this._insertLines(range, newLines); |
164 for (var i = 1; i < newLines.length; ++i) | |
165 this._lines.splice(range.startLine + i, 0, newLines[i]); | |
166 // Adjust attributes, attributes move with the first character of li
ne. | |
167 var spliceParameters = new Array(newLines.length + 1); // 2 + number
of items to insert. | |
168 spliceParameters[0] = range.startColumn ? range.startLine + 1 : rang
e.startLine; | |
169 spliceParameters[1] = 0; | |
170 this._attributes.splice.apply(this._attributes, spliceParameters); | |
171 | |
172 this._setLine(range.startLine + newLines.length - 1, newLines[newLin
es.length - 1] + suffix); | 164 this._setLine(range.startLine + newLines.length - 1, newLines[newLin
es.length - 1] + suffix); |
173 postCaret = newLines[newLines.length - 1].length; | 165 postCaret = newLines[newLines.length - 1].length; |
174 } | 166 } |
175 | 167 |
176 return new WebInspector.TextRange(range.startLine, range.startColumn, | 168 return new WebInspector.TextRange(range.startLine, range.startColumn, |
177 range.startLine + newLines.length - 1,
postCaret); | 169 range.startLine + newLines.length - 1,
postCaret); |
178 }, | 170 }, |
179 | 171 |
| 172 _insertLines: function(range, newLines) |
| 173 { |
| 174 var lines = new Array(this._lines.length + newLines.length - 1); |
| 175 for (var i = 0; i <= range.startLine; ++i) |
| 176 lines[i] = this._lines[i]; |
| 177 // Line at [0] is already set via setLine. |
| 178 for (var i = 1; i < newLines.length; ++i) |
| 179 lines[range.startLine + i] = newLines[i]; |
| 180 for (var i = range.startLine + newLines.length; i < lines.length; ++i) |
| 181 lines[i] = this._lines[i - newLines.length + 1]; |
| 182 this._lines = lines; |
| 183 |
| 184 // Adjust attributes, attributes move with the first character of line. |
| 185 var attributes = new Array(lines.length); |
| 186 var insertionIndex = range.startColumn ? range.startLine + 1 : range.sta
rtLine; |
| 187 for (var i = 0; i < insertionIndex; ++i) |
| 188 attributes[i] = this._attributes[i]; |
| 189 for (var i = insertionIndex + newLines.length - 1; i < attributes.length
; ++i) |
| 190 attributes[i] = this._attributes[i - newLines.length + 1]; |
| 191 this._attributes = attributes; |
| 192 }, |
| 193 |
180 _eraseRange: function(range) | 194 _eraseRange: function(range) |
181 { | 195 { |
182 if (range.isEmpty()) | 196 if (range.isEmpty()) |
183 return; | 197 return; |
184 | 198 |
185 var prefix = this._lines[range.startLine].substring(0, range.startColumn
); | 199 var prefix = this._lines[range.startLine].substring(0, range.startColumn
); |
186 var suffix = this._lines[range.endLine].substring(range.endColumn); | 200 var suffix = this._lines[range.endLine].substring(range.endColumn); |
187 | 201 |
188 if (range.endLine > range.startLine) { | 202 if (range.endLine > range.startLine) { |
189 this._lines.splice(range.startLine + 1, range.endLine - range.startL
ine); | 203 this._lines.splice(range.startLine + 1, range.endLine - range.startL
ine); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 this._redoStack[this._redoStack.length - 1].explicit = true; | 350 this._redoStack[this._redoStack.length - 1].explicit = true; |
337 }, | 351 }, |
338 | 352 |
339 resetUndoStack: function() | 353 resetUndoStack: function() |
340 { | 354 { |
341 this._undoStack = []; | 355 this._undoStack = []; |
342 } | 356 } |
343 } | 357 } |
344 | 358 |
345 WebInspector.settings.textEditorIndent = WebInspector.settings.createSetting("te
xtEditorIndent", WebInspector.TextEditorModel.Indent.FourSpaces); | 359 WebInspector.settings.textEditorIndent = WebInspector.settings.createSetting("te
xtEditorIndent", WebInspector.TextEditorModel.Indent.FourSpaces); |
OLD | NEW |