Skip to content

Commit 427b3bb

Browse files
committed
Move webview keybindings to own file
1 parent 7a7e566 commit 427b3bb

3 files changed

Lines changed: 59 additions & 45 deletions

File tree

src/vs/workbench/parts/html/browser/html.contribution.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import { MenuRegistry } from 'vs/platform/actions/common/actions';
2020
import { IExtensionsWorkbenchService } from 'vs/workbench/parts/extensions/common/extensions';
2121
import { IEditorRegistry, EditorDescriptor, Extensions as EditorExtensions } from 'vs/workbench/browser/editor';
2222

23+
import './webview.contribution';
24+
2325
function getActivePreviewsForResource(accessor: ServicesAccessor, resource: URI | string) {
2426
const uri = resource instanceof URI ? resource : URI.parse(resource);
2527
return accessor.get(IWorkbenchEditorService).getVisibleEditors()
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
6+
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
7+
import { ContextKeyExpr, } from 'vs/platform/contextkey/common/contextkey';
8+
import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
9+
10+
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actions';
11+
import { KEYBINDING_CONTEXT_WEBVIEWEDITOR_FIND_WIDGET_INPUT_FOCUSED, ShowWebViewEditorFindTermCommand, KEYBINDING_CONTEXT_WEBVIEWEDITOR_FOCUS, KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE, HideWebViewEditorFindCommand, ShowWebViewEditorFindWidgetAction } from './webviewEditor';
12+
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
13+
import { Registry } from 'vs/platform/registry/common/platform';
14+
15+
16+
const category = 'Webview';
17+
const actionRegistry = <IWorkbenchActionRegistry>Registry.as(ActionExtensions.WorkbenchActions);
18+
19+
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(ShowWebViewEditorFindWidgetAction, ShowWebViewEditorFindWidgetAction.ID, ShowWebViewEditorFindWidgetAction.LABEL, {
20+
primary: KeyMod.CtrlCmd | KeyCode.KEY_F
21+
}, KEYBINDING_CONTEXT_WEBVIEWEDITOR_FOCUS),
22+
'Webview: Focus Find Widget', category);
23+
24+
25+
const showNextFindTermCommand = new ShowWebViewEditorFindTermCommand({
26+
id: 'editor.action.webvieweditor.showNextFindTerm',
27+
precondition: KEYBINDING_CONTEXT_WEBVIEWEDITOR_FIND_WIDGET_INPUT_FOCUSED,
28+
kbOpts: {
29+
primary: KeyMod.Alt | KeyCode.DownArrow
30+
}
31+
}, true);
32+
KeybindingsRegistry.registerCommandAndKeybindingRule(showNextFindTermCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.editorContrib()));
33+
34+
const showPreviousFindTermCommand = new ShowWebViewEditorFindTermCommand({
35+
id: 'editor.action.webvieweditor.showPreviousFindTerm',
36+
precondition: KEYBINDING_CONTEXT_WEBVIEWEDITOR_FIND_WIDGET_INPUT_FOCUSED,
37+
kbOpts: {
38+
primary: KeyMod.Alt | KeyCode.UpArrow
39+
}
40+
}, false);
41+
KeybindingsRegistry.registerCommandAndKeybindingRule(showPreviousFindTermCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.editorContrib()));
42+
43+
44+
const hideCommand = new HideWebViewEditorFindCommand({
45+
id: 'editor.action.webvieweditor.hideFind',
46+
precondition: ContextKeyExpr.and(
47+
KEYBINDING_CONTEXT_WEBVIEWEDITOR_FOCUS,
48+
KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE),
49+
kbOpts: {
50+
primary: KeyCode.Escape
51+
}
52+
});
53+
KeybindingsRegistry.registerCommandAndKeybindingRule(hideCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.editorContrib()));

