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

Merge pull request #5715 from Inori/select_all_find_matches

Add selectAllMatches command in find widget.
......@@ -220,6 +220,15 @@ export class CommonFindController extends Disposable implements editorCommon.IEd
}
return false;
}
public selectAllMatches(): boolean {
if (this._model) {
this._model.selectAllMatches();
this._editor.focus();
return true;
}
return false;
}
}
export class StartFindAction extends EditorAction {
......@@ -726,3 +735,6 @@ registerFindCommand(FIND_IDS.ReplaceOneAction, x => x.replace(), {
registerFindCommand(FIND_IDS.ReplaceAllAction, x => x.replaceAll(), {
primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.Enter
});
registerFindCommand(FIND_IDS.SelectAllMatchesAction, x => x.selectAllMatches(), {
primary: KeyMod.Alt | KeyCode.Enter
});
......@@ -14,6 +14,7 @@ import * as editorCommon from 'vs/editor/common/editorCommon';
import {FindDecorations} from './findDecorations';
import {FindReplaceState, FindReplaceStateChangedEvent} from './findState';
import {ReplaceAllCommand} from './replaceAllCommand';
import {Selection} from 'vs/editor/common/core/selection';
export const FIND_IDS = {
StartFindAction: 'actions.find',
......@@ -29,7 +30,8 @@ export const FIND_IDS = {
ToggleWholeWordCommand: 'toggleFindWholeWord',
ToggleRegexCommand: 'toggleFindRegex',
ReplaceOneAction: 'editor.action.replaceOne',
ReplaceAllAction: 'editor.action.replaceAll'
ReplaceAllAction: 'editor.action.replaceAll',
SelectAllMatchesAction: 'editor.action.selectAllMatches'
};
export const MATCHES_LIMIT = 999;
......@@ -354,6 +356,19 @@ export class FindModelBoundToEditorModel {
this.research(false);
}
public selectAllMatches(): void {
if (!this._hasMatches()) {
return;
}
let findScope = this._decorations.getFindScope();
// Get all the ranges (even more than the highlighted ones)
let ranges = this._findMatches(findScope, Number.MAX_VALUE);
this._editor.setSelections(ranges.map(r => new Selection(r.startLineNumber, r.startColumn, r.endLineNumber, r.endColumn)));
}
private _executeEditorCommand(source:string, command:editorCommon.ICommand): void {
try {
this._ignoreModelContentChanged = true;
......
......@@ -7,6 +7,7 @@
import * as assert from 'assert';
import {Cursor} from 'vs/editor/common/controller/cursor';
import {Position} from 'vs/editor/common/core/position';
import {Selection} from 'vs/editor/common/core/selection';
import {Range} from 'vs/editor/common/core/range';
import {Handler, ICommonCodeEditor, IRange} from 'vs/editor/common/editorCommon';
import {FindModelBoundToEditorModel, parseReplaceString} from 'vs/editor/contrib/find/common/findModel';
......@@ -1395,6 +1396,48 @@ suite('FindModel', () => {
findState.dispose();
});
findTest('selectAllMatches', (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]
]
);
findModel.selectAllMatches();
assert.deepEqual(editor.getSelections().map(s => s.toString()), [
new Selection(6, 14, 6, 19),
new Selection(6, 27, 6, 32),
new Selection(7, 14, 7, 19),
new Selection(8, 14, 8, 19)
].map(s => s.toString()));
assertFindState(
editor,
[6, 14, 6, 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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册