提交 eb45d355 编写于 作者: S Sandeep Somavarapu

#50583

- Implement Context scoped history input widget
- Adopt to context scoped history input widget
上级 83713d36
......@@ -30,6 +30,7 @@ import { ITheme, registerThemingParticipant, IThemeService } from 'vs/platform/t
import { Color } from 'vs/base/common/color';
import { IConfigurationChangedEvent } from 'vs/editor/common/config/editorOptions';
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';
import { ContextScopedFindInput, ContextScopedHistoryInputBox } from 'vs/platform/widget/browser/input';
export interface IFindController {
......@@ -88,6 +89,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
private _controller: IFindController;
private readonly _contextViewProvider: IContextViewProvider;
private readonly _keybindingService: IKeybindingService;
private readonly _contextKeyService: IContextKeyService;
private _domNode: HTMLElement;
private _findInput: FindInput;
......@@ -131,6 +133,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
this._state = state;
this._contextViewProvider = contextViewProvider;
this._keybindingService = keybindingService;
this._contextKeyService = contextKeyService;
this._isVisible = false;
this._isReplaceVisible = false;
......@@ -710,7 +713,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
private _buildFindPart(): HTMLElement {
// Find input
this._findInput = this._register(new FindInput(null, this._contextViewProvider, {
this._findInput = this._register(new ContextScopedFindInput(null, this._contextViewProvider, {
width: FIND_INPUT_AREA_WIDTH,
label: NLS_FIND_INPUT_LABEL,
placeholder: NLS_FIND_INPUT_PLACEHOLDER,
......@@ -733,7 +736,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
return { content: e.message };
}
}
}));
}, this._contextKeyService));
this._findInput.setRegex(!!this._state.isRegex);
this._findInput.setCaseSensitive(!!this._state.matchCase);
this._findInput.setWholeWords(!!this._state.wholeWord);
......@@ -839,11 +842,11 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
let replaceInput = document.createElement('div');
replaceInput.className = 'replace-input';
replaceInput.style.width = REPLACE_INPUT_AREA_WIDTH + 'px';
this._replaceInputBox = this._register(new HistoryInputBox(replaceInput, null, {
this._replaceInputBox = this._register(new ContextScopedHistoryInputBox(replaceInput, null, {
ariaLabel: NLS_REPLACE_INPUT_LABEL,
placeholder: NLS_REPLACE_INPUT_PLACEHOLDER,
history: []
}));
}, this._contextKeyService));
this._register(dom.addStandardDisposableListener(this._replaceInputBox.inputElement, 'keydown', (e) => this._onReplaceInputKeyDown(e)));
this._register(dom.addStandardDisposableListener(this._replaceInputBox.inputElement, 'input', (e) => {
......
......@@ -14,6 +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 } from 'vs/platform/widget/browser/input';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
const NLS_FIND_INPUT_LABEL = nls.localize('label.find', "Find");
const NLS_FIND_INPUT_PLACEHOLDER = nls.localize('placeholder.find', "Find");
......@@ -31,14 +33,15 @@ export abstract class SimpleFindWidget extends Widget {
private _updateHistoryDelayer: Delayer<void>;
constructor(
@IContextViewService private readonly _contextViewService: IContextViewService
@IContextViewService private readonly _contextViewService: IContextViewService,
@IContextKeyService contextKeyService: IContextKeyService,
) {
super();
this._findInput = this._register(new FindInput(null, this._contextViewService, {
this._findInput = this._register(new ContextScopedFindInput(null, this._contextViewService, {
label: NLS_FIND_INPUT_LABEL,
placeholder: NLS_FIND_INPUT_PLACEHOLDER,
}));
}, contextKeyService));
// Find History with update delayer
this._updateHistoryDelayer = new Delayer<void>(500);
......
/*---------------------------------------------------------------------------------------------
* 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 { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { HistoryInputBox, IHistoryInputOptions } from 'vs/base/browser/ui/inputbox/inputBox';
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';
export const HistoryInputBoxContext = 'historyInputBox';
export class ContextScopedHistoryInputBox extends HistoryInputBox implements IWidget {
constructor(container: HTMLElement, contextViewProvider: IContextViewProvider, options: IHistoryInputOptions,
@IContextKeyService contextKeyService: IContextKeyService
) {
super(container, contextViewProvider, options);
this._register(createWidgetScopedContextKeyService(contextKeyService, this, HistoryInputBoxContext));
}
}
export class ContextScopedFindInput extends FindInput {
constructor(container: HTMLElement, contextViewProvider: IContextViewProvider, options: IFindInputOptions,
@IContextKeyService contextKeyService: IContextKeyService
) {
super(container, contextViewProvider, options);
this._register(createWidgetScopedContextKeyService(contextKeyService, this.inputBox, HistoryInputBoxContext));
}
}
\ No newline at end of file
/*---------------------------------------------------------------------------------------------
* 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 { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { ContextKeyDefinedExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { HistoryInputBoxContext } from 'vs/platform/widget/browser/input';
import { HistoryInputBox } from 'vs/base/browser/ui/inputbox/inputbox';
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'input.action.historyPrevious',
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
when: new ContextKeyDefinedExpr(HistoryInputBoxContext),
primary: KeyMod.Alt | KeyCode.UpArrow,
handler: (accessor, arg2) => {
const historyInputBox: HistoryInputBox = accessor.get(IContextKeyService).getContext(document.activeElement).getValue(HistoryInputBoxContext);
historyInputBox.showPreviousValue();
}
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'input.action.historyNext',
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
when: new ContextKeyDefinedExpr(HistoryInputBoxContext),
primary: KeyMod.Alt | KeyCode.DownArrow,
handler: (accessor, arg2) => {
const historyInputBox: HistoryInputBox = accessor.get(IContextKeyService).getContext(document.activeElement).getValue(HistoryInputBoxContext);
historyInputBox.showNextValue();
}
});
/*---------------------------------------------------------------------------------------------
* 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 { IContextKeyService, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
export function createWidgetScopedContextKeyService(contextKeyService: IContextKeyService, widget: IWidget, contextKey: string): IContextKeyService {
const result = contextKeyService.createScoped(widget.element);
const widgetContext = new RawContextKey<IWidget>(contextKey, widget);
widgetContext.bindTo(result);
return result;
}
export interface IWidget {
readonly element: HTMLElement;
}
\ No newline at end of file
......@@ -29,6 +29,7 @@ import { badgeBackground, contrastBorder } from 'vs/platform/theme/common/colorR
import { localize } from 'vs/nls';
import { Checkbox } from 'vs/base/browser/ui/checkbox/checkbox';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ContextScopedHistoryInputBox } from 'vs/platform/widget/browser/input';
export class ToggleMarkersPanelAction extends TogglePanelAction {
......@@ -151,7 +152,7 @@ export class MarkersFilterActionItem extends BaseActionItem {
}
private createInput(container: HTMLElement): void {
this.filterInputBox = this._register(this.instantiationService.createInstance(HistoryInputBox, container, this.contextViewService, {
this.filterInputBox = this._register(this.instantiationService.createInstance(ContextScopedHistoryInputBox, container, this.contextViewService, {
placeholder: Messages.MARKERS_PANEL_FILTER_PLACEHOLDER,
ariaLabel: Messages.MARKERS_PANEL_FILTER_ARIA_LABEL,
history: this.itemOptions.filterHistory
......@@ -232,14 +233,6 @@ export class MarkersFilterActionItem extends BaseActionItem {
}
}
private showNextFilter() {
this.filterInputBox.showNextValue();
}
private showPreviousFilter() {
this.filterInputBox.showPreviousValue();
}
private onInputKeyDown(keyboardEvent: IKeyboardEvent, filterInputBox: HistoryInputBox) {
let handled = false;
switch (keyboardEvent.keyCode) {
......@@ -247,14 +240,6 @@ export class MarkersFilterActionItem extends BaseActionItem {
filterInputBox.value = '';
handled = true;
break;
case KeyCode.UpArrow:
this.showPreviousFilter();
handled = true;
break;
case KeyCode.DownArrow:
this.showNextFilter();
handled = true;
break;
}
if (handled) {
keyboardEvent.stopPropagation();
......
......@@ -14,6 +14,8 @@ import { KeyCode } from 'vs/base/common/keyCodes';
import { Event as CommonEvent, Emitter } from 'vs/base/common/event';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { attachInputBoxStyler, attachCheckboxStyler } from 'vs/platform/theme/common/styler';
import { ContextScopedHistoryInputBox } from 'vs/platform/widget/browser/input';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
export interface IOptions {
placeholder?: string;
......@@ -44,7 +46,8 @@ export class PatternInputWidget extends Widget {
public onCancel: CommonEvent<boolean> = this._onCancel.event;
constructor(parent: HTMLElement, private contextViewProvider: IContextViewProvider, options: IOptions = Object.create(null),
@IThemeService protected themeService: IThemeService
@IThemeService protected themeService: IThemeService,
@IContextKeyService private contextKeyService: IContextKeyService
) {
super();
this.onOptionChange = null;
......@@ -146,14 +149,14 @@ export class PatternInputWidget extends Widget {
this.domNode.style.width = this.width + 'px';
dom.addClass(this.domNode, 'monaco-findInput');
this.inputBox = new HistoryInputBox(this.domNode, this.contextViewProvider, {
this.inputBox = new ContextScopedHistoryInputBox(this.domNode, this.contextViewProvider, {
placeholder: this.placeholder || '',
ariaLabel: this.ariaLabel || '',
validationOptions: {
validation: null
},
history: options.history || []
});
}, this.contextKeyService);
this._register(attachInputBoxStyler(this.inputBox, this.themeService));
this.inputFocusTracker = dom.trackFocus(this.inputBox.inputElement);
this.onkeyup(this.inputBox.inputElement, (keyboardEvent) => this.onInputKeyUp(keyboardEvent));
......@@ -186,9 +189,10 @@ export class PatternInputWidget extends Widget {
export class ExcludePatternInputWidget extends PatternInputWidget {
constructor(parent: HTMLElement, contextViewProvider: IContextViewProvider, options: IOptions = Object.create(null),
@IThemeService themeService: IThemeService
@IThemeService themeService: IThemeService,
@IContextKeyService contextKeyService: IContextKeyService
) {
super(parent, contextViewProvider, options, themeService);
super(parent, contextViewProvider, options, themeService, contextKeyService);
}
private useExcludesAndIgnoreFilesBox: Checkbox;
......
......@@ -31,6 +31,7 @@ import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
import { ISearchConfigurationProperties } from 'vs/platform/search/common/search';
import { ContextScopedFindInput, ContextScopedHistoryInputBox } from 'vs/platform/widget/browser/input';
export interface ISearchWidgetOptions {
value?: string;
......@@ -243,7 +244,7 @@ export class SearchWidget extends Widget {
};
let searchInputContainer = dom.append(parent, dom.$('.search-container.input-box'));
this.searchInput = this._register(new FindInput(searchInputContainer, this.contextViewService, inputOptions));
this.searchInput = this._register(new ContextScopedFindInput(searchInputContainer, this.contextViewService, inputOptions, this.keyBindingService));
this._register(attachFindInputBoxStyler(this.searchInput, this.themeService));
this.searchInput.onKeyUp((keyboardEvent: IKeyboardEvent) => this.onSearchInputKeyUp(keyboardEvent));
this.searchInput.setValue(options.value || '');
......@@ -282,11 +283,11 @@ export class SearchWidget extends Widget {
private renderReplaceInput(parent: HTMLElement, options: ISearchWidgetOptions): void {
this.replaceContainer = dom.append(parent, dom.$('.replace-container.disabled'));
let replaceBox = dom.append(this.replaceContainer, dom.$('.input-box'));
this.replaceInput = this._register(new HistoryInputBox(replaceBox, this.contextViewService, {
this.replaceInput = this._register(new ContextScopedHistoryInputBox(replaceBox, this.contextViewService, {
ariaLabel: nls.localize('label.Replace', 'Replace: Type replace term and press Enter to preview or Escape to cancel'),
placeholder: nls.localize('search.replace.placeHolder', "Replace"),
history: options.replaceHistory || []
}));
}, this.keyBindingService));
this._register(attachInputBoxStyler(this.replaceInput, this.themeService));
this.onkeyup(this.replaceInput.inputElement, (keyboardEvent) => this.onReplaceInputKeyUp(keyboardEvent));
this.replaceInput.onDidChange(() => this._onReplaceValueChanged.fire());
......
......@@ -16,7 +16,7 @@ export class TerminalFindWidget extends SimpleFindWidget {
@IContextKeyService private readonly _contextKeyService: IContextKeyService,
@ITerminalService private readonly _terminalService: ITerminalService
) {
super(_contextViewService);
super(_contextViewService, _contextKeyService);
this._findInputFocused = KEYBINDING_CONTEXT_TERMINAL_FIND_WIDGET_INPUT_FOCUSED.bindTo(this._contextKeyService);
}
......
......@@ -10,7 +10,7 @@ import { getMediaMime, guessMimeTypes } from 'vs/base/common/mime';
import { nativeSep, extname } from 'vs/base/common/paths';
import { startsWith } from 'vs/base/common/strings';
import URI from 'vs/base/common/uri';
import { IContextKey } from 'vs/platform/contextkey/common/contextkey';
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { IFileService } from 'vs/platform/files/common/files';
......@@ -45,6 +45,7 @@ export class WebviewElement {
@IThemeService private readonly _themeService: IThemeService,
@IEnvironmentService private readonly _environmentService: IEnvironmentService,
@IContextViewService private readonly _contextViewService: IContextViewService,
@IContextKeyService private readonly _contextKeyService: IContextKeyService,
@IFileService private readonly _fileService: IFileService,
) {
this._webview = document.createElement('webview');
......@@ -188,7 +189,7 @@ export class WebviewElement {
}),
);
this._webviewFindWidget = new WebviewFindWidget(this._contextViewService, this);
this._webviewFindWidget = new WebviewFindWidget(this._contextViewService, this._contextKeyService, this);
this._disposables.push(this._webviewFindWidget);
this.style(this._themeService.getTheme());
......
......@@ -6,14 +6,16 @@
import { SimpleFindWidget } from 'vs/editor/contrib/find/simpleFindWidget';
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
import { WebviewElement } from './webviewElement';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
export class WebviewFindWidget extends SimpleFindWidget {
constructor(
@IContextViewService contextViewService: IContextViewService,
@IContextKeyService contextKeyService: IContextKeyService,
private readonly webview: WebviewElement
) {
super(contextViewService);
super(contextViewService, contextKeyService);
}
public find(previous: boolean) {
......
......@@ -15,6 +15,9 @@ import 'vs/workbench/services/configuration/common/configurationExtensionPoint';
// Editor
import 'vs/editor/editor.all';
// Platform
import 'vs/platform/widget/browser/widget.contribution';
// Menus/Actions
import 'vs/workbench/services/actions/electron-browser/menusExtensionPoint';
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册