Changeset 142998 in webkit
- Timestamp:
- Feb 15, 2013 7:45:50 AM (11 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r142995 r142998 1 2013-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 1 11 2013-02-15 Andrew Wilson <atwilson@chromium.org> 2 12 -
trunk/LayoutTests/inspector/editor/text-editor-undo-redo-expected.txt
r142994 r142998 135 135 136 136 137 Running: testSelectionAfterUndoRedo 138 Text before edit: 139 function foo() 140 { 141 142 } 143 144 Text after backspace: 145 function foo() 146 {| 147 } 148 149 Text after first undo: 150 function foo() 151 { 152 | 153 } 154 155 Text after first redo: 156 function foo() 157 {| 158 } 159 160 Text after second undo: 161 function foo() 162 {> 163 < 164 } 165 166 Text after deleting selection: 167 function foo() 168 {| 169 } 170 171 Text after first undo: 172 function foo() 173 {> 174 < 175 } 176 177 Text after first redo: 178 function foo() 179 {| 180 } 181 182 Text after second undo: 183 function foo() 184 {> 185 < 186 } 187 188 -
trunk/LayoutTests/inspector/editor/text-editor-undo-redo.html
r142965 r142998 19 19 return range; 20 20 } 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 21 33 InspectorTest.runTestSuite([ 22 34 function testUndoRedoTab(next) … … 75 87 dumpTextModel("Text after second redo:\n", textModel, range); 76 88 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(); 77 114 } 78 115 ]); -
trunk/Source/WebCore/ChangeLog
r142996 r142998 1 2013-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 1 17 2013-02-15 Joe Mason <jmason@rim.com> 2 18 -
trunk/Source/WebCore/inspector/front-end/DefaultTextEditor.js
r142983 r142998 2468 2468 var endLine = dirtyLines.end; 2469 2469 2470 var originalSelection = this._lastSelection; 2470 2471 var editInfo = this._guessEditRangeBasedOnSelection(startLine, endLine, lines); 2471 2472 if (!editInfo) { … … 2492 2493 } 2493 2494 2494 this._textModel.editRange(editInfo.range, editInfo.text );2495 this._textModel.editRange(editInfo.range, editInfo.text, originalSelection); 2495 2496 this._restoreSelection(selection); 2496 2497 }, … … 3400 3401 3401 3402 var newSelection = this._rangeForCtrlArrowMove(selection, "left"); 3402 this._textModel.editRange(newSelection.normalize(), "" );3403 this._textModel.editRange(newSelection.normalize(), "", selection); 3403 3404 3404 3405 this._textEditor.setSelection(newSelection.collapseToEnd()); -
trunk/Source/WebCore/inspector/front-end/TextEditorModel.js
r142994 r142998 148 148 * @param {WebInspector.TextRange} newRange 149 149 * @param {string} originalText 150 * @param {WebInspector.TextRange} originalSelection 150 151 */ 151 WebInspector.TextEditorCommand = function(newRange, originalText )152 WebInspector.TextEditorCommand = function(newRange, originalText, originalSelection) 152 153 { 153 154 this.newRange = newRange; 154 155 this.originalText = originalText; 156 this.originalSelection = originalSelection; 155 157 } 156 158 … … 251 253 * @param {WebInspector.TextRange} range 252 254 * @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) 256 259 { 257 260 if (this._lastEditedRange && (!text || text.indexOf("\n") !== -1 || this._lastEditedRange.endLine !== range.startLine || this._lastEditedRange.endColumn !== range.startColumn)) 258 261 this._markUndoableState(); 259 return this._innerEditRange(range, text );262 return this._innerEditRange(range, text, originalSelection); 260 263 }, 261 264 … … 263 266 * @param {WebInspector.TextRange} range 264 267 * @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) 268 272 { 269 273 var originalText = this.copyRange(range); 270 274 var newRange = this._innerSetText(range, text); 271 this._pushUndoableCommand(newRange, originalText);272 275 this._lastEditedRange = newRange; 276 this._pushUndoableCommand(newRange, originalText, originalSelection || range); 273 277 this.dispatchEventToListeners(WebInspector.TextEditorModel.Events.TextChanged, { oldRange: range, newRange: newRange, editRange: true }); 274 278 return newRange; … … 460 464 * @param {WebInspector.TextRange} newRange 461 465 * @param {string} originalText 466 * @param {WebInspector.TextRange} originalSelection 462 467 * @return {WebInspector.TextEditorCommand} 463 468 */ 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); 467 472 if (this._inUndo) 468 473 this._redoStack.push(command); … … 518 523 var command = stack[i]; 519 524 stack.length = i; 520 range = this._innerEditRange(command.newRange, command.originalText); 525 this._innerEditRange(command.newRange, command.originalText); 526 range = command.originalSelection; 521 527 if (i > 0 && stack[i - 1].explicit) 522 528 return range;
Note: See TracChangeset
for help on using the changeset viewer.