提交 3fa0a5b1 编写于 作者: A Alex Dima

Fixes #3516: Keep editor selection steady when doing replaceAll

上级 d1220909
......@@ -350,7 +350,7 @@ export class FindModelBoundToEditorModel {
replaceStrings.push(this.getReplaceString(model.getValueInRange(ranges[i])));
}
let command = new ReplaceAllCommand(ranges, replaceStrings);
let command = new ReplaceAllCommand(this._editor.getSelection(), ranges, replaceStrings);
this._executeEditorCommand('replaceAll', command);
this.research(false);
......
......@@ -15,10 +15,13 @@ interface IEditOperation {
export class ReplaceAllCommand implements editorCommon.ICommand {
private _editorSelection: Selection;
private _trackedEditorSelectionId: string;
private _ranges: Range[];
private _replaceStrings: string[];
constructor(ranges: Range[], replaceStrings:string[]) {
constructor(editorSelection:Selection, ranges: Range[], replaceStrings:string[]) {
this._editorSelection = editorSelection;
this._ranges = ranges;
this._replaceStrings = replaceStrings;
}
......@@ -58,16 +61,11 @@ export class ReplaceAllCommand implements editorCommon.ICommand {
builder.addEditOperation(resultOps[i].range, resultOps[i].text);
}
}
this._trackedEditorSelectionId = builder.trackSelection(this._editorSelection);
}
public computeCursorState(model:editorCommon.ITokenizedModel, helper: editorCommon.ICursorStateComputerData): Selection {
var inverseEditOperations = helper.getInverseEditOperations();
var srcRange = inverseEditOperations[inverseEditOperations.length - 1].range;
return Selection.createSelection(
srcRange.endLineNumber,
srcRange.endColumn,
srcRange.endLineNumber,
srcRange.endColumn
);
return helper.getTrackedSelection(this._trackedEditorSelectionId);
}
}
......@@ -1212,7 +1212,7 @@ suite('FindModel', () => {
findModel.replaceAll();
assertFindState(
editor,
[8, 16, 8, 16],
[6, 17, 6, 17],
null,
[ ]
);
......@@ -1248,7 +1248,7 @@ suite('FindModel', () => {
findModel.replaceAll();
assertFindState(
editor,
[9, 3, 9, 3],
[1, 1, 1, 1],
null,
[
[6, 1, 6, 3],
......@@ -1285,7 +1285,7 @@ suite('FindModel', () => {
findModel.replaceAll();
assertFindState(
editor,
[11, 16, 11, 16],
[1, 1, 1, 1],
null,
[]
);
......@@ -1314,7 +1314,7 @@ suite('FindModel', () => {
findModel.replaceAll();
assertFindState(
editor,
[14, 3, 14, 3],
[1, 1, 1, 1],
null,
[]
);
......@@ -1327,6 +1327,36 @@ suite('FindModel', () => {
findState.dispose();
});
findTest('issue #3516: "replace all" moves page/cursor/focus/scroll to the place of the last replacement', (editor, cursor) => {
let findState = new FindReplaceState();
findState.change({ searchString: 'include', replaceString: 'bar' }, false);
let findModel = new FindModelBoundToEditorModel(editor, findState);
assertFindState(
editor,
[1, 1, 1, 1],
null,
[
[2, 2, 2, 9],
[3, 2, 3, 9]
]
);
findModel.replaceAll();
assertFindState(
editor,
[1, 1, 1, 1],
null,
[]
);
assert.equal(editor.getModel().getLineContent(2), '#bar "cool.h"');
assert.equal(editor.getModel().getLineContent(3), '#bar <iostream>');
findModel.dispose();
findState.dispose();
});
findTest('finds only in editable range if replace is shown', (editor, cursor) => {
editor.getModel().setEditableRange({
startLineNumber: 6,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册