Title: [112652] trunk
Revision
112652
Author
[email protected]
Date
2012-03-30 04:36:15 -0700 (Fri, 30 Mar 2012)

Log Message

Web Inspector: editing resets line-ending of the whole file
https://bugs.webkit.org/show_bug.cgi?id=82708

Reviewed by Yury Semikhatsky.

Source/WebCore:

This change splits TextEditorModel's setText into setText (for initialization) and
editRange (for editing). Distinguishing between the two allowed properly detecting
the preferred line endings.

Test: inspector/editor/text-editor-line-breaks.html

* inspector/front-end/_javascript_SourceFrame.js:
(WebInspector._javascript_SourceFrame.prototype.afterTextChanged):
* inspector/front-end/SourceFrame.js:
(WebInspector.SourceFrame.prototype.setContent):
* inspector/front-end/TextEditorModel.js:
(WebInspector.TextEditorCommand):
(WebInspector.TextEditorModel):
(WebInspector.TextEditorModel.endsWithBracketRegex.):
* inspector/front-end/TextViewer.js:
(WebInspector.TextViewer.prototype._textChanged):
(WebInspector.TextEditorMainPanel.prototype._unindentLines.get var):
(WebInspector.TextEditorMainPanel.prototype._unindentLines):
(WebInspector.TextEditorMainPanel.prototype.handleEnterKey.get var):
(WebInspector.TextEditorMainPanel.prototype.handleEnterKey):
(WebInspector.TextEditorMainPanel.prototype._applyDomUpdates):
(WebInspector.TextEditorMainPanel.prototype._editRange):

LayoutTests:

* inspector/editor/highlighter-basics.html:
* inspector/editor/highlighter-long-line.html:
* inspector/editor/highlighter-paste-in-comment.html:
* inspector/editor/indentation.html:
* inspector/editor/text-editor-line-breaks-expected.txt: Added.
* inspector/editor/text-editor-line-breaks.html: Added.
* inspector/editor/text-editor-model.html:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (112651 => 112652)


--- trunk/LayoutTests/ChangeLog	2012-03-30 11:00:01 UTC (rev 112651)
+++ trunk/LayoutTests/ChangeLog	2012-03-30 11:36:15 UTC (rev 112652)
@@ -1,3 +1,18 @@
+2012-03-30  Pavel Feldman  <[email protected]>
+
+        Web Inspector: editing resets line-ending of the whole file
+        https://bugs.webkit.org/show_bug.cgi?id=82708
+
+        Reviewed by Yury Semikhatsky.
+
+        * inspector/editor/highlighter-basics.html:
+        * inspector/editor/highlighter-long-line.html:
+        * inspector/editor/highlighter-paste-in-comment.html:
+        * inspector/editor/indentation.html:
+        * inspector/editor/text-editor-line-breaks-expected.txt: Added.
+        * inspector/editor/text-editor-line-breaks.html: Added.
+        * inspector/editor/text-editor-model.html:
+
 2012-03-29  Vsevolod Vlasov  <[email protected]>
 
         Web Inspector: Take IndexedDB support out of experiments.

Modified: trunk/LayoutTests/inspector/editor/highlighter-basics.html (112651 => 112652)


--- trunk/LayoutTests/inspector/editor/highlighter-basics.html	2012-03-30 11:00:01 UTC (rev 112651)
+++ trunk/LayoutTests/inspector/editor/highlighter-basics.html	2012-03-30 11:36:15 UTC (rev 112652)
@@ -14,7 +14,7 @@
     src += "some text\n";
 
     var textModel = new WebInspector.TextEditorModel();
-    textModel.setText(null, src);
+    textModel.setText(src);
 
     var highlighter = new WebInspector.TextEditorHighlighter(textModel, function() {});
     highlighter.mimeType = "text/_javascript_";
@@ -32,7 +32,7 @@
     dumpTextModel("After highlighting all lines");
 
     var range = new WebInspector.TextRange(3, 0, 6, 0);
-    var newRange = textModel.setText(range, src);
+    var newRange = textModel.editRange(range, src);
     dumpTextModel("After changing text model, but before updating highlights");
 
     highlighter.updateHighlight(newRange.startLine, newRange.endLine + 1);
@@ -42,12 +42,12 @@
     dumpTextModel("After highlighting up to the end");
 
     var range = new WebInspector.TextRange(0, 0, 0, textModel.lineLength(0));
