Merge from master

This commit is contained in:
Raj Musuku
2019-02-21 17:56:04 -08:00
parent 5a146e34fa
commit 666ae11639
11482 changed files with 119352 additions and 255574 deletions

View File

@@ -2,30 +2,31 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as nls from 'vs/nls';
import { Delayer } from 'vs/base/common/async';
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { Disposable } from 'vs/base/common/lifecycle';
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import * as strings from 'vs/base/common/strings';
import * as editorCommon from 'vs/editor/common/editorCommon';
import { registerEditorContribution, registerEditorAction, ServicesAccessor, EditorAction, EditorCommand, registerEditorCommand } from 'vs/editor/browser/editorExtensions';
import { FIND_IDS, FindModelBoundToEditorModel, ToggleCaseSensitiveKeybinding, ToggleRegexKeybinding, ToggleWholeWordKeybinding, ToggleSearchScopeKeybinding, CONTEXT_FIND_WIDGET_VISIBLE } from 'vs/editor/contrib/find/findModel';
import { FindReplaceState, FindReplaceStateChangedEvent, INewFindReplaceState } from 'vs/editor/contrib/find/findState';
import { Delayer } from 'vs/base/common/async';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { FindWidget, IFindController } from 'vs/editor/contrib/find/findWidget';
import { EditorAction, EditorCommand, ServicesAccessor, registerEditorAction, registerEditorCommand, registerEditorContribution } from 'vs/editor/browser/editorExtensions';
import * as editorCommon from 'vs/editor/common/editorCommon';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { CONTEXT_FIND_INPUT_FOCUSED, CONTEXT_FIND_WIDGET_VISIBLE, FIND_IDS, FindModelBoundToEditorModel, ToggleCaseSensitiveKeybinding, ToggleRegexKeybinding, ToggleSearchScopeKeybinding, ToggleWholeWordKeybinding } from 'vs/editor/contrib/find/findModel';
import { FindOptionsWidget } from 'vs/editor/contrib/find/findOptionsWidget';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { optional } from 'vs/platform/instantiation/common/instantiation';
import { FindReplaceState, FindReplaceStateChangedEvent, INewFindReplaceState } from 'vs/editor/contrib/find/findState';
import { FindWidget, IFindController } from 'vs/editor/contrib/find/findWidget';
import { MenuId } from 'vs/platform/actions/common/actions';
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
import { optional } from 'vs/platform/instantiation/common/instantiation';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { IThemeService } from 'vs/platform/theme/common/themeService';
const SEARCH_STRING_MAX_LENGTH = 524288;
export function getSelectionSearchString(editor: ICodeEditor): string {
let selection = editor.getSelection();
@@ -38,7 +39,9 @@ export function getSelectionSearchString(editor: ICodeEditor): string {
return wordAtPosition.word;
}
} else {
return editor.getModel().getValueInRange(selection);
if (editor.getModel().getValueLengthInRange(selection) < SEARCH_STRING_MAX_LENGTH) {
return editor.getModel().getValueInRange(selection);
}
}
}
@@ -57,6 +60,7 @@ export interface IFindStartOptions {
seedSearchStringFromGlobalClipboard: boolean;
shouldFocus: FindStartFocusAction;
shouldAnimate: boolean;
updateSearchScope: boolean;
}
export class CommonFindController extends Disposable implements editorCommon.IEditorContribution {
@@ -68,8 +72,9 @@ export class CommonFindController extends Disposable implements editorCommon.IEd
protected _state: FindReplaceState;
protected _updateHistoryDelayer: Delayer<void>;
private _model: FindModelBoundToEditorModel;
protected _storageService: IStorageService;
private _storageService: IStorageService;
private _clipboardService: IClipboardService;
protected readonly _contextKeyService: IContextKeyService;
public static get(editor: ICodeEditor): CommonFindController {
return editor.getContribution<CommonFindController>(CommonFindController.ID);
@@ -84,6 +89,7 @@ export class CommonFindController extends Disposable implements editorCommon.IEd
super();
this._editor = editor;
this._findWidgetVisible = CONTEXT_FIND_WIDGET_VISIBLE.bindTo(contextKeyService);
this._contextKeyService = contextKeyService;
this._storageService = storageService;
this._clipboardService = clipboardService;
@@ -113,6 +119,7 @@ export class CommonFindController extends Disposable implements editorCommon.IEd
seedSearchStringFromGlobalClipboard: false,
shouldFocus: FindStartFocusAction.NoFocusChange,
shouldAnimate: false,
updateSearchScope: false
});
}
}));
@@ -170,6 +177,10 @@ export class CommonFindController extends Disposable implements editorCommon.IEd
}, false);
}
public isFindInputFocused(): boolean {
return CONTEXT_FIND_INPUT_FOCUSED.getValue(this._contextKeyService);
}
public getState(): FindReplaceState {
return this._state;
}
@@ -184,14 +195,23 @@ export class CommonFindController extends Disposable implements editorCommon.IEd
public toggleCaseSensitive(): void {
this._state.change({ matchCase: !this._state.matchCase }, false);
if (!this._state.isRevealed) {
this.highlightFindOptions();
}
}
public toggleWholeWords(): void {
this._state.change({ wholeWord: !this._state.wholeWord }, false);
if (!this._state.isRevealed) {
this.highlightFindOptions();
}
}
public toggleRegex(): void {
this._state.change({ isRegex: !this._state.isRegex }, false);
if (!this._state.isRevealed) {
this.highlightFindOptions();
}
}
public toggleSearchScope(): void {
@@ -200,7 +220,7 @@ export class CommonFindController extends Disposable implements editorCommon.IEd
} else {
let selection = this._editor.getSelection();
if (selection.endColumn === 1 && selection.endLineNumber > selection.startLineNumber) {
selection = selection.setEndPosition(selection.endLineNumber - 1, 1);
selection = selection.setEndPosition(selection.endLineNumber - 1, this._editor.getModel().getLineMaxColumn(selection.endLineNumber - 1));
}
if (!selection.isEmpty()) {
this._state.change({ searchScope: selection }, true);
@@ -256,6 +276,12 @@ export class CommonFindController extends Disposable implements editorCommon.IEd
stateChanges.isReplaceRevealed = false;
}
if (opts.updateSearchScope) {
let currentSelection = this._editor.getSelection();
if (!currentSelection.isEmpty()) {
stateChanges.searchScope = currentSelection;
}
}
this._state.change(stateChanges, false);
@@ -337,7 +363,7 @@ export class FindController extends CommonFindController implements IFindControl
constructor(
editor: ICodeEditor,
@IContextViewService private readonly _contextViewService: IContextViewService,
@IContextKeyService private readonly _contextKeyService: IContextKeyService,
@IContextKeyService _contextKeyService: IContextKeyService,
@IKeybindingService private readonly _keybindingService: IKeybindingService,
@IThemeService private readonly _themeService: IThemeService,
@IStorageService storageService: IStorageService,
@@ -351,6 +377,11 @@ export class FindController extends CommonFindController implements IFindControl
this._createFindWidget();
}
if (!this._widget.getPosition() && this._editor.getConfiguration().contribInfo.find.autoFindInSelection) {
// not visible yet so we need to set search scope if `editor.find.autoFindInSelection` is `true`
opts.updateSearchScope = true;
}
super._start(opts);
if (opts.shouldFocus === FindStartFocusAction.FocusReplaceInput) {
@@ -407,7 +438,8 @@ export class StartFindAction extends EditorAction {
seedSearchStringFromSelection: editor.getConfiguration().contribInfo.find.seedSearchStringFromSelection,
seedSearchStringFromGlobalClipboard: editor.getConfiguration().contribInfo.find.globalFindClipboard,
shouldFocus: FindStartFocusAction.FocusFindInput,
shouldAnimate: true
shouldAnimate: true,
updateSearchScope: false
});
}
}
@@ -423,7 +455,7 @@ export class StartFindWithSelectionAction extends EditorAction {
precondition: null,
kbOpts: {
kbExpr: null,
primary: null,
primary: 0,
mac: {
primary: KeyMod.CtrlCmd | KeyCode.KEY_E,
},
@@ -440,7 +472,8 @@ export class StartFindWithSelectionAction extends EditorAction {
seedSearchStringFromSelection: true,
seedSearchStringFromGlobalClipboard: false,
shouldFocus: FindStartFocusAction.FocusFindInput,
shouldAnimate: true
shouldAnimate: true,
updateSearchScope: false
});
controller.setGlobalBufferTerm(controller.getState().searchString);
@@ -456,7 +489,8 @@ export abstract class MatchFindAction extends EditorAction {
seedSearchStringFromSelection: (controller.getState().searchString.length === 0) && editor.getConfiguration().contribInfo.find.seedSearchStringFromSelection,
seedSearchStringFromGlobalClipboard: true,
shouldFocus: FindStartFocusAction.NoFocusChange,
shouldAnimate: true
shouldAnimate: true,
updateSearchScope: false
});
this._run(controller);
}
@@ -525,7 +559,8 @@ export abstract class SelectionMatchFindAction extends EditorAction {
seedSearchStringFromSelection: editor.getConfiguration().contribInfo.find.seedSearchStringFromSelection,
seedSearchStringFromGlobalClipboard: false,
shouldFocus: FindStartFocusAction.NoFocusChange,
shouldAnimate: true
shouldAnimate: true,
updateSearchScope: false
});
this._run(controller);
}
@@ -606,22 +641,31 @@ export class StartFindReplaceAction extends EditorAction {
let controller = CommonFindController.get(editor);
let currentSelection = editor.getSelection();
// we only seed search string from selection when the current selection is single line and not empty.
let seedSearchStringFromSelection = !currentSelection.isEmpty() &&
currentSelection.startLineNumber === currentSelection.endLineNumber && editor.getConfiguration().contribInfo.find.seedSearchStringFromSelection;
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.
let shouldFocus = (!!oldSearchString || seedSearchStringFromSelection) ?
let findInputFocused = controller.isFindInputFocused();
// we only seed search string from selection when the current selection is single line and not empty,
// + the find input is not focused
let seedSearchStringFromSelection = !currentSelection.isEmpty()
&& currentSelection.startLineNumber === currentSelection.endLineNumber && editor.getConfiguration().contribInfo.find.seedSearchStringFromSelection
&& !findInputFocused;
/*
* 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.
* findInputFocused true -> seedSearchStringFromSelection false, FocusReplaceInput
* findInputFocused false, seedSearchStringFromSelection true FocusReplaceInput
* findInputFocused false seedSearchStringFromSelection false FocusFindInput
*/
let shouldFocus = (findInputFocused || seedSearchStringFromSelection) ?
FindStartFocusAction.FocusReplaceInput : FindStartFocusAction.FocusFindInput;
if (controller) {
controller.start({
forceRevealReplace: true,
seedSearchStringFromSelection: seedSearchStringFromSelection,
seedSearchStringFromGlobalClipboard: editor.getConfiguration().contribInfo.find.seedSearchStringFromSelection,
shouldFocus: shouldFocus,
shouldAnimate: true
shouldAnimate: true,
updateSearchScope: false
});
}
}