Skip to content

Commit eb45d35

Browse files
committed
- Implement Context scoped history input widget - Adopt to context scoped history input widget
1 parent 83713d3 commit eb45d35

File tree

12 files changed

+125
-36
lines changed

12 files changed

+125
-36
lines changed

src/vs/editor/contrib/find/findWidget.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { ITheme, registerThemingParticipant, IThemeService } from 'vs/platform/t
3030
import { Color } from 'vs/base/common/color';
3131
import { IConfigurationChangedEvent } from 'vs/editor/common/config/editorOptions';
3232
import { editorFindRangeHighlight, editorFindMatch, editorFindMatchHighlight, contrastBorder, inputBackground, editorWidgetBackground, inputActiveOptionBorder, widgetShadow, inputForeground, inputBorder, inputValidationInfoBackground, inputValidationInfoBorder, inputValidationWarningBackground, inputValidationWarningBorder, inputValidationErrorBackground, inputValidationErrorBorder, errorForeground, editorWidgetBorder, editorFindMatchBorder, editorFindMatchHighlightBorder, editorFindRangeHighlightBorder, editorWidgetResizeBorder } from 'vs/platform/theme/common/colorRegistry';
33+
import { ContextScopedFindInput, ContextScopedHistoryInputBox } from 'vs/platform/widget/browser/input';
3334

3435

3536
export interface IFindController {
@@ -88,6 +89,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
8889
private _controller: IFindController;
8990
private readonly _contextViewProvider: IContextViewProvider;
9091
private readonly _keybindingService: IKeybindingService;
92+
private readonly _contextKeyService: IContextKeyService;
9193

9294
private _domNode: HTMLElement;
9395
private _findInput: FindInput;
@@ -131,6 +133,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
131133
this._state = state;
132134
this._contextViewProvider = contextViewProvider;
133135
this._keybindingService = keybindingService;
136+
this._contextKeyService = contextKeyService;
134137

135138
this._isVisible = false;
136139
this._isReplaceVisible = false;
@@ -710,7 +713,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
710713

711714
private _buildFindPart(): HTMLElement {
712715
// Find input
713-
this._findInput = this._register(new FindInput(null, this._contextViewProvider, {
716+
this._findInput = this._register(new ContextScopedFindInput(null, this._contextViewProvider, {
714717
width: FIND_INPUT_AREA_WIDTH,
715718
label: NLS_FIND_INPUT_LABEL,
716719
placeholder: NLS_FIND_INPUT_PLACEHOLDER,
@@ -733,7 +736,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
733736
return { content: e.message };
734737
}
735738
}
736-
}));
739+
}, this._contextKeyService));
737740
this._findInput.setRegex(!!this._state.isRegex);
738741
this._findInput.setCaseSensitive(!!this._state.matchCase);
739742
this._findInput.setWholeWords(!!this._state.wholeWord);
@@ -839,11 +842,11 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
839842
let replaceInput = document.createElement('div');
840843
replaceInput.className = 'replace-input';
841844
replaceInput.style.width = REPLACE_INPUT_AREA_WIDTH + 'px';
842-
this._replaceInputBox = this._register(new HistoryInputBox(replaceInput, null, {
845+
this._replaceInputBox = this._register(new ContextScopedHistoryInputBox(replaceInput, null, {
843846
ariaLabel: NLS_REPLACE_INPUT_LABEL,
844847
placeholder: NLS_REPLACE_INPUT_PLACEHOLDER,
845848
history: []
846-
}));
849+
}, this._contextKeyService));
847850