-    var newRange = textModel.setText(range, "foo /* comment */");
+    var newRange = textModel.editRange(range, "foo /* comment */");
     highlighter.updateHighlight(0, 5);
     dumpTextModel("After changing the first line, and updating the highlights for the first 5 lines");
 
     var range = new WebInspector.TextRange(0, textModel.lineLength(0), 0, textModel.lineLength(0));
-    var newRange = textModel.setText(range, " /*");
+    var newRange = textModel.editRange(range, " /*");
     highlighter.updateHighlight(0, 2);
     dumpTextModel("Again change the first line, but update only first 2 lines (invalidate update for the lines below)");
 

Modified: trunk/LayoutTests/inspector/editor/highlighter-long-line.html (112651 => 112652)


--- trunk/LayoutTests/inspector/editor/highlighter-long-line.html	2012-03-30 11:00:01 UTC (rev 112651)
+++ trunk/LayoutTests/inspector/editor/highlighter-long-line.html	2012-03-30 11:36:15 UTC (rev 112652)
@@ -18,7 +18,7 @@
         src += src;
         comments *= 2;
     }
-    textModel.setText(null, src);
+    textModel.setText(src);
 
     function checkHighlights()
     {
@@ -47,7 +47,7 @@
     // Insert a caret return in the middle of the long line.
     var halfLength = Math.floor(src.length / 2);
     var range = new WebInspector.TextRange(0, halfLength, 0, halfLength);
-    var newRange = textModel.setText(range, "\n");
+    var newRange = textModel.editRange(range, "\n");
     highlighter.updateHighlight(newRange.startLine, newRange.endLine + 1);
     checkHighlights();
 

Modified: trunk/LayoutTests/inspector/editor/highlighter-paste-in-comment.html (112651 => 112652)


--- trunk/LayoutTests/inspector/editor/highlighter-paste-in-comment.html	2012-03-30 11:00:01 UTC (rev 112651)
+++ trunk/LayoutTests/inspector/editor/highlighter-paste-in-comment.html	2012-03-30 11:36:15 UTC (rev 112652)
@@ -18,13 +18,13 @@
     }
 
     var src = ""
-    textModel.setText(null, src);
+    textModel.setText(src);
 
     highlighter.highlight(textModel.linesCount);
     dumpTextModel("After highlighting all lines");
 
     var range = new WebInspector.TextRange(7, 0, 7, 0);
-    var newRange = textModel.setText(range, "1\n2\n3\n4\n5\n");
+    var newRange = textModel.editRange(range, "1\n2\n3\n4\n5\n");
     highlighter.updateHighlight(7, textModel.linesCount);
     dumpTextModel("After update highlights");
 
@@ -33,7 +33,7 @@
 
     // There was an actual bug with wrongly restored position after updating the highlights.
     var range = new WebInspector.TextRange(12, 0, 12, 0);
-    var newRange = textModel.setText(range, "\n");
+    var newRange = textModel.editRange(range, "\n");
     highlighter.updateHighlight(12, textModel.linesCount);
     highlighter.highlight(textModel.linesCount);
     dumpTextModel("After inserting a new line");

Modified: trunk/LayoutTests/inspector/editor/indentation.html (112651 => 112652)


--- trunk/LayoutTests/inspector/editor/indentation.html	2012-03-30 11:00:01 UTC (rev 112651)
+++ trunk/LayoutTests/inspector/editor/indentation.html	2012-03-30 11:36:15 UTC (rev 112652)
@@ -10,7 +10,7 @@
         " */";
 
     var model = new WebInspector.TextEditorModel();
-    model.setText(null, src);
+    model.setText(src);
     function noop() {}
     var textEditorMainPanel = new WebInspector.TextEditorMainPanel(model, '', noop, noop, noop, noop);
 

Added: trunk/LayoutTests/inspector/editor/text-editor-line-breaks-expected.txt (0 => 112652)


--- trunk/LayoutTests/inspector/editor/text-editor-line-breaks-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/inspector/editor/text-editor-line-breaks-expected.txt	2012-03-30 11:36:15 UTC (rev 112652)
@@ -0,0 +1,15 @@
+This test checks that line endings are inferred from the initial text content, not incremental editing.
+
+
+Running: testCRInitial
+1%0A2%0A3%0A
+
+Running: testCRLFInitial
+1%0D%0A2%0D%0A3%0D%0A
+
+Running: testCREdit
+1%0Afoo%0Abar2%0A3%0A
+
+Running: testCRLFEdit
+1%0D%0Afoo%0D%0Abar2%0D%0A3%0D%0A
+
Property changes on: trunk/LayoutTests/inspector/editor/text-editor-line-breaks-expected.txt
___________________________________________________________________

