Web Inspector: get rid of enter/exitTextChangeMode in the editor
authorpfeldman@chromium.org <pfeldman@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 13 Nov 2012 09:29:17 +0000 (09:29 +0000)
committerpfeldman@chromium.org <pfeldman@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 13 Nov 2012 09:29:17 +0000 (09:29 +0000)
https://bugs.webkit.org/show_bug.cgi?id=101845

Reviewed by Vsevolod Vlasov.

They seem to do nothing.

* inspector/front-end/DefaultTextEditor.js:
(WebInspector.DefaultTextEditor.prototype._textChanged):
(WebInspector.DefaultTextEditor.prototype.editRange):
(WebInspector.TextEditorMainPanel):
(WebInspector.TextEditorMainPanel.prototype.handleUndoRedo):
(WebInspector.TextEditorMainPanel.prototype.handleEnterKey.get var):
(WebInspector.TextEditorMainPanel.prototype.handleEnterKey):
(WebInspector.TextEditorMainPanel.prototype._applyDomUpdates):
* inspector/front-end/TextEditorModel.js:
(WebInspector.TextEditorModel.endsWithBracketRegex.):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@134387 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/inspector/front-end/DefaultTextEditor.js
Source/WebCore/inspector/front-end/TextEditorModel.js

index 0b60254..1820438 100644 (file)
@@ -1,3 +1,23 @@
+2012-11-13  Pavel Feldman  <pfeldman@chromium.org>
+
+        Web Inspector: get rid of enter/exitTextChangeMode in the editor
+        https://bugs.webkit.org/show_bug.cgi?id=101845
+
+        Reviewed by Vsevolod Vlasov.
+
+        They seem to do nothing.
+
+        * inspector/front-end/DefaultTextEditor.js:
+        (WebInspector.DefaultTextEditor.prototype._textChanged):
+        (WebInspector.DefaultTextEditor.prototype.editRange):
+        (WebInspector.TextEditorMainPanel):
+        (WebInspector.TextEditorMainPanel.prototype.handleUndoRedo):
+        (WebInspector.TextEditorMainPanel.prototype.handleEnterKey.get var):
+        (WebInspector.TextEditorMainPanel.prototype.handleEnterKey):
+        (WebInspector.TextEditorMainPanel.prototype._applyDomUpdates):
+        * inspector/front-end/TextEditorModel.js:
+        (WebInspector.TextEditorModel.endsWithBracketRegex.):
+
 2012-11-13  Tommy Widenflycht  <tommyw@google.com>
 
         Remove the custom WebSocket::send for both V8 and JSC
index 294592a..f1b984d 100644 (file)
@@ -56,14 +56,11 @@ WebInspector.DefaultTextEditor = function(url, delegate)
 
     this._textModel = new WebInspector.TextEditorModel();
     this._textModel.addEventListener(WebInspector.TextEditorModel.Events.TextChanged, this._textChanged, this);
-    this._textModel.resetUndoStack();
 
-    var enterTextChangeMode = this._enterInternalTextChangeMode.bind(this);
-    var exitTextChangeMode = this._exitInternalTextChangeMode.bind(this);
     var syncScrollListener = this._syncScroll.bind(this);
     var syncDecorationsForLineListener = this._syncDecorationsForLine.bind(this);
     var syncLineHeightListener = this._syncLineHeight.bind(this);
-    this._mainPanel = new WebInspector.TextEditorMainPanel(this._delegate, this._textModel, url, syncScrollListener, syncDecorationsForLineListener, enterTextChangeMode, exitTextChangeMode);
+    this._mainPanel = new WebInspector.TextEditorMainPanel(this._delegate, this._textModel, url, syncScrollListener, syncDecorationsForLineListener);
     this._gutterPanel = new WebInspector.TextEditorGutterPanel(this._textModel, syncDecorationsForLineListener, syncLineHeightListener);
 
     this._mainPanel.element.addEventListener("scroll", this._handleScrollChanged.bind(this), false);
@@ -130,14 +127,6 @@ WebInspector.DefaultTextEditor.prototype = {
     },
 
     /**
-     * @return {WebInspector.TextEditorModel}
-     */
-    get textModel()
-    {
-        return this._textModel;
-    },
-
-    /**
      * @return {Element}
      */
     defaultFocusedElement: function()
