findController.ts 20.3 KB
Newer Older
1 2 3 4 5 6 7
/*---------------------------------------------------------------------------------------------
 *  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 * as nls from 'vs/nls';
J
Johannes Rieken 已提交
8
import { HistoryNavigator } from 'vs/base/common/history';
9
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
J
Johannes Rieken 已提交
10 11
import { Disposable } from 'vs/base/common/lifecycle';
import { ContextKeyExpr, RawContextKey, IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
12
import * as strings from 'vs/base/common/strings';
A
Alex Dima 已提交
13
import * as editorCommon from 'vs/editor/common/editorCommon';
14
import { registerEditorAction, ServicesAccessor, EditorAction, EditorCommand, CommonEditorRegistry } from 'vs/editor/common/editorCommonExtensions';
15 16
import { FIND_IDS, FindModelBoundToEditorModel, ToggleCaseSensitiveKeybinding, ToggleRegexKeybinding, ToggleWholeWordKeybinding, ToggleSearchScopeKeybinding, ShowPreviousFindTermKeybinding, ShowNextFindTermKeybinding } from 'vs/editor/contrib/find/findModel';
import { FindReplaceState, FindReplaceStateChangedEvent, INewFindReplaceState } from 'vs/editor/contrib/find/findState';
17
import { Delayer } from 'vs/base/common/async';
18
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
19
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
A
Alex Dima 已提交
20

21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
export function getSelectionSearchString(editor: editorCommon.ICommonCodeEditor): string {
	let selection = editor.getSelection();

	// if selection spans multiple lines, default search string to empty
	if (selection.startLineNumber === selection.endLineNumber) {
		if (selection.isEmpty()) {
			let wordAtPosition = editor.getModel().getWordAtPosition(selection.getStartPosition());
			if (wordAtPosition) {
				return wordAtPosition.word;
			}
		} else {
			return editor.getModel().getValueInRange(selection);
		}
	}

	return null;
}

A
Alex Dima 已提交
39
export const enum FindStartFocusAction {
40 41 42 43 44 45
	NoFocusChange,
	FocusFindInput,
	FocusReplaceInput
}

export interface IFindStartOptions {
46 47 48 49
	forceRevealReplace: boolean;
	seedSearchStringFromSelection: boolean;
	shouldFocus: FindStartFocusAction;
	shouldAnimate: boolean;
50 51
}

A
Alex Dima 已提交
52
export const CONTEXT_FIND_WIDGET_VISIBLE = new RawContextKey<boolean>('findWidgetVisible', false);
A
Alex Dima 已提交
53
export const CONTEXT_FIND_WIDGET_NOT_VISIBLE: ContextKeyExpr = CONTEXT_FIND_WIDGET_VISIBLE.toNegated();
54
// Keep ContextKey use of 'Focussed' to not break when clauses
A
Alex Dima 已提交
55
export const CONTEXT_FIND_INPUT_FOCUSED = new RawContextKey<boolean>('findInputFocussed', false);
56

A
Alex Dima 已提交
57
export class CommonFindController extends Disposable implements editorCommon.IEditorContribution {
58

59
	private static ID = 'editor.contrib.findController';
60

A
Alex Dima 已提交
61
	private _editor: editorCommon.ICommonCodeEditor;
A
Alex Dima 已提交
62
	private _findWidgetVisible: IContextKey<boolean>;
63
	protected _state: FindReplaceState;
64
	private _currentHistoryNavigator: HistoryNavigator<string>;
S
Sandeep Somavarapu 已提交
65
	protected _updateHistoryDelayer: Delayer<void>;
66
	private _model: FindModelBoundToEditorModel;
67
	private _storageService: IStorageService;
68

69
	public static get(editor: editorCommon.ICommonCodeEditor): CommonFindController {
A
Alex Dima 已提交
70
		return editor.getContribution<CommonFindController>(CommonFindController.ID);
71 72
	}

73
	constructor(editor: editorCommon.ICommonCodeEditor, @IContextKeyService contextKeyService: IContextKeyService, @IStorageService storageService: IStorageService) {
74 75
		super();
		this._editor = editor;
76
		this._findWidgetVisible = CONTEXT_FIND_WIDGET_VISIBLE.bindTo(contextKeyService);
77
		this._storageService = storageService;
78

79 80
		this._updateHistoryDelayer = new Delayer<void>(500);
		this._currentHistoryNavigator = new HistoryNavigator<string>();
81
		this._state = this._register(new FindReplaceState());
82
		this.loadQueryState();
83 84 85 86
		this._register(this._state.addChangeListener((e) => this._onStateChanged(e)));

		this._model = null;

A
Alex Dima 已提交
87
		this._register(this._editor.onDidChangeModel(() => {
88 89 90 91
			let shouldRestartFind = (this._editor.getModel() && this._state.isRevealed);

			this.disposeModel();

92
			this._state.change({
93 94 95 96
				searchScope: null,
				matchCase: this._storageService.getBoolean('editor.matchCase', StorageScope.WORKSPACE, false),
				wholeWord: this._storageService.getBoolean('editor.wholeWord', StorageScope.WORKSPACE, false),
				isRegex: this._storageService.getBoolean('editor.isRegex', StorageScope.WORKSPACE, false)
97 98
			}, false);

99 100 101 102 103
			if (shouldRestartFind) {
				this._start({
					forceRevealReplace: false,
					seedSearchStringFromSelection: false,
					shouldFocus: FindStartFocusAction.NoFocusChange,
104
					shouldAnimate: false,
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
				});
			}
		}));
	}

	public dispose(): void {
		this.disposeModel();
		super.dispose();
	}

	private disposeModel(): void {
		if (this._model) {
			this._model.dispose();
			this._model = null;
		}
	}

	public getId(): string {
		return CommonFindController.ID;
	}

126
	private _onStateChanged(e: FindReplaceStateChangedEvent): void {
127 128
		this.saveQueryState(e);

129 130 131
		if (e.updateHistory && e.searchString) {
			this._delayedUpdateHistory();
		}
132 133 134 135 136 137 138 139 140 141
		if (e.isRevealed) {
			if (this._state.isRevealed) {
				this._findWidgetVisible.set(true);
			} else {
				this._findWidgetVisible.reset();
				this.disposeModel();
			}
		}
	}

142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
	private saveQueryState(e: FindReplaceStateChangedEvent) {
		if (e.isRegex && typeof this._state.isRegex !== 'undefined') {
			this._storageService.store('editor.isRegex', this._state.isRegex, StorageScope.WORKSPACE);
		}
		if (e.wholeWord && typeof this._state.wholeWord !== 'undefined') {
			this._storageService.store('editor.wholeWord', this._state.wholeWord, StorageScope.WORKSPACE);
		}
		if (e.matchCase && typeof this._state.matchCase !== 'undefined') {
			this._storageService.store('editor.matchCase', this._state.matchCase, StorageScope.WORKSPACE);
		}
	}

	private loadQueryState() {
		this._state.change({
			matchCase: this._storageService.getBoolean('editor.matchCase', StorageScope.WORKSPACE, this._state.matchCase),
			wholeWord: this._storageService.getBoolean('editor.wholeWord', StorageScope.WORKSPACE, this._state.wholeWord),
			isRegex: this._storageService.getBoolean('editor.isRegex', StorageScope.WORKSPACE, this._state.isRegex)
		}, false);
	}

162 163 164 165 166 167 168 169 170 171
	protected _delayedUpdateHistory() {
		this._updateHistoryDelayer.trigger(this._updateHistory.bind(this));
	}

	protected _updateHistory() {
		if (this._state.searchString) {
			this._currentHistoryNavigator.add(this._state.searchString);
		}
	}

172 173 174 175
	public getState(): FindReplaceState {
		return this._state;
	}

176 177 178 179
	public getHistory(): HistoryNavigator<string> {
		return this._currentHistoryNavigator;
	}

180
	public closeFindWidget(): void {
181 182 183 184
		this._state.change({
			isRevealed: false,
			searchScope: null
		}, false);
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
		this._editor.focus();
	}

	public toggleCaseSensitive(): void {
		this._state.change({ matchCase: !this._state.matchCase }, false);
	}

	public toggleWholeWords(): void {
		this._state.change({ wholeWord: !this._state.wholeWord }, false);
	}

	public toggleRegex(): void {
		this._state.change({ isRegex: !this._state.isRegex }, false);
	}

200 201 202 203 204 205 206 207 208 209 210 211 212 213
	public toggleSearchScope(): void {
		if (this._state.searchScope) {
			this._state.change({ searchScope: null }, true);
		} else {
			let selection = this._editor.getSelection();
			if (selection.endColumn === 1 && selection.endLineNumber > selection.startLineNumber) {
				selection = selection.setEndPosition(selection.endLineNumber - 1, 1);
			}
			if (!selection.isEmpty()) {
				this._state.change({ searchScope: selection }, true);
			}
		}
	}

214
	public setSearchString(searchString: string): void {
215 216 217
		this._state.change({ searchString: searchString }, false);
	}

218 219 220 221
	public highlightFindOptions(): void {
		// overwritten in subclass
	}

222
	protected _start(opts: IFindStartOptions): void {
223 224 225 226 227 228 229 230 231 232 233 234
		this.disposeModel();

		if (!this._editor.getModel()) {
			// cannot do anything with an editor that doesn't have a model...
			return;
		}

		let stateChanges: INewFindReplaceState = {
			isRevealed: true
		};

		// Consider editor selection and overwrite the state with it
235
		if (opts.seedSearchStringFromSelection && this._editor.getConfiguration().contribInfo.find.seedSearchStringFromSelection) {
236
			let selectionSearchString = getSelectionSearchString(this._editor);
237
			if (selectionSearchString) {
238 239 240 241 242
				if (this._state.isRegex) {
					stateChanges.searchString = strings.escapeRegExpCharacters(selectionSearchString);
				} else {
					stateChanges.searchString = selectionSearchString;
				}
243 244 245 246 247 248
			}
		}

		// Overwrite isReplaceRevealed
		if (opts.forceRevealReplace) {
			stateChanges.isReplaceRevealed = true;
249 250
		} else if (!this._findWidgetVisible.get()) {
			stateChanges.isReplaceRevealed = false;
251 252
		}

253

254 255 256 257 258 259 260
		this._state.change(stateChanges, false);

		if (!this._model) {
			this._model = new FindModelBoundToEditorModel(this._editor, this._state);
		}
	}

261
	public start(opts: IFindStartOptions): void {
262
		this._start(opts);
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
	}

	public moveToNextMatch(): boolean {
		if (this._model) {
			this._model.moveToNextMatch();
			return true;
		}
		return false;
	}

	public moveToPrevMatch(): boolean {
		if (this._model) {
			this._model.moveToPrevMatch();
			return true;
		}
		return false;
	}

	public replace(): boolean {
		if (this._model) {
			this._model.replace();
			return true;
		}
		return false;
	}

	public replaceAll(): boolean {
		if (this._model) {
			this._model.replaceAll();
			return true;
		}
		return false;
	}
I
Inori 已提交
296 297 298

	public selectAllMatches(): boolean {
		if (this._model) {
I
Inori 已提交
299
			this._model.selectAllMatches();
300
			this._editor.focus();
I
Inori 已提交
301 302 303 304
			return true;
		}
		return false;
	}
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320

	public showPreviousFindTerm(): boolean {
		let previousTerm = this._currentHistoryNavigator.previous();
		if (previousTerm) {
			this._state.change({ searchString: previousTerm }, false, false);
		}
		return true;
	}

	public showNextFindTerm(): boolean {
		let nextTerm = this._currentHistoryNavigator.next();
		if (nextTerm) {
			this._state.change({ searchString: nextTerm }, false, false);
		}
		return true;
	}
321 322
}

A
Alex Dima 已提交
323
export class StartFindAction extends EditorAction {
324

A
Alex Dima 已提交
325
	constructor() {
326 327
		super({
			id: FIND_IDS.StartFindAction,
328
			label: nls.localize('startFindAction', "Find"),
329 330 331 332
			alias: 'Find',
			precondition: null,
			kbOpts: {
				kbExpr: null,
333 334 335 336 337
				primary: KeyMod.CtrlCmd | KeyCode.KEY_F,
				mac: {
					primary: KeyMod.CtrlCmd | KeyCode.KEY_F,
					secondary: [KeyMod.CtrlCmd | KeyCode.KEY_E]
				}
338 339
			}
		});
340 341
	}

342
	public run(accessor: ServicesAccessor, editor: editorCommon.ICommonCodeEditor): void {
A
Alex Dima 已提交
343
		let controller = CommonFindController.get(editor);
344 345 346 347 348 349 350 351
		if (controller) {
			controller.start({
				forceRevealReplace: false,
				seedSearchStringFromSelection: true,
				shouldFocus: FindStartFocusAction.FocusFindInput,
				shouldAnimate: true
			});
		}
352 353 354
	}
}

A
Alex Dima 已提交
355
export abstract class MatchFindAction extends EditorAction {
356
	public run(accessor: ServicesAccessor, editor: editorCommon.ICommonCodeEditor): void {
A
Alex Dima 已提交
357
		let controller = CommonFindController.get(editor);
358
		if (controller && !this._run(controller)) {
359 360 361 362 363 364
			controller.start({
				forceRevealReplace: false,
				seedSearchStringFromSelection: (controller.getState().searchString.length === 0),
				shouldFocus: FindStartFocusAction.NoFocusChange,
				shouldAnimate: true
			});
365
			this._run(controller);
366 367
		}
	}
368

369
	protected abstract _run(controller: CommonFindController): boolean;
370 371
}

372
export class NextMatchFindAction extends MatchFindAction {
A
Alex Dima 已提交
373 374

	constructor() {
375 376 377 378 379 380
		super({
			id: FIND_IDS.NextMatchFindAction,
			label: nls.localize('findNextMatchAction', "Find Next"),
			alias: 'Find Next',
			precondition: null,
			kbOpts: {
381
				kbExpr: EditorContextKeys.focus,
382 383 384 385
				primary: KeyCode.F3,
				mac: { primary: KeyMod.CtrlCmd | KeyCode.KEY_G, secondary: [KeyCode.F3] }
			}
		});
A
Alex Dima 已提交
386 387
	}

388
	protected _run(controller: CommonFindController): boolean {
389 390 391
		return controller.moveToNextMatch();
	}
}
392

393
export class PreviousMatchFindAction extends MatchFindAction {
A
Alex Dima 已提交
394 395

	constructor() {
396 397 398 399 400 401
		super({
			id: FIND_IDS.PreviousMatchFindAction,
			label: nls.localize('findPreviousMatchAction', "Find Previous"),
			alias: 'Find Previous',
			precondition: null,
			kbOpts: {
402
				kbExpr: EditorContextKeys.focus,
403 404 405 406
				primary: KeyMod.Shift | KeyCode.F3,
				mac: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_G, secondary: [KeyMod.Shift | KeyCode.F3] }
			}
		});
A
Alex Dima 已提交
407 408
	}

409
	protected _run(controller: CommonFindController): boolean {
410 411 412 413
		return controller.moveToPrevMatch();
	}
}

A
Alex Dima 已提交
414
export abstract class SelectionMatchFindAction extends EditorAction {
415
	public run(accessor: ServicesAccessor, editor: editorCommon.ICommonCodeEditor): void {
A
Alex Dima 已提交
416
		let controller = CommonFindController.get(editor);
417 418 419
		if (!controller) {
			return;
		}
420
		let selectionSearchString = getSelectionSearchString(editor);
421 422 423 424
		if (selectionSearchString) {
			controller.setSearchString(selectionSearchString);
		}
		if (!this._run(controller)) {
425 426
			controller.start({
				forceRevealReplace: false,
427
				seedSearchStringFromSelection: false,
428 429 430
				shouldFocus: FindStartFocusAction.NoFocusChange,
				shouldAnimate: true
			});
431
			this._run(controller);
432 433
		}
	}
434

435
	protected abstract _run(controller: CommonFindController): boolean;
436 437 438
}

export class NextSelectionMatchFindAction extends SelectionMatchFindAction {
A
Alex Dima 已提交
439 440

	constructor() {
441 442 443 444 445 446
		super({
			id: FIND_IDS.NextSelectionMatchFindAction,
			label: nls.localize('nextSelectionMatchFindAction', "Find Next Selection"),
			alias: 'Find Next Selection',
			precondition: null,
			kbOpts: {
447
				kbExpr: EditorContextKeys.focus,
448 449 450
				primary: KeyMod.CtrlCmd | KeyCode.F3
			}
		});
A
Alex Dima 已提交
451 452
	}

453
	protected _run(controller: CommonFindController): boolean {
454 455 456 457 458
		return controller.moveToNextMatch();
	}
}

export class PreviousSelectionMatchFindAction extends SelectionMatchFindAction {
A
Alex Dima 已提交
459 460

	constructor() {
461 462 463 464 465 466
		super({
			id: FIND_IDS.PreviousSelectionMatchFindAction,
			label: nls.localize('previousSelectionMatchFindAction', "Find Previous Selection"),
			alias: 'Find Previous Selection',
			precondition: null,
			kbOpts: {
467
				kbExpr: EditorContextKeys.focus,
468 469 470
				primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.F3
			}
		});
A
Alex Dima 已提交
471 472
	}

473
	protected _run(controller: CommonFindController): boolean {
474 475
		return controller.moveToPrevMatch();
	}
476 477
}

A
Alex Dima 已提交
478
export class StartFindReplaceAction extends EditorAction {
A
Alex Dima 已提交
479 480

	constructor() {
481 482 483 484 485 486 487 488 489 490 491
		super({
			id: FIND_IDS.StartFindReplaceAction,
			label: nls.localize('startReplace', "Replace"),
			alias: 'Replace',
			precondition: null,
			kbOpts: {
				kbExpr: null,
				primary: KeyMod.CtrlCmd | KeyCode.KEY_H,
				mac: { primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.KEY_F }
			}
		});
492 493
	}

494
	public run(accessor: ServicesAccessor, editor: editorCommon.ICommonCodeEditor): void {
495 496 497 498
		if (editor.getConfiguration().readOnly) {
			return;
		}

A
Alex Dima 已提交
499
		let controller = CommonFindController.get(editor);
500 501
		let currentSelection = editor.getSelection();
		// we only seed search string from selection when the current selection is single line and not empty.
R
rebornix 已提交
502 503
		let seedSearchStringFromSelection = !currentSelection.isEmpty() &&
			currentSelection.startLineNumber === currentSelection.endLineNumber;
504 505 506
		let oldSearchString = controller.getState().searchString;
		// if the existing search string in find widget is empty and we don't seed search string from selection, it means the Find Input
		// is still empty, so we should focus the Find Input instead of Replace Input.
R
rebornix 已提交
507 508
		let shouldFocus = (!!oldSearchString || seedSearchStringFromSelection) ?
			FindStartFocusAction.FocusReplaceInput : FindStartFocusAction.FocusFindInput;
509

510 511 512
		if (controller) {
			controller.start({
				forceRevealReplace: true,
513 514
				seedSearchStringFromSelection: seedSearchStringFromSelection,
				shouldFocus: shouldFocus,
515 516 517
				shouldAnimate: true
			});
		}
518 519 520
	}
}

S
Sandeep Somavarapu 已提交
521 522 523 524 525 526 527 528 529 530
export class ShowNextFindTermAction extends MatchFindAction {

	constructor() {
		super({
			id: FIND_IDS.ShowNextFindTermAction,
			label: nls.localize('showNextFindTermAction', "Show Next Find Term"),
			alias: 'Show Next Find Term',
			precondition: CONTEXT_FIND_WIDGET_VISIBLE,
			kbOpts: {
				weight: CommonEditorRegistry.commandWeight(5),
A
Alex Dima 已提交
531
				kbExpr: ContextKeyExpr.and(CONTEXT_FIND_INPUT_FOCUSED, EditorContextKeys.focus),
S
Sandeep Somavarapu 已提交
532 533 534 535 536 537 538 539 540 541 542 543 544
				primary: ShowNextFindTermKeybinding.primary,
				mac: ShowNextFindTermKeybinding.mac,
				win: ShowNextFindTermKeybinding.win,
				linux: ShowNextFindTermKeybinding.linux
			}
		});
	}

	protected _run(controller: CommonFindController): boolean {
		return controller.showNextFindTerm();
	}
}

545
export class ShowPreviousFindTermAction extends MatchFindAction {
S
Sandeep Somavarapu 已提交
546 547 548 549 550 551 552 553 554

	constructor() {
		super({
			id: FIND_IDS.ShowPreviousFindTermAction,
			label: nls.localize('showPreviousFindTermAction', "Show Previous Find Term"),
			alias: 'Find Show Previous Find Term',
			precondition: CONTEXT_FIND_WIDGET_VISIBLE,
			kbOpts: {
				weight: CommonEditorRegistry.commandWeight(5),
A
Alex Dima 已提交
555
				kbExpr: ContextKeyExpr.and(CONTEXT_FIND_INPUT_FOCUSED, EditorContextKeys.focus),
S
Sandeep Somavarapu 已提交
556 557 558 559 560 561 562 563 564 565 566 567 568
				primary: ShowPreviousFindTermKeybinding.primary,
				mac: ShowPreviousFindTermKeybinding.mac,
				win: ShowPreviousFindTermKeybinding.win,
				linux: ShowPreviousFindTermKeybinding.linux
			}
		});
	}

	protected _run(controller: CommonFindController): boolean {
		return controller.showPreviousFindTerm();
	}
}

569 570 571 572 573 574 575 576
registerEditorAction(StartFindAction);
registerEditorAction(NextMatchFindAction);
registerEditorAction(PreviousMatchFindAction);
registerEditorAction(NextSelectionMatchFindAction);
registerEditorAction(PreviousSelectionMatchFindAction);
registerEditorAction(StartFindReplaceAction);
registerEditorAction(ShowNextFindTermAction);
registerEditorAction(ShowPreviousFindTermAction);
577

A
Alex Dima 已提交
578
const FindCommand = EditorCommand.bindToContribution<CommonFindController>(CommonFindController.get);
A
Alex Dima 已提交
579

580
CommonEditorRegistry.registerEditorCommand(new FindCommand({
581 582 583 584
	id: FIND_IDS.CloseFindWidgetCommand,
	precondition: CONTEXT_FIND_WIDGET_VISIBLE,
	handler: x => x.closeFindWidget(),
	kbOpts: {
A
Alex Dima 已提交
585
		weight: CommonEditorRegistry.commandWeight(5),
586
		kbExpr: EditorContextKeys.focus,
A
Alex Dima 已提交
587 588 589
		primary: KeyCode.Escape,
		secondary: [KeyMod.Shift | KeyCode.Escape]
	}
590
}));
A
Alex Dima 已提交
591

592
CommonEditorRegistry.registerEditorCommand(new FindCommand({
593 594 595 596 597
	id: FIND_IDS.ToggleCaseSensitiveCommand,
	precondition: null,
	handler: x => x.toggleCaseSensitive(),
	kbOpts: {
		weight: CommonEditorRegistry.commandWeight(5),
598
		kbExpr: EditorContextKeys.focus,
S
Sandeep Somavarapu 已提交
599 600 601 602
		primary: ToggleCaseSensitiveKeybinding.primary,
		mac: ToggleCaseSensitiveKeybinding.mac,
		win: ToggleCaseSensitiveKeybinding.win,
		linux: ToggleCaseSensitiveKeybinding.linux
A
Alex Dima 已提交
603
	}
604
}));
A
Alex Dima 已提交
605

606
CommonEditorRegistry.registerEditorCommand(new FindCommand({
607 608 609 610 611
	id: FIND_IDS.ToggleWholeWordCommand,
	precondition: null,
	handler: x => x.toggleWholeWords(),
	kbOpts: {
		weight: CommonEditorRegistry.commandWeight(5),
612
		kbExpr: EditorContextKeys.focus,
S
Sandeep Somavarapu 已提交
613 614 615 616
		primary: ToggleWholeWordKeybinding.primary,
		mac: ToggleWholeWordKeybinding.mac,
		win: ToggleWholeWordKeybinding.win,
		linux: ToggleWholeWordKeybinding.linux
A
Alex Dima 已提交
617
	}
618
}));
A
Alex Dima 已提交
619

620
CommonEditorRegistry.registerEditorCommand(new FindCommand({
621 622 623 624 625
	id: FIND_IDS.ToggleRegexCommand,
	precondition: null,
	handler: x => x.toggleRegex(),
	kbOpts: {
		weight: CommonEditorRegistry.commandWeight(5),
626
		kbExpr: EditorContextKeys.focus,
S
Sandeep Somavarapu 已提交
627 628 629 630
		primary: ToggleRegexKeybinding.primary,
		mac: ToggleRegexKeybinding.mac,
		win: ToggleRegexKeybinding.win,
		linux: ToggleRegexKeybinding.linux
A
Alex Dima 已提交
631
	}
632
}));
A
Alex Dima 已提交
633

634 635 636 637 638 639 640 641 642 643 644 645 646 647
CommonEditorRegistry.registerEditorCommand(new FindCommand({
	id: FIND_IDS.ToggleSearchScopeCommand,
	precondition: null,
	handler: x => x.toggleSearchScope(),
	kbOpts: {
		weight: CommonEditorRegistry.commandWeight(5),
		kbExpr: EditorContextKeys.focus,
		primary: ToggleSearchScopeKeybinding.primary,
		mac: ToggleSearchScopeKeybinding.mac,
		win: ToggleSearchScopeKeybinding.win,
		linux: ToggleSearchScopeKeybinding.linux
	}
}));

648
CommonEditorRegistry.registerEditorCommand(new FindCommand({
649 650 651 652 653
	id: FIND_IDS.ReplaceOneAction,
	precondition: CONTEXT_FIND_WIDGET_VISIBLE,
	handler: x => x.replace(),
	kbOpts: {
		weight: CommonEditorRegistry.commandWeight(5),
654
		kbExpr: EditorContextKeys.focus,
A
Alex Dima 已提交
655 656
		primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_1
	}
657
}));
A
Alex Dima 已提交
658

659
CommonEditorRegistry.registerEditorCommand(new FindCommand({
660 661 662 663 664
	id: FIND_IDS.ReplaceAllAction,
	precondition: CONTEXT_FIND_WIDGET_VISIBLE,
	handler: x => x.replaceAll(),
	kbOpts: {
		weight: CommonEditorRegistry.commandWeight(5),
665
		kbExpr: EditorContextKeys.focus,
A
Alex Dima 已提交
666 667
		primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.Enter
	}
668
}));
A
Alex Dima 已提交
669

670
CommonEditorRegistry.registerEditorCommand(new FindCommand({
671 672 673 674 675
	id: FIND_IDS.SelectAllMatchesAction,
	precondition: CONTEXT_FIND_WIDGET_VISIBLE,
	handler: x => x.selectAllMatches(),
	kbOpts: {
		weight: CommonEditorRegistry.commandWeight(5),
676
		kbExpr: EditorContextKeys.focus,
A
Alex Dima 已提交
677 678
		primary: KeyMod.Alt | KeyCode.Enter
	}
679
}));