mirror of
https://github.com/Microsoft/vscode
synced 2024-10-12 06:17:18 +00:00
Fixes #14143: Maintain editor's selection as primary range if it is one of the find matches
This commit is contained in:
parent
6dd7a04bbd
commit
d55daa1998
|
@ -428,8 +428,19 @@ export class FindModelBoundToEditorModel {
|
|||
|
||||
// Get all the ranges (even more than the highlighted ones)
|
||||
let ranges = this._findMatches(findScope, Number.MAX_VALUE);
|
||||
let selections = ranges.map(r => new Selection(r.startLineNumber, r.startColumn, r.endLineNumber, r.endColumn));
|
||||
|
||||
this._editor.setSelections(ranges.map(r => new Selection(r.startLineNumber, r.startColumn, r.endLineNumber, r.endColumn)));
|
||||
// If one of the ranges is the editor selection, then maintain it as primary
|
||||
let editorSelection = this._editor.getSelection();
|
||||
for (let i = 0, len = selections.length; i < len; i++) {
|
||||
let sel = selections[i];
|
||||
if (sel.equalsRange(editorSelection)) {
|
||||
selections = [editorSelection].concat(selections.slice(0, i)).concat(selections.slice(i + 1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this._editor.setSelections(selections);
|
||||
}
|
||||
|
||||
private _executeEditorCommand(source: string, command: editorCommon.ICommand): void {
|
||||
|
|
|
@ -1585,6 +1585,52 @@ suite('FindModel', () => {
|
|||
findState.dispose();
|
||||
});
|
||||
|
||||
findTest('issue #14143 selectAllMatches should maintain primary cursor if feasible', (editor, cursor) => {
|
||||
let findState = new FindReplaceState();
|
||||
findState.change({ searchString: 'hello', replaceString: 'hi', wholeWord: true }, false);
|
||||
let findModel = new FindModelBoundToEditorModel(editor, findState);
|
||||
|
||||
assertFindState(
|
||||
editor,
|
||||
[1, 1, 1, 1],
|
||||
null,
|
||||
[
|
||||
[6, 14, 6, 19],
|
||||
[6, 27, 6, 32],
|
||||
[7, 14, 7, 19],
|
||||
[8, 14, 8, 19]
|
||||
]
|
||||
);
|
||||
|
||||
editor.setSelection(new Range(7, 14, 7, 19));
|
||||
|
||||
findModel.selectAllMatches();
|
||||
|
||||
assert.deepEqual(editor.getSelections().map(s => s.toString()), [
|
||||
new Selection(7, 14, 7, 19),
|
||||
new Selection(6, 14, 6, 19),
|
||||
new Selection(6, 27, 6, 32),
|
||||
new Selection(8, 14, 8, 19)
|
||||
].map(s => s.toString()));
|
||||
|
||||
assert.deepEqual(editor.getSelection().toString(), new Selection(7, 14, 7, 19).toString());
|
||||
|
||||
assertFindState(
|
||||
editor,
|
||||
[7, 14, 7, 19],
|
||||
null,
|
||||
[
|
||||
[6, 14, 6, 19],
|
||||
[6, 27, 6, 32],
|
||||
[7, 14, 7, 19],
|
||||
[8, 14, 8, 19]
|
||||
]
|
||||
);
|
||||
|
||||
findModel.dispose();
|
||||
findState.dispose();
|
||||
});
|
||||
|
||||
findTest('issue #1914: NPE when there is only one find match', (editor, cursor) => {
|
||||
let findState = new FindReplaceState();
|
||||
findState.change({ searchString: 'cool.h' }, false);
|
||||
|
|
Loading…
Reference in a new issue