Diff
Modified: trunk/LayoutTests/ChangeLog (142997 => 142998)
--- trunk/LayoutTests/ChangeLog 2013-02-15 15:33:57 UTC (rev 142997)
+++ trunk/LayoutTests/ChangeLog 2013-02-15 15:45:50 UTC (rev 142998)
@@ -1,3 +1,13 @@
+2013-02-15 Vsevolod Vlasov <[email protected]>
+
+ 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.
+
+ * inspector/editor/text-editor-undo-redo-expected.txt:
+ * inspector/editor/text-editor-undo-redo.html:
+
2013-02-15 Andrew Wilson <[email protected]>
Unreviewed chromium rebaselines for r142947.
Modified: trunk/LayoutTests/inspector/editor/text-editor-undo-redo-expected.txt (142997 => 142998)
--- trunk/LayoutTests/inspector/editor/text-editor-undo-redo-expected.txt 2013-02-15 15:33:57 UTC (rev 142997)
+++ trunk/LayoutTests/inspector/editor/text-editor-undo-redo-expected.txt 2013-02-15 15:45:50 UTC (rev 142998)
@@ -134,3 +134,55 @@
}
+Running: testSelectionAfterUndoRedo
+Text before edit:
+function foo()
+{
+
+}
+
+Text after backspace:
+function foo()
+{|
+}
+
+Text after first undo:
+function foo()
+{
+|
+}
+
+Text after first redo:
+function foo()
+{|
+}
+
+Text after second undo:
+function foo()
+{>
+<
+}
+
+Text after deleting selection:
+function foo()
+{|
+}
+
+Text after first undo:
+function foo()
+{>
+<
+}
+
+Text after first redo:
+function foo()
+{|
+}
+
+Text after second undo:
+function foo()
+{>
+<
+}
+
+
Modified: trunk/LayoutTests/inspector/editor/text-editor-undo-redo.html (142997 => 142998)
--- trunk/LayoutTests/inspector/editor/text-editor-undo-redo.html 2013-02-15 15:33:57 UTC (rev 142997)
+++ trunk/LayoutTests/inspector/editor/text-editor-undo-redo.html 2013-02-15 15:45:50 UTC (rev 142998)
@@ -18,6 +18,18 @@
range = textModel.editRange(range, text[i]).collapseToEnd();
return range;
}
+
+ function typeBackspace(textModel, startRange, count)
+ {
+ var count = count || 1;
+ var range = startRange;
+ for (var i = 0; i < count; ++i) {
+ var backspaceRange = range.isEmpty() ? textModel.growRangeLeft(range) : range;
+ range = textModel.editRange(backspaceRange, "", range).collapseToEnd();
+ }
+ return range;
+ }
+
InspectorTest.runTestSuite([
function testUndoRedoTab(next)
{
@@ -74,6 +86,31 @@
range = textModel.redo();
dumpTextModel("Text after second redo:\n", textModel, range);
next();
+ },
+
+ function testSelectionAfterUndoRedo(next)
+ {
+ var textModel = new WebInspector.TextEditorModel();
+ var functionText = " bar();\n baz();\n foo();";
+ textModel.setText("function foo()\n{\n\n}\n");
+ dumpTextModel("Text before edit:\n", textModel);
+ range = typeBackspace(textModel, new WebInspector.TextRange(2, 0, 2, 0), 1);
+ dumpTextModel("Text after backspace:\n", textModel, range);
+ range = textModel.undo();
+ dumpTextModel("Text after first undo:\n", textModel, range);
+ range = textModel.redo();
+ dumpTextModel("Text after first redo:\n", textModel, range);
+ range = textModel.undo();
+ dumpTextModel("Text after second undo:\n", textModel, range);
+ range = typeBackspace(textModel, new WebInspector.TextRange(1, 1, 2, 0), 1);
+ dumpTextModel("Text after deleting selection:\n", textModel, range);
+ range = textModel.undo();
+ dumpTextModel("Text after first undo:\n", textModel, range);
+ range = textModel.redo();
+ dumpTextModel("Text after first redo:\n", textModel, range);
+ range = textModel.undo();
+ dumpTextModel("Text after second undo:\n", textModel, range);
+ next();
}
]);
}
Modified: trunk/Source/WebCore/ChangeLog (142997 => 142998)
--- trunk/Source/WebCore/ChangeLog 2013-02-15 15:33:57 UTC (rev 142997)
+++ trunk/Source/WebCore/ChangeLog 2013-02-15 15:45:50 UTC (rev 142998)
@@ -1,3 +1,19 @@
+2013-02-15 Vsevolod Vlasov <[email protected]>
+
+ 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.
+
+ 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.):
+
2013-02-15 Joe Mason <[email protected]>
[BlackBerry] Remove redundant requireAuth parameter of NetworkJob::notifyAuthReceived
Modified: trunk/Source/WebCore/inspector/front-end/DefaultTextEditor.js (142997 => 142998)
--- trunk/Source/WebCore/inspector/front-end/DefaultTextEditor.js 2013-02-15 15:33:57 UTC (rev 142997)
+++ trunk/Source/WebCore/inspector/front-end/DefaultTextEditor.js 2013-02-15 15:45:50 UTC (rev 142998)
@@ -2467,6 +2467,7 @@
var startLine = dirtyLines.start;
var endLine = dirtyLines.end;
+ var originalSelection = this._lastSelection;
var editInfo = this._guessEditRangeBasedOnSelection(startLine, endLine, lines);
if (!editInfo) {
if (WebInspector.debugDefaultTextEditor)
@@ -2491,7 +2492,7 @@
}
}
- this._textModel.editRange(editInfo.range, editInfo.text);
+ this._textModel.editRange(editInfo.range, editInfo.text, originalSelection);
this._restoreSelection(selection);
},
@@ -3399,7 +3400,7 @@
return false;
var newSelection = this._rangeForCtrlArrowMove(selection, "left");
- this._textModel.editRange(newSelection.normalize(), "");
+ this._textModel.editRange(newSelection.normalize(), "", selection);
this._textEditor.setSelection(newSelection.collapseToEnd());
return true;
Modified: trunk/Source/WebCore/inspector/front-end/TextEditorModel.js (142997 => 142998)
--- trunk/Source/WebCore/inspector/front-end/TextEditorModel.js 2013-02-15 15:33:57 UTC (rev 142997)
+++ trunk/Source/WebCore/inspector/front-end/TextEditorModel.js 2013-02-15 15:45:50 UTC (rev 142998)
@@ -147,11 +147,13 @@
* @constructor
* @param {WebInspector.TextRange} newRange
* @param {string} originalText
+ * @param {WebInspector.TextRange} originalSelection
*/
-WebInspector.TextEditorCommand = function(newRange, originalText)
+WebInspector.TextEditorCommand = function(newRange, originalText, originalSelection)
{
this.newRange = newRange;
this.originalText = originalText;
+ this.originalSelection = originalSelection;
}
/**
@@ -250,26 +252,28 @@
/**
* @param {WebInspector.TextRange} range
* @param {string} text
+ * @param {WebInspector.TextRange=} originalSelection
* @return {WebInspector.TextRange}
*/
- editRange: function(range, text)
+ editRange: function(range, text, originalSelection)
{
if (this._lastEditedRange && (!text || text.indexOf("\n") !== -1 || this._lastEditedRange.endLine !== range.startLine || this._lastEditedRange.endColumn !== range.startColumn))
this._markUndoableState();
- return this._innerEditRange(range, text);
+ return this._innerEditRange(range, text, originalSelection);
},
/**
* @param {WebInspector.TextRange} range
* @param {string} text
+ * @param {WebInspector.TextRange=} originalSelection
* @return {WebInspector.TextRange}
*/
- _innerEditRange: function(range, text)
+ _innerEditRange: function(range, text, originalSelection)
{
var originalText = this.copyRange(range);
var newRange = this._innerSetText(range, text);
- this._pushUndoableCommand(newRange, originalText);
this._lastEditedRange = newRange;
+ this._pushUndoableCommand(newRange, originalText, originalSelection || range);
this.dispatchEventToListeners(WebInspector.TextEditorModel.Events.TextChanged, { oldRange: range, newRange: newRange, editRange: true });
return newRange;
},
@@ -459,11 +463,12 @@
/**
* @param {WebInspector.TextRange} newRange
* @param {string} originalText
+ * @param {WebInspector.TextRange} originalSelection
* @return {WebInspector.TextEditorCommand}
*/
- _pushUndoableCommand: function(newRange, originalText)
+ _pushUndoableCommand: function(newRange, originalText, originalSelection)
{
- var command = new WebInspector.TextEditorCommand(newRange.clone(), originalText);
+ var command = new WebInspector.TextEditorCommand(newRange.clone(), originalText, originalSelection);
if (this._inUndo)
this._redoStack.push(command);
else {
@@ -517,7 +522,8 @@
for (var i = stack.length - 1; i >= 0; --i) {
var command = stack[i];
stack.length = i;
- range = this._innerEditRange(command.newRange, command.originalText);
+ this._innerEditRange(command.newRange, command.originalText);
+ range = command.originalSelection;
if (i > 0 && stack[i - 1].explicit)
return range;
}