Skip to content

Commit

Permalink
microsoft#50583 Remove the existing history navigation commands
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 committed Jun 8, 2018
1 parent e21ffce commit 44b554d
Show file tree
Hide file tree
Showing 22 changed files with 96 additions and 555 deletions.
73 changes: 2 additions & 71 deletions src/vs/editor/contrib/find/findController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import * as nls from 'vs/nls';
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { Disposable } from 'vs/base/common/lifecycle';
import { ContextKeyExpr, IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
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, CONTEXT_FIND_INPUT_FOCUSED } from 'vs/editor/contrib/find/findModel';
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';
Expand All @@ -25,8 +25,6 @@ import { FindOptionsWidget } from 'vs/editor/contrib/find/findOptionsWidget';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { optional } from 'vs/platform/instantiation/common/instantiation';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { showDeprecatedWarning } from 'vs/platform/widget/browser/input';

export function getSelectionSearchString(editor: ICodeEditor): string {
let selection = editor.getSelection();
Expand Down Expand Up @@ -310,16 +308,6 @@ export class CommonFindController extends Disposable implements editorCommon.IEd
return false;
}

public showPreviousFindTerm(): boolean {
// overwritten in subclass
return false;
}

public showNextFindTerm(): boolean {
// overwritten in subclass
return false;
}

public getGlobalBufferTerm(): string {
if (this._editor.getConfiguration().contribInfo.find.globalFindClipboard
&& this._clipboardService
Expand Down Expand Up @@ -352,7 +340,6 @@ export class FindController extends CommonFindController implements IFindControl
@IKeybindingService private readonly _keybindingService: IKeybindingService,
@IThemeService private readonly _themeService: IThemeService,
@IStorageService storageService: IStorageService,
@INotificationService private readonly _notificationService: INotificationService,
@optional(IClipboardService) clipboardService: IClipboardService
) {
super(editor, _contextKeyService, storageService, clipboardService);
Expand Down Expand Up @@ -387,18 +374,6 @@ export class FindController extends CommonFindController implements IFindControl
this._widget = this._register(new FindWidget(this._editor, this, this._state, this._contextViewService, this._keybindingService, this._contextKeyService, this._themeService));
this._findOptionsWidget = this._register(new FindOptionsWidget(this._editor, this._state, this._keybindingService, this._themeService));
}

public showPreviousFindTerm(): boolean {
showDeprecatedWarning(this._notificationService, this._keybindingService, this._storageService);
this._widget.showPreviousFindTerm();
return true;
}

public showNextFindTerm(): boolean {
showDeprecatedWarning(this._notificationService, this._keybindingService, this._storageService);
this._widget.showNextFindTerm();
return true;
}
}

export class StartFindAction extends EditorAction {
Expand Down Expand Up @@ -632,48 +607,6 @@ export class StartFindReplaceAction extends EditorAction {
}
}

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: KeybindingsRegistry.WEIGHT.editorContrib(5),
kbExpr: ContextKeyExpr.and(CONTEXT_FIND_INPUT_FOCUSED, EditorContextKeys.focus),
primary: null
}
});
}

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

export class ShowPreviousFindTermAction extends MatchFindAction {

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: KeybindingsRegistry.WEIGHT.editorContrib(5),
kbExpr: ContextKeyExpr.and(CONTEXT_FIND_INPUT_FOCUSED, EditorContextKeys.focus),
primary: null
}
});
}

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

registerEditorContribution(FindController);

registerEditorAction(StartFindAction);
Expand All @@ -683,8 +616,6 @@ registerEditorAction(PreviousMatchFindAction);
registerEditorAction(NextSelectionMatchFindAction);
registerEditorAction(PreviousSelectionMatchFindAction);
registerEditorAction(StartFindReplaceAction);
registerEditorAction(ShowNextFindTermAction);
registerEditorAction(ShowPreviousFindTermAction);

const FindCommand = EditorCommand.bindToContribution<CommonFindController>(CommonFindController.get);