Added: svn:eol-style

Added: trunk/LayoutTests/inspector/editor/text-editor-line-breaks.html (0 => 112652)


--- trunk/LayoutTests/inspector/editor/text-editor-line-breaks.html	                        (rev 0)
+++ trunk/LayoutTests/inspector/editor/text-editor-line-breaks.html	2012-03-30 11:36:15 UTC (rev 112652)
@@ -0,0 +1,54 @@
+<html>
+<head>
+<script src=""
+<script>
+
+function test()
+{
+    InspectorTest.runTestSuite([
+        function testCRInitial(next)
+        {
+            var textModel = new WebInspector.TextEditorModel();
+            textModel.setText("1\n2\n3\n");
+            InspectorTest.addResult(encodeURI(textModel.text));
+            next();
+        },
+
+        function testCRLFInitial(next)
+        {
+            var textModel = new WebInspector.TextEditorModel();
+            textModel.setText("1\r\n2\r\n3\r\n");
+            InspectorTest.addResult(encodeURI(textModel.text));
+            next();
+        },
+
+        function testCREdit(next)
+        {
+            var textModel = new WebInspector.TextEditorModel();
+            textModel.setText("1\n2\n3\n");
+            textModel.editRange(new WebInspector.TextRange(1, 0, 1, 0), "foo\r\nbar");
+            InspectorTest.addResult(encodeURI(textModel.text));
+            next();
+        },
+
+        function testCRLFEdit(next)
+        {
+            var textModel = new WebInspector.TextEditorModel();
+            textModel.setText("1\r\n2\r\n3\r\n");
+            textModel.editRange(new WebInspector.TextRange(1, 0, 1, 0), "foo\r\nbar");
+            InspectorTest.addResult(encodeURI(textModel.text));
+            next();
+        }
+    ]);
+}
+
+</script>
+</head>
+
+<body _onload_="runTest()">
+<p>
+This test checks that line endings are inferred from the initial text content, not incremental editing.
+</p>
+
+</body>
+</html>
Property changes on: trunk/LayoutTests/inspector/editor/text-editor-line-breaks.html
___________________________________________________________________

Added: svn:eol-style

Modified: trunk/LayoutTests/inspector/editor/text-editor-model.html (112651 => 112652)


--- trunk/LayoutTests/inspector/editor/text-editor-model.html	2012-03-30 11:00:01 UTC (rev 112651)
+++ trunk/LayoutTests/inspector/editor/text-editor-model.html	2012-03-30 11:36:15 UTC (rev 112652)
@@ -8,7 +8,7 @@
     function createAndDumpTextModel(text)
     {
         var textModel = new WebInspector.TextEditorModel();
-        textModel.setText(null, text);
+        textModel.setText(text);
         InspectorTest.addResult("Lines:" + textModel.linesCount + ", length:" + textModel.text.length + ", input equals output:" + (textModel.text === text));
     }
 

Modified: trunk/Source/WebCore/ChangeLog (112651 => 112652)


--- trunk/Source/WebCore/ChangeLog	2012-03-30 11:00:01 UTC (rev 112651)
+++ trunk/Source/WebCore/ChangeLog	2012-03-30 11:36:15 UTC (rev 112652)
@@ -1,3 +1,33 @@
+2012-03-30  Pavel Feldman  <[email protected]>
+
+        Web Inspector: editing resets line-ending of the whole file
+        https://bugs.webkit.org/show_bug.cgi?id=82708
+
+        Reviewed by Yury Semikhatsky.
+
+        This change splits TextEditorModel's setText into setText (for initialization) and
+        editRange (for editing). Distinguishing between the two allowed properly detecting
+        the preferred line endings.
+
+        Test: inspector/editor/text-editor-line-breaks.html
+
+        * inspector/front-end/_javascript_SourceFrame.js:
+        (WebInspector._javascript_SourceFrame.prototype.afterTextChanged):
+        * inspector/front-end/SourceFrame.js:
+        (WebInspector.SourceFrame.prototype.setContent):
+        * inspector/front-end/TextEditorModel.js:
+        (WebInspector.TextEditorCommand):
+        (WebInspector.TextEditorModel):
+        (WebInspector.TextEditorModel.endsWithBracketRegex.):
+        * inspector/front-end/TextViewer.js:
+        (WebInspector.TextViewer.prototype._textChanged):
+        (WebInspector.TextEditorMainPanel.prototype._unindentLines.get var):
+        (WebInspector.TextEditorMainPanel.prototype._unindentLines):
+        (WebInspector.TextEditorMainPanel.prototype.handleEnterKey.get var):
+        (WebInspector.TextEditorMainPanel.prototype.handleEnterKey):
+        (WebInspector.TextEditorMainPanel.prototype._applyDomUpdates):
+        (WebInspector.TextEditorMainPanel.prototype._editRange):
+
 2012-03-29  Vsevolod Vlasov  <[email protected]>
 
         Web Inspector: Take IndexedDB support out of experiments.