src/vs/workbench/parts/html/browser/webviewEditor.ts

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,10 @@ import { IStorageService } from 'vs/platform/storage/common/storage';
1212
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
1313
import { Command, ICommandOptions } from 'vs/editor/browser/editorExtensions';
1414
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
15-
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
16-
import { ContextKeyExpr, IContextKey, RawContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
17-
import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
15+
import { IContextKey, RawContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
1816

1917
import { Webview } from './webview';
2018
import { Builder } from 'vs/base/browser/builder';
21-
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actions';
22-
import { Registry } from 'vs/platform/registry/common/platform';
23-
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
2419
import { Action } from 'vs/base/common/actions';
2520
import { TPromise } from 'vs/base/common/winjs.base';
2621

@@ -98,7 +93,7 @@ export abstract class WebviewEditor extends BaseWebviewEditor {
9893
protected abstract createEditor(parent: Builder): void;
9994
}
10095

101-
class ShowWebViewEditorFindWidgetAction extends Action {
96+
export class ShowWebViewEditorFindWidgetAction extends Action {
10297
public static readonly ID = 'editor.action.webvieweditor.showFind';
10398
public static readonly LABEL = nls.localize('editor.action.webvieweditor.showFind', "Focus Find Widget");
10499

@@ -127,15 +122,7 @@ class ShowWebViewEditorFindWidgetAction extends Action {
127122
}
128123
}
129124

130-
const category = 'Webview';
131-
let actionRegistry = <IWorkbenchActionRegistry>Registry.as(ActionExtensions.WorkbenchActions);
132-
133-
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(ShowWebViewEditorFindWidgetAction, ShowWebViewEditorFindWidgetAction.ID, ShowWebViewEditorFindWidgetAction.LABEL, {
134-
primary: KeyMod.CtrlCmd | KeyCode.KEY_F
135-
}, KEYBINDING_CONTEXT_WEBVIEWEDITOR_FOCUS),
136-
'Webview: Focus Find Widget', category);
137-
138-
class HideWebViewEditorFindCommand extends Command {
125+
export class HideWebViewEditorFindCommand extends Command {
139126
public runCommand(accessor: ServicesAccessor, args: any): void {
140127
const webViewEditor = this.getWebViewEditor(accessor);
141128
if (webViewEditor) {
@@ -151,18 +138,8 @@ class HideWebViewEditorFindCommand extends Command {
151138
return null;
152139
}
153140
}
154-
const hideCommand = new HideWebViewEditorFindCommand({
155-
id: 'editor.action.webvieweditor.hideFind',
156-
precondition: ContextKeyExpr.and(
157-
KEYBINDING_CONTEXT_WEBVIEWEDITOR_FOCUS,
158-
KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE),
159-
kbOpts: {
160-
primary: KeyCode.Escape
161-
}
162-
});
163-
KeybindingsRegistry.registerCommandAndKeybindingRule(hideCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.editorContrib()));
164141

165-
class ShowWebViewEditorFindTermCommand extends Command {
142+
export class ShowWebViewEditorFindTermCommand extends Command {
166143
constructor(opts: ICommandOptions, private _next: boolean) {
167144
super(opts);
168145
}
@@ -186,21 +163,3 @@ class ShowWebViewEditorFindTermCommand extends Command {
186163
return null;
187164
}
188165
}
189-
190-
const showNextFindTermCommand = new ShowWebViewEditorFindTermCommand({
191-
id: 'editor.action.webvieweditor.showNextFindTerm',
192-
precondition: KEYBINDING_CONTEXT_WEBVIEWEDITOR_FIND_WIDGET_INPUT_FOCUSED,
193-
kbOpts: {
194-
primary: KeyMod.Alt | KeyCode.DownArrow
195-
}
196-
}, true);
197-
KeybindingsRegistry.registerCommandAndKeybindingRule(showNextFindTermCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.editorContrib()));
198-
199-
const showPreviousFindTermCommand = new ShowWebViewEditorFindTermCommand({
200-
id: 'editor.action.webvieweditor.showPreviousFindTerm',
201-
precondition: KEYBINDING_CONTEXT_WEBVIEWEDITOR_FIND_WIDGET_INPUT_FOCUSED,
202-
kbOpts: {
203-
primary: KeyMod.Alt | KeyCode.UpArrow
204-
}
205-
}, false);
206-
KeybindingsRegistry.registerCommandAndKeybindingRule(showPreviousFindTermCommand.toCommandAndKeybindingRule(KeybindingsRegistry.WEIGHT.editorContrib()));

0 commit comments

Comments
 (0)