提交 8ffd4d78 编写于 作者: D Daniel Imms

Fix escape to close terminal find widget

Fixes #28770
上级 6eab963c
......@@ -252,6 +252,11 @@ export interface ITerminalInstance {
*/
findPrevious(term: string): boolean;
/**
* Notifies the terminal that the find widget's focus state has been changed.
*/
notifyFindWidgetFocusChanged(isFocused: boolean): void;
/**
* Focuses the terminal instance.
*
......
......@@ -288,6 +288,7 @@ actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(FocusTerminalFin
primary: KeyMod.CtrlCmd | KeyCode.KEY_F
}, KEYBINDING_CONTEXT_TERMINAL_FOCUS), 'Terminal: Focus Find Widget', category);
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(HideTerminalFindWidgetAction, HideTerminalFindWidgetAction.ID, HideTerminalFindWidgetAction.LABEL, {
primary: KeyCode.Escape
}, KEYBINDING_CONTEXT_TERMINAL_FIND_WIDGET_VISIBLE), 'Terminal: Focus Find Widget', category);
primary: KeyCode.Escape,
secondary: [KeyCode.Shift | KeyCode.Escape]
}, ContextKeyExpr.and(KEYBINDING_CONTEXT_TERMINAL_FOCUS, KEYBINDING_CONTEXT_TERMINAL_FIND_WIDGET_VISIBLE)), 'Terminal: Focus Find Widget', category);
registerColors();
......@@ -84,6 +84,7 @@ export class TerminalFindWidget extends Widget {
private _findInput: FindInput;
private _domNode: HTMLElement;
private _isVisible: boolean;
private _focusTracker: dom.IFocusTracker;
constructor(
@IContextViewService private _contextViewService: IContextViewService,
......@@ -95,6 +96,9 @@ export class TerminalFindWidget extends Widget {
label: NLS_FIND_INPUT_LABEL,
placeholder: NLS_FIND_INPUT_PLACEHOLDER,
}));
this._focusTracker = this._register(dom.trackFocus(this._findInput.inputBox.inputElement));
this._register(this._focusTracker.addFocusListener(() => this._terminalService.getActiveInstance().notifyFindWidgetFocusChanged(true)));
this._register(this._focusTracker.addBlurListener(() => this._terminalService.getActiveInstance().notifyFindWidgetFocusChanged(false)));
let find = (previous) => {
let val = this._findInput.getValue();
......
......@@ -357,6 +357,13 @@ export class TerminalInstance implements ITerminalInstance {
return this._xterm.findPrevious(term);
}
public notifyFindWidgetFocusChanged(isFocused: boolean): void {
// In order to support escape to close the find widget when the terminal
// is focused terminalFocus needs to be true when either the terminal or
// the find widget are focused.
this._terminalFocusContextKey.set(isFocused || document.activeElement === this._xterm.textarea);
}
public dispose(): void {
if (this._linkHandler) {
this._linkHandler.dispose();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册