848851
this._register(dom.addStandardDisposableListener(this._replaceInputBox.inputElement, 'keydown', (e) => this._onReplaceInputKeyDown(e)));
849852
this._register(dom.addStandardDisposableListener(this._replaceInputBox.inputElement, 'input', (e) => {

src/vs/editor/contrib/find/simpleFindWidget.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { IContextViewService } from 'vs/platform/contextview/browser/contextView
1414
import { registerThemingParticipant, ITheme } from 'vs/platform/theme/common/themeService';
1515
import { inputBackground, inputActiveOptionBorder, inputForeground, inputBorder, inputValidationInfoBackground, inputValidationInfoBorder, inputValidationWarningBackground, inputValidationWarningBorder, inputValidationErrorBackground, inputValidationErrorBorder, editorWidgetBackground, widgetShadow } from 'vs/platform/theme/common/colorRegistry';
1616
import { SimpleButton } from './findWidget';
17+
import { ContextScopedFindInput } from 'vs/platform/widget/browser/input';
18+
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
1719

1820
const NLS_FIND_INPUT_LABEL = nls.localize('label.find', "Find");
1921
const NLS_FIND_INPUT_PLACEHOLDER = nls.localize('placeholder.find', "Find");
@@ -31,14 +33,15 @@ export abstract class SimpleFindWidget extends Widget {
3133
private _updateHistoryDelayer: Delayer<void>;
3234

3335
constructor(
34-
@IContextViewService private readonly _contextViewService: IContextViewService
36+
@IContextViewService private readonly _contextViewService: IContextViewService,
37+
@IContextKeyService contextKeyService: IContextKeyService,
3538
) {
3639
super();
3740

38-
this._findInput = this._register(new FindInput(null, this._contextViewService, {
41+
this._findInput = this._register(new ContextScopedFindInput(null, this._contextViewService, {
3942
label: NLS_FIND_INPUT_LABEL,
4043
placeholder: NLS_FIND_INPUT_PLACEHOLDER,
41-
}));
44+
}, contextKeyService));
4245

4346
// Find History with update delayer
4447
this._updateHistoryDelayer = new Delayer<void>(500);
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
'use strict';
6+
7+
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
8+
import { HistoryInputBox, IHistoryInputOptions } from 'vs/base/browser/ui/inputbox/inputBox';
9+
import { FindInput, IFindInputOptions } from 'vs/base/browser/ui/findinput/findInput';
10+
import { IContextViewProvider } from 'vs/base/browser/ui/contextview/contextview';
11+
import { createWidgetScopedContextKeyService, IWidget } from 'vs/platform/widget/browser/widget';
12+
13+
export const HistoryInputBoxContext = 'historyInputBox';
14+
15+
export class ContextScopedHistoryInputBox extends HistoryInputBox implements IWidget {
16+
17+
constructor(container: HTMLElement, contextViewProvider: IContextViewProvider, options: IHistoryInputOptions,
18+
@IContextKeyService contextKeyService: IContextKeyService
19+
) {
20+
super(container, contextViewProvider, options);
21+
this._register(createWidgetScopedContextKeyService(contextKeyService, this, HistoryInputBoxContext));
22+
}
23+
}
24+
25+
export class ContextScopedFindInput extends FindInput {
26+
27+
constructor(container: HTMLElement, contextViewProvider: IContextViewProvider, options: IFindInputOptions,
28+
@IContextKeyService contextKeyService: IContextKeyService
29+
) {
30+
super(container, contextViewProvider, options);
31+
this._register(createWidgetScopedContextKeyService(contextKeyService, this.inputBox, HistoryInputBoxContext));
32+
}
33+
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
'use strict';
6+
7+
import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
8+
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
9+
import { ContextKeyDefinedExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
10+
import { HistoryInputBoxContext } from 'vs/platform/widget/browser/input';
11+
import { HistoryInputBox } from 'vs/base/browser/ui/inputbox/inputbox';
12+
13+
KeybindingsRegistry.registerCommandAndKeybindingRule({
14+
id: 'input.action.historyPrevious',
15+
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
16+
when: new ContextKeyDefinedExpr(HistoryInputBoxContext),
17+
primary: KeyMod.Alt | KeyCode.UpArrow,
18+
handler: (accessor, arg2) => {
19+
const historyInputBox: HistoryInputBox = accessor.get(IContextKeyService).getContext(document.activeElement).getValue(HistoryInputBoxContext);
20+
historyInputBox.showPreviousValue();
21+
}
22+
});
23+
24+
KeybindingsRegistry.registerCommandAndKeybindingRule({
25+
id: 'input.action.historyNext',
26+
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
27+
when: new ContextKeyDefinedExpr(HistoryInputBoxContext),
28+
primary: KeyMod.Alt | KeyCode.DownArrow,
29+
handler: (accessor, arg2) => {
30+
const historyInputBox: HistoryInputBox = accessor.get(IContextKeyService).getContext(document.activeElement).getValue(HistoryInputBoxContext);
31+
historyInputBox.showNextValue();
32+
}
33+
});
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
'use strict';
6+
7+
import { IContextKeyService, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
8+
9+
export function createWidgetScopedContextKeyService(contextKeyService: IContextKeyService, widget: IWidget, contextKey: string): IContextKeyService {
10+
const result = contextKeyService.createScoped(widget.element);
11+
const widgetContext = new RawContextKey<IWidget>(contextKey, widget);
12+
widgetContext.bindTo(result);
13+
return result;
14+
}
15+
16+
export interface IWidget {
17+
18+
readonly element: HTMLElement;
19+
20+
}

src/vs/workbench/parts/markers/electron-browser/markersPanelActions.ts

+2-17
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { badgeBackground, contrastBorder } from 'vs/platform/theme/common/colorR
2929
import { localize } from 'vs/nls';
3030
import { Checkbox } from 'vs/base/browser/ui/checkbox/checkbox';
3131
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
32+
import { ContextScopedHistoryInputBox } from 'vs/platform/widget/browser/input';
3233

3334
export class ToggleMarkersPanelAction extends TogglePanelAction {
3435

@@ -151,7 +152,7 @@ export class MarkersFilterActionItem extends BaseActionItem {
151152
}
152153

153154
private createInput(container: HTMLElement): void {
154-
this.filterInputBox = this._register(this.instantiationService.createInstance(HistoryInputBox, container, this.contextViewService, {
155+
this.filterInputBox = this._register(this.instantiationService.createInstance(ContextScopedHistoryInputBox, container, this.contextViewService, {
155156
placeholder: Messages.MARKERS_PANEL_FILTER_PLACEHOLDER,
156157
ariaLabel: Messages.MARKERS_PANEL_FILTER_ARIA_LABEL,
157158
history: this.itemOptions.filterHistory
@@ -232,29 +233,13 @@ export class MarkersFilterActionItem extends BaseActionItem {
232233
}
233234
}
234235

235-
private showNextFilter() {
236-
this.filterInputBox.showNextValue();
237-
}
238-
239-
private showPreviousFilter() {
240-
this.filterInputBox.showPreviousValue();
241-
}
242-
243236
private onInputKeyDown(keyboardEvent: IKeyboardEvent, filterInputBox: HistoryInputBox) {
244237
let handled = false;
245238
switch (keyboardEvent.keyCode) {
246239
case KeyCode.Escape:
247240
filterInputBox.value = '';
248241
handled = true;
249242
break;
250-
case KeyCode.UpArrow:
251-
this.showPreviousFilter();
252-
handled = true;
253-
break;
254-
case KeyCode.DownArrow:
255-
this.showNextFilter();
256-
handled = true;
257-
break;
258243
}
259244
if (handled) {
260245
keyboardEvent.stopPropagation();

src/vs/workbench/parts/search/browser/patternInputWidget.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { KeyCode } from 'vs/base/common/keyCodes';
1414
import { Event as CommonEvent, Emitter } from 'vs/base/common/event';
1515
import { IThemeService } from 'vs/platform/theme/common/themeService';
1616
import { attachInputBoxStyler, attachCheckboxStyler } from 'vs/platform/theme/common/styler';
17+
import { ContextScopedHistoryInputBox } from 'vs/platform/widget/browser/input';
18+
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
1719

1820
export interface IOptions {
1921
placeholder?: string;
@@ -44,7 +46,8 @@ export class PatternInputWidget extends Widget {
4446
public onCancel: CommonEvent<boolean> = this._onCancel.event;
4547

4648
constructor(parent: HTMLElement, private contextViewProvider: IContextViewProvider, options: IOptions = Object.create(null),
47-
@IThemeService protected themeService: IThemeService
49+
@IThemeService protected themeService: IThemeService,
50+
@IContextKeyService private contextKeyService: IContextKeyService
4851
) {
4952
super();
5053
this.onOptionChange = null;
@@ -146,14 +149,14 @@ export class PatternInputWidget extends Widget {
146149
this.domNode.style.width = this.width + 'px';
147150
dom.addClass(this.domNode, 'monaco-findInput');
148151

149-
this.inputBox = new HistoryInputBox(this.domNode, this.contextViewProvider, {
152+
this.inputBox = new ContextScopedHistoryInputBox(this.domNode, this.contextViewProvider, {
150153
placeholder: this.placeholder || '',
151154
ariaLabel: this.ariaLabel || '',
152155
validationOptions: {
153156
validation: null
154157
},
155158
history: options.history || []
156-
});
159+
}, this.contextKeyService);
157160
this._register(attachInputBoxStyler(this.inputBox, this.themeService));
158161
this.inputFocusTracker = dom.trackFocus(this.inputBox.inputElement);
159162
this.onkeyup(this.inputBox.inputElement, (keyboardEvent) => this.onInputKeyUp(keyboardEvent));
@@ -186,9 +189,10 @@ export class PatternInputWidget extends Widget {
186189
export class ExcludePatternInputWidget extends PatternInputWidget {
187190

188191
constructor(parent: HTMLElement, contextViewProvider: IContextViewProvider, options: IOptions = Object.create(null),
189-
@IThemeService themeService: IThemeService
192+
@IThemeService themeService: IThemeService,
193+
@IContextKeyService contextKeyService: IContextKeyService
190194
) {
191-
super(parent, contextViewProvider, options, themeService);
195+
super(parent, contextViewProvider, options, themeService, contextKeyService);
192196
}
193197

194198
private useExcludesAndIgnoreFilesBox: Checkbox;

src/vs/workbench/parts/search/browser/searchWidget.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService
3131
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
3232
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
3333
import { ISearchConfigurationProperties } from 'vs/platform/search/common/search';
34+
import { ContextScopedFindInput, ContextScopedHistoryInputBox } from 'vs/platform/widget/browser/input';
3435

3536
export interface ISearchWidgetOptions {
3637
value?: string;
@@ -243,7 +244,7 @@ export class SearchWidget extends Widget {
243244
};
244245

245246
let searchInputContainer = dom.append(parent, dom.$('.search-container.input-box'));
246-
this.searchInput = this._register(new FindInput(searchInputContainer, this.contextViewService, inputOptions));
247+
this.searchInput = this._register(new ContextScopedFindInput(searchInputContainer, this.contextViewService, inputOptions, this.keyBindingService));
247248
this._register(attachFindInputBoxStyler(this.searchInput, this.themeService));
248249
this.searchInput.onKeyUp((keyboardEvent: IKeyboardEvent) => this.onSearchInputKeyUp(keyboardEvent));
249250
this.searchInput.setValue(options.value || '');
@@ -282,11 +283,11 @@ export class SearchWidget extends Widget {
282283
private renderReplaceInput(parent: HTMLElement, options: ISearchWidgetOptions): void {
283284
this.replaceContainer = dom.append(parent, dom.$('.replace-container.disabled'));
284285
let replaceBox = dom.append(this.replaceContainer, dom.$('.input-box'));
285-
this.replaceInput = this._register(new HistoryInputBox(replaceBox, this.contextViewService, {
286+
this.replaceInput = this._register(new ContextScopedHistoryInputBox(replaceBox, this.contextViewService, {
286287
ariaLabel: nls.localize('label.Replace', 'Replace: Type replace term and press Enter to preview or Escape to cancel'),
287288
placeholder: nls.localize('search.replace.placeHolder', "Replace"),
288289
history: options.replaceHistory || []
289-
}));
290+
}, this.keyBindingService));
290291
this._register(attachInputBoxStyler(this.replaceInput, this.themeService));
291292
this.onkeyup(this.replaceInput.inputElement, (keyboardEvent) => this.onReplaceInputKeyUp(keyboardEvent));
292293
this.replaceInput.onDidChange(() => this._onReplaceValueChanged.fire());

src/vs/workbench/parts/terminal/browser/terminalFindWidget.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class TerminalFindWidget extends SimpleFindWidget {
1616
@IContextKeyService private readonly _contextKeyService: IContextKeyService,
1717
@ITerminalService private readonly _terminalService: ITerminalService
1818
) {
19-
super(_contextViewService);
19+
super(_contextViewService, _contextKeyService);
2020
this._findInputFocused = KEYBINDING_CONTEXT_TERMINAL_FIND_WIDGET_INPUT_FOCUSED.bindTo(this._contextKeyService);
2121
}
2222

src/vs/workbench/parts/webview/electron-browser/webviewElement.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { getMediaMime, guessMimeTypes } from 'vs/base/common/mime';
1010
import { nativeSep, extname } from 'vs/base/common/paths';
1111
import { startsWith } from 'vs/base/common/strings';
1212
import URI from 'vs/base/common/uri';
13-
import { IContextKey } from 'vs/platform/contextkey/common/contextkey';
13+
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
1414
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
1515
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
1616
import { IFileService } from 'vs/platform/files/common/files';
@@ -45,6 +45,7 @@ export class WebviewElement {
4545
@IThemeService private readonly _themeService: IThemeService,
4646
@IEnvironmentService private readonly _environmentService: IEnvironmentService,
4747
@IContextViewService private readonly _contextViewService: IContextViewService,
48+
@IContextKeyService private readonly _contextKeyService: IContextKeyService,
4849
@IFileService private readonly _fileService: IFileService,
4950
) {
5051
this._webview = document.createElement('webview');
@@ -188,7 +189,7 @@ export class WebviewElement {
188189
}),
189190
);
190191

191-
this._webviewFindWidget = new WebviewFindWidget(this._contextViewService, this);
192+
this._webviewFindWidget = new WebviewFindWidget(this._contextViewService, this._contextKeyService, this);
192193
this._disposables.push(this._webviewFindWidget);
193194

194195
this.style(this._themeService.getTheme());

src/vs/workbench/parts/webview/electron-browser/webviewFindWidget.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66
import { SimpleFindWidget } from 'vs/editor/contrib/find/simpleFindWidget';
77
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
88
import { WebviewElement } from './webviewElement';
9+
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
910

1011
export class WebviewFindWidget extends SimpleFindWidget {
1112

1213
constructor(
1314
@IContextViewService contextViewService: IContextViewService,
15+
@IContextKeyService contextKeyService: IContextKeyService,
1416
private readonly webview: WebviewElement
1517
) {
16-
super(contextViewService);
18+
super(contextViewService, contextKeyService);
1719
}
1820

1921
public find(previous: boolean) {

src/vs/workbench/workbench.main.ts

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import 'vs/workbench/services/configuration/common/configurationExtensionPoint';
1515
// Editor
1616
import 'vs/editor/editor.all';
1717

18+
// Platform
19+
import 'vs/platform/widget/browser/widget.contribution';
20+
1821
// Menus/Actions
1922
import 'vs/workbench/services/actions/electron-browser/menusExtensionPoint';
2023

0 commit comments

Comments
 (0)