Expand Down
6 changes: 1 addition & 5 deletions src/vs/editor/contrib/find/findModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,7 @@ export const FIND_IDS = {
ToggleSearchScopeCommand: 'toggleFindInSelection',
ReplaceOneAction: 'editor.action.replaceOne',
ReplaceAllAction: 'editor.action.replaceAll',
SelectAllMatchesAction: 'editor.action.selectAllMatches',
ShowPreviousFindTermAction: 'find.history.showPrevious',
ShowNextFindTermAction: 'find.history.showNext',
ShowPreviousReplaceTermAction: 'replace.history.showPrevious',
ShowNextReplaceTermAction: 'replace.history.showNext'
SelectAllMatchesAction: 'editor.action.selectAllMatches'
};

export const MATCHES_LIMIT = 19999;
Expand Down
8 changes: 0 additions & 8 deletions src/vs/editor/contrib/find/findWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,6 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
return null;
}

public showNextFindTerm() {
this._findInput.inputBox.showNextValue();
}

public showPreviousFindTerm() {
this._findInput.inputBox.showPreviousValue();
}

// ----- React to state changes

private _onStateChanged(e: FindReplaceStateChangedEvent): void {
Expand Down
20 changes: 2 additions & 18 deletions src/vs/editor/contrib/find/simpleFindWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ import { IContextViewService } from 'vs/platform/contextview/browser/contextView
import { registerThemingParticipant, ITheme } from 'vs/platform/theme/common/themeService';
import { inputBackground, inputActiveOptionBorder, inputForeground, inputBorder, inputValidationInfoBackground, inputValidationInfoBorder, inputValidationWarningBackground, inputValidationWarningBorder, inputValidationErrorBackground, inputValidationErrorBorder, editorWidgetBackground, widgetShadow } from 'vs/platform/theme/common/colorRegistry';
import { SimpleButton } from './findWidget';
import { ContextScopedFindInput, showDeprecatedWarning } from 'vs/platform/widget/browser/input';
import { ContextScopedFindInput } from 'vs/platform/widget/browser/input';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { IStorageService } from 'vs/platform/storage/common/storage';

const NLS_FIND_INPUT_LABEL = nls.localize('label.find', "Find");
const NLS_FIND_INPUT_PLACEHOLDER = nls.localize('placeholder.find', "Find");
Expand All @@ -37,10 +34,7 @@ export abstract class SimpleFindWidget extends Widget {

constructor(
@IContextViewService private readonly _contextViewService: IContextViewService,
@IContextKeyService contextKeyService: IContextKeyService,
@IKeybindingService private readonly _keybindingService: IKeybindingService,
@INotificationService private readonly _notificationService: INotificationService,
@IStorageService private readonly _storageService: IStorageService
@IContextKeyService contextKeyService: IContextKeyService
) {
super();

Expand Down Expand Up @@ -206,16 +200,6 @@ export abstract class SimpleFindWidget extends Widget {
this._findInput.inputBox.addToHistory(this._findInput.getValue());
}
}

public showNextFindTerm() {
showDeprecatedWarning(this._notificationService, this._keybindingService, this._storageService);
this._findInput.inputBox.showNextValue();
}

public showPreviousFindTerm() {
showDeprecatedWarning(this._notificationService, this._keybindingService, this._storageService);
this._findInput.inputBox.showPreviousValue();
}
}

// theming
Expand Down
40 changes: 0 additions & 40 deletions src/vs/platform/widget/browser/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ import { HistoryInputBox, IHistoryInputOptions } from 'vs/base/browser/ui/inputb
import { FindInput, IFindInputOptions } from 'vs/base/browser/ui/findinput/findInput';
import { IContextViewProvider } from 'vs/base/browser/ui/contextview/contextview';
import { createWidgetScopedContextKeyService, IWidget } from 'vs/platform/widget/browser/widget';
import { INotificationService, Severity } from 'vs/platform/notification/common/notification';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { ResolvedKeybindingItem } from 'vs/platform/keybinding/common/resolvedKeybindingItem';
import { localize } from 'vs/nls';

export const HistoryInputBoxContext = 'historyInputBox';

Expand All @@ -36,39 +31,4 @@ export class ContextScopedFindInput extends FindInput {
this._register(createWidgetScopedContextKeyService(contextKeyService, this.inputBox, HistoryInputBoxContext));
}

}