Modified: trunk/Source/WebCore/inspector/front-end/_javascript_SourceFrame.js (112651 => 112652)


--- trunk/Source/WebCore/inspector/front-end/_javascript_SourceFrame.js	2012-03-30 11:00:01 UTC (rev 112651)
+++ trunk/Source/WebCore/inspector/front-end/_javascript_SourceFrame.js	2012-03-30 11:36:15 UTC (rev 112652)
@@ -160,7 +160,7 @@
 
     afterTextChanged: function(oldRange, newRange)
     {
-        var isDirty = this.textModel.copyRange() !== this._originalContent;
+        var isDirty = this.textModel.text !== this._originalContent;
         if (isDirty)
             this._scriptsPanel.setScriptSourceIsDirty(this._uiSourceCode, true);
         else

Modified: trunk/Source/WebCore/inspector/front-end/SourceFrame.js (112651 => 112652)


--- trunk/Source/WebCore/inspector/front-end/SourceFrame.js	2012-03-30 11:00:01 UTC (rev 112651)
+++ trunk/Source/WebCore/inspector/front-end/SourceFrame.js	2012-03-30 11:36:15 UTC (rev 112652)
@@ -216,7 +216,7 @@
         this._textViewer.mimeType = mimeType;
 
         this._loaded = true;
-        this._textModel.setText(null, content);
+        this._textModel.setText(content);
 
         this._textViewer.beginUpdates();
 

Modified: trunk/Source/WebCore/inspector/front-end/TextEditorModel.js (112651 => 112652)


--- trunk/Source/WebCore/inspector/front-end/TextEditorModel.js	2012-03-30 11:00:01 UTC (rev 112651)
+++ trunk/Source/WebCore/inspector/front-end/TextEditorModel.js	2012-03-30 11:36:15 UTC (rev 112652)
@@ -30,6 +30,10 @@
 
 /**
  * @constructor
+ * @param {number} startLine
+ * @param {number} startColumn
+ * @param {number} endLine
+ * @param {number} endColumn
  */
 WebInspector.TextRange = function(startLine, startColumn, endLine, endColumn)
 {
@@ -40,11 +44,17 @@
 }
 
 WebInspector.TextRange.prototype = {
+    /**
+     * @return {boolean}
+     */
     isEmpty: function()
     {
         return this.startLine === this.endLine && this.startColumn === this.endColumn;
     },
 
+    /**
+     * @type {number}
+     */
     get linesCount()
     {
         return this.endLine - this.startLine;
@@ -55,6 +65,9 @@
         return new WebInspector.TextRange(this.endLine, this.endColumn, this.endLine, this.endColumn);
     },
 
+    /**
+     * @return {WebInspector.TextRange}
+     */
     normalize: function()
     {
         if (this.startLine > this.endLine || (this.startLine === this.endLine && this.startColumn > this.endColumn))
@@ -63,6 +76,9 @@
             return this;
     },
 
+    /**
+     * @return {WebInspector.TextRange}
+     */
     clone: function()
     {
         return new WebInspector.TextRange(this.startLine, this.startColumn, this.endLine, this.endColumn);
@@ -71,11 +87,24 @@
 
 /**
  * @constructor
+ * @param {WebInspector.TextRange} newRange
+ * @param {string} originalText
  */
+WebInspector.TextEditorCommand = function(newRange, originalText)
+{
+    this.newRange = newRange;
+    this.originalText = originalText;
+}
+
+/**
+ * @constructor
+ * @extends {WebInspector.Object}
+ */
 WebInspector.TextEditorModel = function()
 {
     this._lines = [""];
     this._attributes = [];
+    /** @type {Array.<WebInspector.TextEditorCommand>} */
     this._undoStack = [];
     this._noPunctuationRegex = /[^ !%&()*+,-.:;<=>?\[\]\^{|}~]+/;
     this._lineBreak = "\n";
@@ -88,29 +117,41 @@
     TabCharacter: "\t"
 }
 
+WebInspector.TextEditorModel.Events = {
+    TextChanged: "TextChanged"
+}
+
 WebInspector.TextEditorModel.endsWithBracketRegex = /[{(\[]\s*$/;
 
 WebInspector.TextEditorModel.prototype = {
-    set changeListener(changeListener)
-    {
-        this._changeListener = changeListener;
-    },
-
+    /**
+     * @type {number}
+     */
     get linesCount()
     {
         return this._lines.length;
     },
 
+    /**
+     * @type {string}
+     */
     get text()
     {
         return this._lines.join(this._lineBreak);
     },
 
+    /**
+     * @type {string}
+     */
     get lineBreak()
     {
         return this._lineBreak;
     },
 
+    /**
+     * @param {number} lineNumber
+     * @return {string}
+     */
     line: function(lineNumber)
     {
         if (lineNumber >= this._lines.length)
@@ -118,30 +159,49 @@
         return this._lines[lineNumber];
     },
 
+    /**
+     * @param {number} lineNumber
+     * @return {number}
+     */
     lineLength: function(lineNumber)
     {
         return this._lines[lineNumber].length;
     },
 
-    setText: function(range, text)
+    /**
+     * @param {string} text 
+     */
+    setText: function(text)
     {
         text = text || "";
-        if (!range) {
-            range = new WebInspector.TextRange(0, 0, this._lines.length - 1, this._lines[this._lines.length - 1].length);
-            this._lineBreak = /\r\n/.test(text) ? "\r\n" : "\n";
-        }
-        var command = this._pushUndoableCommand(range, text);
-        if (!command)
+        var range = new WebInspector.TextRange(0, 0, this._lines.length - 1, this._lines[this._lines.length - 1].length);
+        this._lineBreak = /\r\n/.test(text) ? "\r\n" : "\n";
+        var newRange = this._innerSetText(range, text);
+        this.dispatchEventToListeners(WebInspector.TextEditorModel.Events.TextChanged, { oldRange: range, newRange: newRange});
+    },
+
+    /**
+     * @param {WebInspector.TextRange} range
+     * @param {string} text
+     * @return {WebInspector.TextRange}
+     */
+    editRange: function(range, text)
+    {
+        var originalText = this.copyRange(range);
+        if (text === originalText)
             return range; // Noop
 
         var newRange = this._innerSetText(range, text);
-        command.range = newRange.clone();
-
-        if (this._changeListener)
-            this._changeListener(range, newRange, command.text, text);
+        this._pushUndoableCommand(newRange, originalText);
+        this.dispatchEventToListeners(WebInspector.TextEditorModel.Events.TextChanged, { oldRange: range, newRange: newRange });
         return newRange;
     },
 
+    /**
+     * @param {WebInspector.TextRange} range
+     * @param {string} text
+     * @return {WebInspector.TextRange}
+     */
     _innerSetText: function(range, text)
     {
         this._eraseRange(range);
@@ -169,6 +229,10 @@
                                           range.startLine + newLines.length - 1, postCaret);
     },
 
+    /**
+     * @param {WebInspector.TextRange} range
+     * @param {Array.<string>} newLines
+     */
     _insertLines: function(range, newLines)
     {
         var lines = new Array(this._lines.length + newLines.length - 1);
@@ -191,6 +255,9 @@
         this._attributes = attributes;
     },
 
+    /**
+     * @param {WebInspector.TextRange} range
+     */
     _eraseRange: function(range)
     {
         if (range.isEmpty())
@@ -207,16 +274,31 @@
         this._setLine(range.startLine, prefix + suffix);
     },
 
+    /**
+     * @param {number} lineNumber
+     * @param {string} text
+     */
     _setLine: function(lineNumber, text)
     {
         this._lines[lineNumber] = text;
     },
 
+    /**
+     * @param {number} lineNumber
+     * @param {number} column
+     * @return {WebInspector.TextRange}
+     */
     wordRange: function(lineNumber, column)
     {
         return new WebInspector.TextRange(lineNumber, this.wordStart(lineNumber, column, true), lineNumber, this.wordEnd(lineNumber, column, true));
     },
 
+    /**
+     * @param {number} lineNumber
+     * @param {number} column
+     * @param {boolean} gapless
+     * @return {number}
+     */
     wordStart: function(lineNumber, column, gapless)
     {
         var line = this._lines[lineNumber];
@@ -225,6 +307,12 @@
         return prefixMatch && (!gapless || prefixMatch.index === 0) ? column - prefixMatch.index - prefixMatch[0].length : column;
     },
 
+    /**
+     * @param {number} lineNumber
+     * @param {number} column
+     * @param {boolean} gapless
+     * @return {number}
+     */
     wordEnd: function(lineNumber, column, gapless)
     {
         var line = this._lines[lineNumber];
@@ -233,6 +321,10 @@
         return suffixMatch && (!gapless || suffixMatch.index === 0) ? column + suffixMatch.index + suffixMatch[0].length : column;
     },
 
+    /**
+     * @param {WebInspector.TextRange} range
+     * @return {string}  
+     */
     copyRange: function(range)
     {
         if (!range)
@@ -250,6 +342,11 @@
         return clip.join(this._lineBreak);
     },
 
+    /**
+     * @param {number} line
+     * @param {string} name  
+     * @param {Object?} value  
+     */
     setAttribute: function(line, name, value)
     {
         var attrs = this._attributes[line];
@@ -260,12 +357,21 @@
         attrs[name] = value;
     },
 
+    /**
+     * @param {number} line
+     * @param {string} name  
+     * @return {Object|null} value  
+     */
     getAttribute: function(line, name)
     {
         var attrs = this._attributes[line];
         return attrs ? attrs[name] : null;
     },
 
+    /**
+     * @param {number} line
+     * @param {string} name
+     */
     removeAttribute: function(line, name)
     {
         var attrs = this._attributes[line];
@@ -273,18 +379,14 @@
             delete attrs[name];
     },
 
-    _pushUndoableCommand: function(range, text)
+    /**
+     * @param {WebInspector.TextRange} newRange
+     * @param {string} originalText
+     * @return {WebInspector.TextEditorCommand}
+     */
+    _pushUndoableCommand: function(newRange, originalText)
     {
-        var command = {
-            text: this.copyRange(range),
-            startLine: range.startLine,
-            startColumn: range.startColumn,
-            endLine: range.startLine,
-            endColumn: range.startColumn
-        };
-        if (text === command.text)
-            return null;
-
+        var command = new WebInspector.TextEditorCommand(newRange, originalText);
         if (this._inUndo)
             this._redoStack.push(command);
         else {
@@ -295,6 +397,11 @@
         return command;
     },
 
+    /**
+     * @param {function()=} beforeCallback
+     * @param {function(WebInspector.TextRange, WebInspector.TextRange)=} afterCallback
+     * @return {WebInspector.TextRange}
+     */
     undo: function(beforeCallback, afterCallback)
     {
         this._markRedoableState();
@@ -306,6 +413,11 @@
         return range;
     },
 
+    /**
+     * @param {function()=} beforeCallback
+     * @param {function(WebInspector.TextRange, WebInspector.TextRange)=} afterCallback
+     * @return {WebInspector.TextRange}
+     */
     redo: function(beforeCallback, afterCallback)
     {
         this.markUndoableState();
@@ -317,6 +429,12 @@
         return range;
     },
 
+    /**
+     * @param {Array.<WebInspector.TextEditorCommand>} stack
+     * @param {function()=} beforeCallback
+     * @param {function(WebInspector.TextRange, WebInspector.TextRange)=} afterCallback
+     * @return {WebInspector.TextRange}
+     */
     _doUndo: function(stack, beforeCallback, afterCallback)
     {
         var range = null;
@@ -327,10 +445,10 @@
             if (beforeCallback)
                 beforeCallback();
 
-            range = this.setText(command.range, command.text);
+            range = this.editRange(command.newRange, command.originalText);
 
             if (afterCallback)
-                afterCallback(command.range, range);
+                afterCallback(command.newRange, range);
 
             if (i > 0 && stack[i - 1].explicit)
                 return range;
@@ -356,4 +474,6 @@
     }
 }
 
+WebInspector.TextEditorModel.prototype.__proto__ = WebInspector.Object.prototype;
+
 WebInspector.settings.textEditorIndent = WebInspector.settings.createSetting("textEditorIndent", WebInspector.TextEditorModel.Indent.FourSpaces);

Modified: trunk/Source/WebCore/inspector/front-end/TextViewer.js (112651 => 112652)


--- trunk/Source/WebCore/inspector/front-end/TextViewer.js	2012-03-30 11:00:01 UTC (rev 112651)
+++ trunk/Source/WebCore/inspector/front-end/TextViewer.js	2012-03-30 11:36:15 UTC (rev 112652)
@@ -39,7 +39,7 @@
     this.registerRequiredCSS("textViewer.css");
 
     this._textModel = textModel;
-    this._textModel.changeListener = this._textChanged.bind(this);
+    this._textModel.addEventListener(WebInspector.TextEditorModel.Events.TextChanged, this._textChanged, this);
     this._textModel.resetUndoStack();
     this._delegate = delegate;
 
@@ -176,13 +176,12 @@
         this._updatePanelOffsets();
     },
 
-    // WebInspector.TextModel listener
-    _textChanged: function(oldRange, newRange, oldText, newText)
+    _textChanged: function(event)
     {
         if (!this._internalTextChangeMode)
             this._textModel.resetUndoStack();
-        this._mainPanel.textChanged(oldRange, newRange);
-        this._gutterPanel.textChanged(oldRange, newRange);
+        this._mainPanel.textChanged(event.data.oldRange, event.data.newRange);
+        this._gutterPanel.textChanged(event.data.oldRange, event.data.newRange);
         this._updatePanelOffsets();
     },
 
@@ -1125,7 +1124,7 @@
             newRange = this._unindentLines(range);
         else {
             if (range.isEmpty()) {
-                newRange = this._setText(range, WebInspector.settings.textEditorIndent.get());
+                newRange = this._editRange(range, WebInspector.settings.textEditorIndent.get());
                 newRange.startColumn = newRange.endColumn;
             } else
                 newRange = this._indentLines(range);
@@ -1158,7 +1157,7 @@
             indentEndLine--;
 
         for (var lineNumber = range.startLine; lineNumber <= indentEndLine; lineNumber++)
-            this._textModel.setText(new WebInspector.TextRange(lineNumber, 0, lineNumber, 0), indent);
+            this._textModel.editRange(new WebInspector.TextRange(lineNumber, 0, lineNumber, 0), indent);
 
         this._lastEditedRange = newRange;
 
@@ -1191,7 +1190,7 @@
             else
                 continue;
 
-            this._textModel.setText(new WebInspector.TextRange(lineNumber, 0, lineNumber, lineIndentLength), "");
+            this._textModel.editRange(new WebInspector.TextRange(lineNumber, 0, lineNumber, lineIndentLength), "");
 
             if (lineNumber === range.startLine)
                 newRange.startColumn = Math.max(0, newRange.startColumn - lineIndentLength);
@@ -1241,11 +1240,11 @@
             // {
             //     |
             // }
-            newRange = this._setText(range, lineBreak + indent + lineBreak + currentIndent);
+            newRange = this._editRange(range, lineBreak + indent + lineBreak + currentIndent);
             newRange.endLine--;
             newRange.endColumn += textEditorIndent.length;
         } else
-            newRange = this._setText(range, lineBreak + indent);
+            newRange = this._editRange(range, lineBreak + indent);
 
         this._exitTextChangeMode(range, newRange);
         this.endUpdates();
@@ -1862,7 +1861,7 @@
 
         delete this._dirtyLines;
 
-        var newRange = this._setText(oldRange, newContent);
+        var newRange = this._editRange(oldRange, newContent);
 
         this._paintScheduledLines(true);
         this._restoreSelection(selection);
@@ -1879,12 +1878,12 @@
         this.endDomUpdates();
     },
 
-    _setText: function(range, text)
+    _editRange: function(range, text)
     {
         if (this._lastEditedRange && (!text || text.indexOf("\n") !== -1 || this._lastEditedRange.endLine !== range.startLine || this._lastEditedRange.endColumn !== range.startColumn))
             this._textModel.markUndoableState();
 
-        var newRange = this._textModel.setText(range, text);
+        var newRange = this._textModel.editRange(range, text);
         this._lastEditedRange = newRange;
 
         return newRange;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to