diff options
Diffstat (limited to 'Source/WebCore/inspector/front-end/TextEditorModel.js')
-rw-r--r-- | Source/WebCore/inspector/front-end/TextEditorModel.js | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/Source/WebCore/inspector/front-end/TextEditorModel.js b/Source/WebCore/inspector/front-end/TextEditorModel.js index b14a3b7..47c53d7 100644 --- a/Source/WebCore/inspector/front-end/TextEditorModel.js +++ b/Source/WebCore/inspector/front-end/TextEditorModel.js @@ -59,6 +59,7 @@ WebInspector.TextEditorModel = function() this._attributes = []; this._undoStack = []; this._noPunctuationRegex = /[^ !%&()*+,-.:;<=>?\[\]\^{|}~]+/; + this._lineBreak = "\n"; } WebInspector.TextEditorModel.prototype = { @@ -74,7 +75,7 @@ WebInspector.TextEditorModel.prototype = { get text() { - return this._lines.join("\n"); + return this._lines.join(this._lineBreak); }, line: function(lineNumber) @@ -91,9 +92,12 @@ WebInspector.TextEditorModel.prototype = { setText: function(range, text) { - if (!range) + text = text || ""; + if (!range) { range = new WebInspector.TextRange(0, 0, this._lines.length - 1, this._lines[this._lines.length - 1].length); - var command = this._pushUndoableCommand(range, text); + this._lineBreak = /\r\n/.test(text) ? "\r\n" : "\n"; + } + var command = this._pushUndoableCommand(range); var newRange = this._innerSetText(range, text); command.range = newRange.clone(); @@ -113,11 +117,10 @@ WebInspector.TextEditorModel.prototype = { if (text === "") return new WebInspector.TextRange(range.startLine, range.startColumn, range.startLine, range.startColumn); - var newLines = text.split("\n"); + var newLines = text.split(/\r?\n/); this._replaceTabsIfNeeded(newLines); var prefix = this._lines[range.startLine].substring(0, range.startColumn); - var prefixArguments = this._arguments var suffix = this._lines[range.startLine].substring(range.startColumn); var postCaret = prefix.length; @@ -211,13 +214,13 @@ WebInspector.TextEditorModel.prototype = { var clip = []; if (range.startLine === range.endLine) { clip.push(this._lines[range.startLine].substring(range.startColumn, range.endColumn)); - return clip.join("\n"); + return clip.join(this._lineBreak); } clip.push(this._lines[range.startLine].substring(range.startColumn)); for (var i = range.startLine + 1; i < range.endLine; ++i) clip.push(this._lines[i]); clip.push(this._lines[range.endLine].substring(0, range.endColumn)); - return clip.join("\n"); + return clip.join(this._lineBreak); }, setAttribute: function(line, name, value) @@ -243,7 +246,7 @@ WebInspector.TextEditorModel.prototype = { delete attrs[name]; }, - _pushUndoableCommand: function(range, text) + _pushUndoableCommand: function(range) { var command = { text: this.copyRange(range), @@ -262,29 +265,29 @@ WebInspector.TextEditorModel.prototype = { return command; }, - undo: function() + undo: function(callback) { this._markRedoableState(); this._inUndo = true; - var range = this._doUndo(this._undoStack); + var range = this._doUndo(this._undoStack, callback); delete this._inUndo; return range; }, - redo: function() + redo: function(callback) { this.markUndoableState(); this._inRedo = true; - var range = this._doUndo(this._redoStack); + var range = this._doUndo(this._redoStack, callback); delete this._inRedo; return range; }, - _doUndo: function(stack) + _doUndo: function(stack, callback) { var range = null; for (var i = stack.length - 1; i >= 0; --i) { @@ -292,6 +295,8 @@ WebInspector.TextEditorModel.prototype = { stack.length = i; range = this.setText(command.range, command.text); + if (callback) + callback(command.range, range); if (i > 0 && stack[i - 1].explicit) return range; } |