@@ -306,11 +295,11 @@ WebInspector.DefaultTextEditor.prototype = {
 
     _textChanged: function(event)
     {
-        if (!this._internalTextChangeMode)
-            this._textModel.resetUndoStack();
         this._mainPanel.textChanged(event.data.oldRange, event.data.newRange);
         this._gutterPanel.textChanged(event.data.oldRange, event.data.newRange);
         this._updatePanelOffsets();
+        if (event.data.editRange)
+            this._delegate.onTextChanged(event.data.oldRange, event.data.newRange);
     },
 
     /**
@@ -320,25 +309,7 @@ WebInspector.DefaultTextEditor.prototype = {
      */
     editRange: function(range, text)
     {
-        this._enterInternalTextChangeMode();
-        var newRange = this._textModel.editRange(range, text);
-        this._exitInternalTextChangeMode(range, newRange);
-        return newRange;
-    },
-
-    _enterInternalTextChangeMode: function()
-    {
-        this._internalTextChangeMode = true;
-    },
-
-    /**
-     * @param {WebInspector.TextRange} oldRange
-     * @param {WebInspector.TextRange} newRange
-     */
-    _exitInternalTextChangeMode: function(oldRange, newRange)
-    {
-        this._internalTextChangeMode = false;
-        this._delegate.onTextChanged(oldRange, newRange);
+        return this._textModel.editRange(range, text);
     },
 
     _updatePanelOffsets: function()
@@ -618,14 +589,6 @@ WebInspector.TextEditorChunkedPanel = function(textModel)
 
 WebInspector.TextEditorChunkedPanel.prototype = {
     /**
-     * @return {WebInspector.TextEditorModel}
-     */
-    get textModel()
-    {
-        return this._textModel;
-    },
-
-    /**
      * @param {number} lineNumber
      */
     scrollToLine: function(lineNumber)
@@ -1238,15 +1201,13 @@ WebInspector.TextEditorGutterChunk.prototype = {
  * @param {WebInspector.TextEditorModel} textModel
  * @param {?string} url
  */
-WebInspector.TextEditorMainPanel = function(delegate, textModel, url, syncScrollListener, syncDecorationsForLineListener, enterTextChangeMode, exitTextChangeMode)
+WebInspector.TextEditorMainPanel = function(delegate, textModel, url, syncScrollListener, syncDecorationsForLineListener)
 {
     WebInspector.TextEditorChunkedPanel.call(this, textModel);
 
     this._delegate = delegate;
     this._syncScrollListener = syncScrollListener;
     this._syncDecorationsForLineListener = syncDecorationsForLineListener;
-    this._enterTextChangeMode = enterTextChangeMode;
-    this._exitTextChangeMode = exitTextChangeMode;
 
     this._url = url;
     this._highlighter = new WebInspector.TextEditorHighlighter(textModel, this._highlightDataReady.bind(this));
@@ -1428,17 +1389,7 @@ WebInspector.TextEditorMainPanel.prototype = {
 
         this.beginUpdates();
 
-        function before()
-        {
-            this._enterTextChangeMode();
-        }
-
-        function after(oldRange, newRange)
-        {
-            this._exitTextChangeMode(oldRange, newRange);
-        }
-
-        var range = redo ? this._textModel.redo(before.bind(this), after.bind(this)) : this._textModel.undo(before.bind(this), after.bind(this));
+        var range = redo ? this._textModel.redo() : this._textModel.undo();
 
         this.endUpdates();
 
@@ -1464,7 +1415,6 @@ WebInspector.TextEditorMainPanel.prototype = {
         var range = selection.normalize();
 
         this.beginUpdates();
-        this._enterTextChangeMode();
 
         var newRange;
         var rangeWasEmpty = range.isEmpty();
@@ -1477,7 +1427,6 @@ WebInspector.TextEditorMainPanel.prototype = {
                 newRange = this._textModel.indentLines(range);
         }
 
-        this._exitTextChangeMode(range, newRange);
         this.endUpdates();
         if (rangeWasEmpty)
             newRange.startColumn = newRange.endColumn;
@@ -1511,7 +1460,6 @@ WebInspector.TextEditorMainPanel.prototype = {
             return false;
 
         this.beginUpdates();
-        this._enterTextChangeMode();
 
         var lineBreak = this._textModel.lineBreak;
         var newRange;
@@ -1527,7 +1475,6 @@ WebInspector.TextEditorMainPanel.prototype = {
         } else
             newRange = this._textModel.editRange(range, lineBreak + indent);
 
-        this._exitTextChangeMode(range, newRange);
         this.endUpdates();
         this._restoreSelection(newRange.collapseToEnd(), true);
 
@@ -2214,15 +2161,10 @@ WebInspector.TextEditorMainPanel.prototype = {
         if (lines.length === 1 && lines[0] === "}" && oldRange.isEmpty() && selection.isEmpty() && !this._textModel.line(oldRange.endLine).trim())
             this._unindentAfterBlock(oldRange, selection);
 
-        // This is a "foreign" call outside of this class. Should be before we delete the dirty lines flag.
-        this._enterTextChangeMode();
-
-        var newRange = this._textModel.editRange(oldRange, newContent);
-
+        this._textModel.editRange(oldRange, newContent);
         this._paintScheduledLines(true);
         this._restoreSelection(selection);
 
-        this._exitTextChangeMode(oldRange, newRange);
     },
 
     /**
index d8ac2bd..ee5bb58 100644 (file)
@@ -225,6 +225,7 @@ WebInspector.TextEditorModel.prototype = {
      */
     setText: function(text)
     {
+        this._resetUndoStack();
         text = text || "";
         var range = this.range();
         this._lineBreak = /\r\n/.test(text) ? "\r\n" : "\n";
@@ -258,7 +259,7 @@ WebInspector.TextEditorModel.prototype = {
         var newRange = this._innerSetText(range, text);
         this._lastEditedRange = newRange;
         this._pushUndoableCommand(newRange, originalText);
-        this.dispatchEventToListeners(WebInspector.TextEditorModel.Events.TextChanged, { oldRange: range, newRange: newRange });
+        this.dispatchEventToListeners(WebInspector.TextEditorModel.Events.TextChanged, { oldRange: range, newRange: newRange, editRange: true });
         return newRange;
     },
 
@@ -463,11 +464,9 @@ WebInspector.TextEditorModel.prototype = {
     },
 
     /**
-     * @param {function()=} beforeCallback
-     * @param {function(WebInspector.TextRange, WebInspector.TextRange)=} afterCallback
      * @return {?WebInspector.TextRange}
      */
-    undo: function(beforeCallback, afterCallback)
+    undo: function()
     {
         if (!this._undoStack.length)
             return null;
@@ -475,25 +474,23 @@ WebInspector.TextEditorModel.prototype = {
         this._markRedoableState();
 
         this._inUndo = true;
-        var range = this._doUndo(this._undoStack, beforeCallback, afterCallback);
+        var range = this._doUndo(this._undoStack);
         delete this._inUndo;
 
         return range;
     },
 
     /**
-     * @param {function()=} beforeCallback
-     * @param {function(WebInspector.TextRange, WebInspector.TextRange)=} afterCallback
      * @return {WebInspector.TextRange}
      */
-    redo: function(beforeCallback, afterCallback)
+    redo: function()
     {
         if (!this._redoStack || !this._redoStack.length)
             return null;
         this._markUndoableState();
 
         this._inRedo = true;
-        var range = this._doUndo(this._redoStack, beforeCallback, afterCallback);
+        var range = this._doUndo(this._redoStack);
         delete this._inRedo;
 
         return range;
@@ -501,25 +498,15 @@ WebInspector.TextEditorModel.prototype = {
 
     /**
      * @param {Array.<WebInspector.TextEditorCommand>} stack
-     * @param {function()=} beforeCallback
-     * @param {function(WebInspector.TextRange, WebInspector.TextRange)=} afterCallback
      * @return {WebInspector.TextRange}
      */
-    _doUndo: function(stack, beforeCallback, afterCallback)
+    _doUndo: function(stack)
     {
         var range = null;
         for (var i = stack.length - 1; i >= 0; --i) {
             var command = stack[i];
             stack.length = i;
-
-            if (beforeCallback)
-                beforeCallback();
-
             range = this._innerEditRange(command.newRange, command.originalText);
-
-            if (afterCallback)
-                afterCallback(command.newRange, range);
-
             if (i > 0 && stack[i - 1].explicit)
                 return range;
         }
@@ -538,7 +525,7 @@ WebInspector.TextEditorModel.prototype = {
             this._redoStack[this._redoStack.length - 1].explicit = true;
     },
 
-    resetUndoStack: function()
+    _resetUndoStack: function()
     {
         this._undoStack = [];
     },