Changeset 142998 in webkit


Ignore:
Timestamp:
Feb 15, 2013 7:45:50 AM (11 years ago)
Author:
vsevik@chromium.org
Message:

Web Inspector: Pass original selection to textModel to correctly restore it after undo.
https://bugs.webkit.org/show_bug.cgi?id=109911

Reviewed by Pavel Feldman.

Source/WebCore:

We can distinguish backspace pressed with and without selection now.

  • inspector/front-end/DefaultTextEditor.js:

(WebInspector.TextEditorMainPanel.prototype._applyDomUpdates):
(WebInspector.DefaultTextEditor.WordMovementController.prototype._handleCtrlBackspace):

  • inspector/front-end/TextEditorModel.js:

(WebInspector.TextEditorCommand):
(WebInspector.TextEditorModel.endsWithBracketRegex.):

LayoutTests:

  • inspector/editor/text-editor-undo-redo-expected.txt:
  • inspector/editor/text-editor-undo-redo.html:
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r142995 r142998  
     12013-02-15  Vsevolod Vlasov  <vsevik@chromium.org>
     2
     3        Web Inspector: Pass original selection to textModel to correctly restore it after undo.
     4        https://bugs.webkit.org/show_bug.cgi?id=109911
     5
     6        Reviewed by Pavel Feldman.
     7
     8        * inspector/editor/text-editor-undo-redo-expected.txt:
     9        * inspector/editor/text-editor-undo-redo.html:
     10
    1112013-02-15  Andrew Wilson  <atwilson@chromium.org>
    212
  • trunk/LayoutTests/inspector/editor/text-editor-undo-redo-expected.txt

    r142994 r142998  
    135135
    136136
     137Running: testSelectionAfterUndoRedo
     138Text before edit:
     139function foo()
     140{
     141
     142}
     143
     144Text after backspace:
     145function foo()
     146{|
     147}
     148
     149Text after first undo:
     150function foo()
     151{
     152|
     153}
     154
     155Text after first redo:
     156function foo()
     157{|
     158}
     159
     160Text after second undo:
     161function foo()
     162{>
     163<
     164}
     165
     166Text after deleting selection:
     167function foo()
     168{|
     169}
     170
     171Text after first undo:
     172function foo()
     173{>
     174<
     175}
     176
     177Text after first redo:
     178function foo()
     179{|
     180}
     181
     182Text after second undo:
     183function foo()
     184{>
     185<
     186}
     187
     188
  • trunk/LayoutTests/inspector/editor/text-editor-undo-redo.html

    r142965 r142998  
    1919        return range;
    2020    }
     21
     22    function typeBackspace(textModel, startRange, count)
     23    {
     24        var count = count || 1;
     25        var range = startRange;
     26        for (var i = 0; i < count; ++i) {
     27            var backspaceRange = range.isEmpty() ? textModel.growRangeLeft(range) : range;
     28            range = textModel.editRange(backspaceRange, "", range).collapseToEnd();
     29        }
     30        return range;
     31    }
     32
    2133    InspectorTest.runTestSuite([
    2234        function testUndoRedoTab(next)
     
    7587            dumpTextModel("Text after second redo:\n", textModel, range);
    7688            next();
     89        },
     90
     91        function testSelectionAfterUndoRedo(next)
     92        {
     93            var textModel = new WebInspector.TextEditorModel();
     94            var functionText = "    bar();\n    baz();\n    foo();";
     95            textModel.setText("function foo()\n{\n\n}\n");
     96            dumpTextModel("Text before edit:\n", textModel);
     97            range = typeBackspace(textModel, new WebInspector.TextRange(2, 0, 2, 0), 1);
     98            dumpTextModel("Text after backspace:\n", textModel, range);
     99            range = textModel.undo();
     100            dumpTextModel("Text after first undo:\n", textModel, range);
     101            range = textModel.redo();
     102            dumpTextModel("Text after first redo:\n", textModel, range);
     103            range = textModel.undo();
     104            dumpTextModel("Text after second undo:\n", textModel, range);
     105            range = typeBackspace(textModel, new WebInspector.TextRange(1, 1, 2, 0), 1);
     106            dumpTextModel("Text after deleting selection:\n", textModel, range);
     107            range = textModel.undo();
     108            dumpTextModel("Text after first undo:\n", textModel, range);
     109            range = textModel.redo();
     110            dumpTextModel("Text after first redo:\n", textModel, range);
     111            range = textModel.undo();
     112            dumpTextModel("Text after second undo:\n", textModel, range);
     113            next();
    77114        }
    78115    ]);
  • trunk/Source/WebCore/ChangeLog

    r142996 r142998  
     12013-02-15  Vsevolod Vlasov  <vsevik@chromium.org>
     2
     3        Web Inspector: Pass original selection to textModel to correctly restore it after undo.
     4        https://bugs.webkit.org/show_bug.cgi?id=109911
     5
     6        Reviewed by Pavel Feldman.
     7
     8        We can distinguish backspace pressed with and without selection now.
     9
     10        * inspector/front-end/DefaultTextEditor.js:
     11        (WebInspector.TextEditorMainPanel.prototype._applyDomUpdates):
     12        (WebInspector.DefaultTextEditor.WordMovementController.prototype._handleCtrlBackspace):
     13        * inspector/front-end/TextEditorModel.js:
     14        (WebInspector.TextEditorCommand):
     15        (WebInspector.TextEditorModel.endsWithBracketRegex.):
     16
    1172013-02-15  Joe Mason  <jmason@rim.com>
    218
  • trunk/Source/WebCore/inspector/front-end/DefaultTextEditor.js

    r142983 r142998  
    24682468        var endLine = dirtyLines.end;
    24692469
     2470        var originalSelection = this._lastSelection;
    24702471        var editInfo = this._guessEditRangeBasedOnSelection(startLine, endLine, lines);
    24712472        if (!editInfo) {
     
    24922493        }
    24932494
    2494         this._textModel.editRange(editInfo.range, editInfo.text);
     2495        this._textModel.editRange(editInfo.range, editInfo.text, originalSelection);
    24952496        this._restoreSelection(selection);
    24962497    },
     
    34003401
    34013402        var newSelection = this._rangeForCtrlArrowMove(selection, "left");
    3402         this._textModel.editRange(newSelection.normalize(), "");
     3403        this._textModel.editRange(newSelection.normalize(), "", selection);
    34033404
    34043405        this._textEditor.setSelection(newSelection.collapseToEnd());
  • trunk/Source/WebCore/inspector/front-end/TextEditorModel.js

    r142994 r142998  
    148148 * @param {WebInspector.TextRange} newRange
    149149 * @param {string} originalText
     150 * @param {WebInspector.TextRange} originalSelection
    150151 */
    151 WebInspector.TextEditorCommand = function(newRange, originalText)
     152WebInspector.TextEditorCommand = function(newRange, originalText, originalSelection)
    152153{
    153154    this.newRange = newRange;
    154155    this.originalText = originalText;
     156    this.originalSelection = originalSelection;
    155157}
    156158
     
    251253     * @param {WebInspector.TextRange} range
    252254     * @param {string} text
    253      * @return {WebInspector.TextRange}
    254      */
    255     editRange: function(range, text)
     255     * @param {WebInspector.TextRange=} originalSelection
     256     * @return {WebInspector.TextRange}
     257     */
     258    editRange: function(range, text, originalSelection)
    256259    {   
    257260        if (this._lastEditedRange && (!text || text.indexOf("\n") !== -1 || this._lastEditedRange.endLine !== range.startLine || this._lastEditedRange.endColumn !== range.startColumn))
    258261            this._markUndoableState();
    259         return this._innerEditRange(range, text);
     262        return this._innerEditRange(range, text, originalSelection);
    260263    },
    261264
     
    263266     * @param {WebInspector.TextRange} range
    264267     * @param {string} text
    265      * @return {WebInspector.TextRange}
    266      */
    267     _innerEditRange: function(range, text)
     268     * @param {WebInspector.TextRange=} originalSelection
     269     * @return {WebInspector.TextRange}
     270     */
     271    _innerEditRange: function(range, text, originalSelection)
    268272    {
    269273        var originalText = this.copyRange(range);
    270274        var newRange = this._innerSetText(range, text);
    271         this._pushUndoableCommand(newRange, originalText);
    272275        this._lastEditedRange = newRange;
     276        this._pushUndoableCommand(newRange, originalText, originalSelection || range);
    273277        this.dispatchEventToListeners(WebInspector.TextEditorModel.Events.TextChanged, { oldRange: range, newRange: newRange, editRange: true });
    274278        return newRange;
     
    460464     * @param {WebInspector.TextRange} newRange
    461465     * @param {string} originalText
     466     * @param {WebInspector.TextRange} originalSelection
    462467     * @return {WebInspector.TextEditorCommand}
    463468     */
    464     _pushUndoableCommand: function(newRange, originalText)
    465     {
    466         var command = new WebInspector.TextEditorCommand(newRange.clone(), originalText);
     469    _pushUndoableCommand: function(newRange, originalText, originalSelection)
     470    {
     471        var command = new WebInspector.TextEditorCommand(newRange.clone(), originalText, originalSelection);
    467472        if (this._inUndo)
    468473            this._redoStack.push(command);
     
    518523            var command = stack[i];
    519524            stack.length = i;
    520             range = this._innerEditRange(command.newRange, command.originalText);
     525            this._innerEditRange(command.newRange, command.originalText);
     526            range = command.originalSelection;
    521527            if (i > 0 && stack[i - 1].explicit)
    522528                return range;
Note: See TracChangeset for help on using the changeset viewer.