export function showDeprecatedWarning(notificationService: INotificationService, keybindingService: IKeybindingService, storageService: IStorageService): void {
const previousCommand = 'input.action.historyPrevious';
const nextCommand = 'input.action.historyNext';
let previousKeybinding: ResolvedKeybindingItem, nextKeybinding: ResolvedKeybindingItem;
for (const keybinding of keybindingService.getKeybindings()) {
if (keybinding.command === previousCommand) {
if (!keybinding.isDefault) {
return;
}
previousKeybinding = keybinding;
}
if (keybinding.command === nextCommand) {
if (!keybinding.isDefault) {
return;
}
nextKeybinding = keybinding;
}
}
const key = 'donotshow.historyNavigation.warning';
if (!storageService.getBoolean(key, StorageScope.GLOBAL, false)) {
const message = localize('showDeprecatedWarningMessage', "History navigation commands you are using are deprecated. Instead use following new commands: {0} and {1}", `${previousCommand} (${previousKeybinding.resolvedKeybinding.getLabel()})`, `${nextCommand} (${nextKeybinding.resolvedKeybinding.getLabel()})`);
notificationService.prompt(Severity.Warning, message, [
{
label: localize('more information', "More Information..."),
run: () => null
},
{
label: localize('Do not show again', "Don't show again"),
isSecondary: true,
run: () => storageService.store(key, true, StorageScope.GLOBAL)
}
]);
}
}
5 changes: 5 additions & 0 deletions src/vs/workbench/electron-browser/main.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import { inQuickOpenContext, getQuickNavigateHandler } from 'vs/workbench/browse
import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
import { HistoryNavigationKeybindingsChangedContribution } from 'vs/workbench/electron-browser/removedKeybindingsContribution';

// Contribute Commands
registerCommands();
Expand Down Expand Up @@ -501,3 +504,5 @@ configurationRegistry.registerConfiguration({
}
}
});

Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(HistoryNavigationKeybindingsChangedContribution, LifecyclePhase.Eventually);
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*---------------------------------------------------------------------------------------------
* 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 { IWorkbenchContribution } from 'vs/workbench/common/contributions';
import { INotificationService, Severity } from 'vs/platform/notification/common/notification';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { localize } from 'vs/nls';
import { IPreferencesService } from 'vs/workbench/services/preferences/common/preferences';

export class HistoryNavigationKeybindingsChangedContribution implements IWorkbenchContribution {

private previousCommands: string[] = [

'search.history.showNextIncludePattern',
'search.history.showPreviousIncludePattern',
'search.history.showNextExcludePattern',
'search.history.showPreviousExcludePattern',
'search.history.showNext',
'search.history.showPrevious',
'search.replaceHistory.showNext',
'search.replaceHistory.showPrevious',

'find.history.showPrevious',
'find.history.showNext',

'workbench.action.terminal.findWidget.history.showNext',
'workbench.action.terminal.findWidget.history.showPrevious',

'editor.action.extensioneditor.showNextFindTerm',
'editor.action.extensioneditor.showPreviousFindTerm',

'editor.action.webvieweditor.showNextFindTerm',
'editor.action.webvieweditor.showPreviousFindTerm'

];

constructor(
@INotificationService private readonly notificationService: INotificationService,
@IKeybindingService private readonly keybindingService: IKeybindingService,
@IPreferencesService private readonly preferencesService: IPreferencesService,
@IStorageService private readonly storageService: IStorageService
) {
this.showRemovedWarning();
}

private showRemovedWarning(): void {
const key = 'donotshow.historyNavigation.warning';
if (!this.storageService.getBoolean(key, StorageScope.GLOBAL, false)) {
const keybindingsToRemove = this.keybindingService.getKeybindings().filter(keybinding => !keybinding.isDefault && this.previousCommands.indexOf(keybinding.command) !== -1);
if (keybindingsToRemove.length) {
const message = localize('showDeprecatedWarningMessage', "History navigation commands have changed. Please update your keybindings to use following new commands: 'input.action.historyPrevious' and 'input.action.historyNext'");
this.notificationService.prompt(Severity.Warning, message, [
{
label: localize('Open Keybindings', "Open Keybindings File"),
run: () => this.preferencesService.openGlobalKeybindingSettings(true)
},
{
label: localize('more information', "More Information..."),
run: () => null
},
{
label: localize('Do not show again', "Don't show again"),
isSecondary: true,
run: () => this.storageService.store(key, true, StorageScope.GLOBAL)
}
]);
}
}
}
}
Loading

0 comments on commit 44b554d

Please sign in to comment.