提交 79e52cb3 编写于 作者: P Peng Lyu

Move Enter handler to commands from input keydown handler.

上级 6e43f069
......@@ -9,7 +9,7 @@ import * as dom from 'vs/base/browser/dom';
import { FindInput, IFindInputStyles } from 'vs/base/browser/ui/findinput/findInput';
import { Widget } from 'vs/base/browser/ui/widget';
import { Delayer } from 'vs/base/common/async';
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { KeyCode } from 'vs/base/common/keyCodes';
import { FindReplaceState } from 'vs/editor/contrib/find/findState';
import { IMessage as InputBoxMessage } from 'vs/base/browser/ui/inputbox/inputBox';
import { SimpleButton } from 'vs/editor/contrib/find/findWidget';
......@@ -42,8 +42,7 @@ export abstract class SimpleFindWidget extends Widget {
@IContextViewService private readonly _contextViewService: IContextViewService,
@IContextKeyService contextKeyService: IContextKeyService,
private readonly _state: FindReplaceState = new FindReplaceState(),
showOptionButtons?: boolean,
private readonly _invertDefaultDirection: boolean = false
showOptionButtons?: boolean
) {
super();
......@@ -94,20 +93,6 @@ export abstract class SimpleFindWidget extends Widget {
this.findFirst();
}));
this._register(this._findInput.onKeyDown((e) => {
if (e.equals(KeyCode.Enter)) {
this.find(this._invertDefaultDirection);
e.preventDefault();
return;
}
if (e.equals(KeyMod.Shift | KeyCode.Enter)) {
this.find(!this._invertDefaultDirection);
e.preventDefault();
return;
}
}));
this.prevBtn = this._register(new SimpleButton({
label: NLS_PREVIOUS_MATCH_BTN_LABEL,
className: 'previous',
......
......@@ -50,7 +50,7 @@ import { IExtensionService } from 'vs/workbench/services/extensions/common/exten
import { getDefaultValue } from 'vs/platform/configuration/common/configurationRegistry';
import { isUndefined } from 'vs/base/common/types';
import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService';
import { IWebviewService, Webview } from 'vs/workbench/contrib/webview/browser/webview';
import { IWebviewService, Webview, KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_FOCUSED } from 'vs/workbench/contrib/webview/browser/webview';
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { generateUuid } from 'vs/base/common/uuid';
import { platform } from 'vs/base/common/process';
......@@ -525,6 +525,12 @@ export class ExtensionEditor extends BaseEditor {
}
}
runFindAction(previous: boolean): void {
if (this.activeElement && (<Webview>this.activeElement).runFindAction) {
(<Webview>this.activeElement).runFindAction(previous);
}
}
private onNavbarChange(extension: IExtension, { id, focus }: { id: string | null, focus: boolean }, template: IExtensionEditorTemplate): void {
if (this.editorLoadComplete) {
/* __GDPR__
......@@ -1314,28 +1320,66 @@ export class ExtensionEditor extends BaseEditor {
}
}
const contextKeyExpr = ContextKeyExpr.and(ContextKeyExpr.equals('activeEditor', ExtensionEditor.ID), ContextKeyExpr.not('editorFocus'));
class ShowExtensionEditorFindCommand extends Command {
public runCommand(accessor: ServicesAccessor, args: any): void {
const extensionEditor = this.getExtensionEditor(accessor);
const extensionEditor = getExtensionEditor(accessor);
if (extensionEditor) {
extensionEditor.showFind();
}
}
}
(new ShowExtensionEditorFindCommand({
id: 'editor.action.extensioneditor.showfind',
precondition: contextKeyExpr,
kbOpts: {
primary: KeyMod.CtrlCmd | KeyCode.KEY_F,
weight: KeybindingWeight.EditorContrib
}
})).register();
private getExtensionEditor(accessor: ServicesAccessor): ExtensionEditor | null {
const activeControl = accessor.get(IEditorService).activeControl as ExtensionEditor;
if (activeControl instanceof ExtensionEditor) {
return activeControl;
class StartExtensionEditorFindNextCommand extends Command {
public runCommand(accessor: ServicesAccessor, args: any): void {
const extensionEditor = getExtensionEditor(accessor);
if (extensionEditor) {
extensionEditor.runFindAction(false);
}
return null;
}
}
const showCommand = new ShowExtensionEditorFindCommand({
id: 'editor.action.extensioneditor.showfind',
precondition: ContextKeyExpr.and(ContextKeyExpr.equals('activeEditor', ExtensionEditor.ID), ContextKeyExpr.not('editorFocus')),
(new StartExtensionEditorFindNextCommand({
id: 'editor.action.extensioneditor.findNext',
precondition: ContextKeyExpr.and(
contextKeyExpr,
KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_FOCUSED),
kbOpts: {
primary: KeyMod.CtrlCmd | KeyCode.KEY_F,
primary: KeyCode.Enter,
weight: KeybindingWeight.EditorContrib
}
});
showCommand.register();
})).register();
class StartExtensionEditorFindPreviousCommand extends Command {
public runCommand(accessor: ServicesAccessor, args: any): void {
const extensionEditor = getExtensionEditor(accessor);
if (extensionEditor) {
extensionEditor.runFindAction(true);
}
}
}
(new StartExtensionEditorFindPreviousCommand({
id: 'editor.action.extensioneditor.findPrevious',
precondition: ContextKeyExpr.and(
contextKeyExpr,
KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_FOCUSED),
kbOpts: {
primary: KeyMod.Shift | KeyCode.Enter,
weight: KeybindingWeight.EditorContrib
}
})).register();
function getExtensionEditor(accessor: ServicesAccessor): ExtensionEditor | null {
const activeControl = accessor.get(IEditorService).activeControl as ExtensionEditor;
if (activeControl instanceof ExtensionEditor) {
return activeControl;
}
return null;
}
......@@ -530,7 +530,7 @@ actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(FindNext, FindNe
}, KEYBINDING_CONTEXT_TERMINAL_FOCUS), 'Terminal: Find next', category);
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(FindNext, FindNext.ID, FindNext.LABEL, {
primary: KeyCode.F3,
mac: { primary: KeyMod.CtrlCmd | KeyCode.KEY_G, secondary: [KeyCode.F3] }
mac: { primary: KeyMod.CtrlCmd | KeyCode.KEY_G, secondary: [KeyCode.F3, KeyMod.Shift | KeyCode.Enter] }
}, KEYBINDING_CONTEXT_TERMINAL_FIND_WIDGET_FOCUSED), 'Terminal: Find next');
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(FindPrevious, FindPrevious.ID_TERMINAL_FOCUS, FindPrevious.LABEL, {
primary: KeyMod.Shift | KeyCode.F3,
......@@ -538,7 +538,7 @@ actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(FindPrevious, Fi
}, KEYBINDING_CONTEXT_TERMINAL_FOCUS), 'Terminal: Find previous', category);
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(FindPrevious, FindPrevious.ID, FindPrevious.LABEL, {
primary: KeyMod.Shift | KeyCode.F3,
mac: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_G, secondary: [KeyMod.Shift | KeyCode.F3] },
mac: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_G, secondary: [KeyMod.Shift | KeyCode.F3, KeyCode.Enter] },
}, KEYBINDING_CONTEXT_TERMINAL_FIND_WIDGET_FOCUSED), 'Terminal: Find previous');
......
......@@ -19,7 +19,7 @@ export class TerminalFindWidget extends SimpleFindWidget {
@IContextKeyService private readonly _contextKeyService: IContextKeyService,
@ITerminalService private readonly _terminalService: ITerminalService
) {
super(_contextViewService, _contextKeyService, findState, true, true);
super(_contextViewService, _contextKeyService, findState, true);
this._register(findState.onFindReplaceStateChange(() => {
this.show();
}));
......
......@@ -153,6 +153,7 @@ export class DynamicWebviewEditorOverlay extends Disposable implements WebviewEd
reload(): void { this.withWebview(webview => webview.reload()); }
showFind(): void { this.withWebview(webview => webview.showFind()); }
hideFind(): void { this.withWebview(webview => webview.hideFind()); }
runFindAction(previous: boolean): void { this.withWebview(webview => webview.runFindAction(previous)); }
public getInnerWebview() {
return this._webview.value;
......
......@@ -15,8 +15,8 @@ import { EditorDescriptor, Extensions as EditorExtensions, IEditorRegistry } fro
import { Extensions as ActionExtensions, IWorkbenchActionRegistry } from 'vs/workbench/common/actions';
import { Extensions as EditorInputExtensions, IEditorInputFactoryRegistry } from 'vs/workbench/common/editor';
import { WebviewEditorInputFactory } from 'vs/workbench/contrib/webview/browser/webviewEditorInputFactory';
import { KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE, webviewDeveloperCategory } from 'vs/workbench/contrib/webview/browser/webview';
import { HideWebViewEditorFindCommand, ReloadWebviewAction, ShowWebViewEditorFindWidgetCommand } from '../browser/webviewCommands';
import { KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE, webviewDeveloperCategory, KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_FOCUSED } from 'vs/workbench/contrib/webview/browser/webview';
import { HideWebViewEditorFindCommand, ReloadWebviewAction, ShowWebViewEditorFindWidgetCommand, WebViewEditorFindNextCommand, WebViewEditorFindPreviousCommand } from '../browser/webviewCommands';
import { WebviewEditor } from '../browser/webviewEditor';
import { WebviewEditorInput } from '../browser/webviewEditorInput';
import { IWebviewEditorService, WebviewEditorService } from '../browser/webviewEditorService';
......@@ -58,6 +58,28 @@ function registerWebViewCommands(editorId: string): void {
weight: KeybindingWeight.EditorContrib
}
})).register();
(new WebViewEditorFindNextCommand({
id: WebViewEditorFindNextCommand.ID,
precondition: ContextKeyExpr.and(
contextKeyExpr,
KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_FOCUSED),
kbOpts: {
primary: KeyCode.Enter,
weight: KeybindingWeight.EditorContrib
}
})).register();
(new WebViewEditorFindPreviousCommand({
id: WebViewEditorFindPreviousCommand.ID,
precondition: ContextKeyExpr.and(
contextKeyExpr,
KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_FOCUSED),
kbOpts: {
primary: KeyMod.Shift | KeyCode.Enter,
weight: KeybindingWeight.EditorContrib
}
})).register();
}
registerWebViewCommands(WebviewEditor.ID);
......
......@@ -16,6 +16,7 @@ import { createDecorator } from 'vs/platform/instantiation/common/instantiation'
* Set when the find widget in a webview is visible.
*/
export const KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE = new RawContextKey<boolean>('webviewFindWidgetVisible', false);
export const KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_FOCUSED = new RawContextKey<boolean>('webviewFindWidgetFocused', false);
export const IWebviewService = createDecorator<IWebviewService>('webviewService');
......@@ -83,6 +84,7 @@ export interface Webview extends IDisposable {
showFind(): void;
hideFind(): void;
runFindAction(previous: boolean): void;
}
export interface WebviewElement extends Webview {
......
......@@ -32,6 +32,27 @@ export class HideWebViewEditorFindCommand extends Command {
}
}
export class WebViewEditorFindNextCommand extends Command {
public static readonly ID = 'editor.action.webvieweditor.findNext';
public runCommand(accessor: ServicesAccessor, args: any): void {
const webViewEditor = getActiveWebviewEditor(accessor);
if (webViewEditor) {
webViewEditor.find(false);
}
}
}
export class WebViewEditorFindPreviousCommand extends Command {
public static readonly ID = 'editor.action.webvieweditor.findPrevious';
public runCommand(accessor: ServicesAccessor, args: any): void {
const webViewEditor = getActiveWebviewEditor(accessor);
if (webViewEditor) {
webViewEditor.find(true);
}
}
}
export class ReloadWebviewAction extends Action {
static readonly ID = 'workbench.action.webview.reloadWebviewAction';
static readonly LABEL = nls.localize('refreshWebviewLabel', "Reload Webviews");
......@@ -62,4 +83,4 @@ function getActiveWebviewEditor(accessor: ServicesAccessor): WebviewEditor | nul
const editorService = accessor.get(IEditorService);
const activeControl = editorService.activeControl as WebviewEditor;
return activeControl.isWebviewEditor ? activeControl : null;
}
\ No newline at end of file
}
......@@ -25,7 +25,6 @@ export class WebviewEditor extends BaseEditor {
private readonly _scopedContextKeyService = this._register(new MutableDisposable<IContextKeyService>());
private _findWidgetVisible: IContextKey<boolean>;
private _editorFrame?: HTMLElement;
private _content?: HTMLElement;
......@@ -79,6 +78,12 @@ export class WebviewEditor extends BaseEditor {
this.withWebview(webview => webview.hideFind());
}
public find(previous: boolean) {
this.withWebview(webview => {
webview.runFindAction(previous);
});
}
public reload() {
this.withWebview(webview => webview.reload());
}
......
......@@ -268,6 +268,10 @@ export class IFrameWebview extends Disposable implements Webview {
throw new Error('Method not implemented.');
}
runFindAction(previous: boolean): void {
throw new Error('Method not implemented.');
}
public set state(state: string | undefined) {
this.content = {
html: this.content.html,
......
......@@ -4,8 +4,9 @@
*--------------------------------------------------------------------------------------------*/
import { SimpleFindWidget } from 'vs/workbench/contrib/codeEditor/browser/find/simpleFindWidget';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
import { KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_FOCUSED } from 'vs/workbench/contrib/webview/browser/webview';
export interface WebviewFindDelegate {
find(value: string, previous: boolean): void;
......@@ -15,6 +16,7 @@ export interface WebviewFindDelegate {
}
export class WebviewFindWidget extends SimpleFindWidget {
protected _findWidgetFocused: IContextKey<boolean>;
constructor(
private readonly _delegate: WebviewFindDelegate,
......@@ -22,6 +24,7 @@ export class WebviewFindWidget extends SimpleFindWidget {
@IContextKeyService contextKeyService: IContextKeyService
) {
super(contextViewService, contextKeyService);
this._findWidgetFocused = KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_FOCUSED.bindTo(contextKeyService);
}
public find(previous: boolean) {
......@@ -47,9 +50,13 @@ export class WebviewFindWidget extends SimpleFindWidget {
return false;
}
protected onFocusTrackerFocus() { }
protected onFocusTrackerFocus() {
this._findWidgetFocused.set(true);
}
protected onFocusTrackerBlur() { }
protected onFocusTrackerBlur() {
this._findWidgetFocused.reset();
}
protected onFindInputFocusTrackerFocus() { }
......
......@@ -640,6 +640,12 @@ export class ElectronWebviewBasedWebview extends Disposable implements Webview {
}
}
public runFindAction(previous: boolean) {
if (this._webviewFindWidget) {
this._webviewFindWidget.find(previous);
}
}
public reload() {
this.doUpdateContent();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册