提交 49220160 编写于 作者: I Inori

add selectAllMatches command

上级 849abd65
......@@ -220,6 +220,15 @@ export class CommonFindController extends Disposable implements editorCommon.IEd
}
return false;
}
public selectAllMatches(): boolean {
if (this._model) {
this._model.selectAll();
this.closeFindWidget();
return true;
}
return false;
}
}
export class StartFindAction extends EditorAction {
......@@ -722,3 +731,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 {SelectAllMatchesCommand} from './selectAllMatchesCommand';
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;
......@@ -350,6 +352,20 @@ export class FindModelBoundToEditorModel {
this.research(false);
}
public selectAll(): 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);
let command = new SelectAllMatchesCommand(this._editor, ranges);
this._executeEditorCommand('selectAllMatches', command);
}
private _executeEditorCommand(source:string, command:editorCommon.ICommand): void {
try {
this._ignoreModelContentChanged = true;
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import {Selection} from 'vs/editor/common/core/selection';
import {ISelection} from 'vs/editor/common/editorCommon';
import * as editorCommon from 'vs/editor/common/editorCommon';
export class SelectAllMatchesCommand implements editorCommon.ICommand {
private _editor:editorCommon.ICommonCodeEditor;
private _ranges: editorCommon.IEditorRange[];
constructor(editor:editorCommon.ICommonCodeEditor, ranges: editorCommon.IEditorRange[]) {
this._editor = editor;
this._ranges = ranges;
}
public getEditOperations(model:editorCommon.ITokenizedModel, builder:editorCommon.IEditOperationBuilder): void {
if (this._ranges.length > 0) {
// Collect all select operations
let newSelections = new Array<ISelection>();
for (var i = 0; i < this._ranges.length; i++) {
newSelections.push({
selectionStartLineNumber: this._ranges[i].startLineNumber,
selectionStartColumn: this._ranges[i].startColumn,
positionLineNumber: this._ranges[i].startLineNumber,
positionColumn: this._ranges[i].endColumn
});
}
this._editor.setSelections(newSelections);
}
}
public computeCursorState(model:editorCommon.ITokenizedModel, helper: editorCommon.ICursorStateComputerData): editorCommon.IEditorSelection {
var inverseEditOperations = helper.getInverseEditOperations();
var srcRange = inverseEditOperations[inverseEditOperations.length - 1].range;
return Selection.createSelection(
srcRange.endLineNumber,
srcRange.endColumn,
srcRange.endLineNumber,
srcRange.endColumn
);
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册