From bb624faa90f4dea2c29b2e7198946f06fed55bea Mon Sep 17 00:00:00 2001 From: Igor Vinokur Date: Wed, 11 Dec 2019 11:40:44 +0200 Subject: [PATCH] Fixes for Vscode emacs extension Signed-off-by: Igor Vinokur --- packages/core/src/browser/keybinding.ts | 14 +++++++--- packages/core/src/browser/keyboard/keys.ts | 2 +- .../plugin-vscode-commands-contribution.ts | 27 ++++++++++++++++++- .../plugin-ext/src/common/known-commands.ts | 2 ++ .../keybindings-contribution-handler.ts | 2 +- 5 files changed, 40 insertions(+), 7 deletions(-) diff --git a/packages/core/src/browser/keybinding.ts b/packages/core/src/browser/keybinding.ts index 239ee04ec58f2..2059591ed5849 100644 --- a/packages/core/src/browser/keybinding.ts +++ b/packages/core/src/browser/keybinding.ts @@ -29,6 +29,7 @@ import * as common from '../common/keybinding'; export enum KeybindingScope { DEFAULT, + DEFAULT_OVERRIDING, USER, WORKSPACE, END @@ -191,9 +192,10 @@ export class KeybindingRegistry { * Register a default keybinding to the registry. * * @param binding + * @param override Override existed keybinding */ - registerKeybinding(binding: Keybinding): Disposable { - return this.doRegisterKeybinding(binding, KeybindingScope.DEFAULT); + registerKeybinding(binding: Keybinding, override?: boolean): Disposable { + return this.doRegisterKeybinding(binding, !!override ? KeybindingScope.DEFAULT_OVERRIDING : undefined); } /** @@ -241,7 +243,7 @@ export class KeybindingRegistry { protected doRegisterKeybinding(binding: Keybinding, scope: KeybindingScope = KeybindingScope.DEFAULT): Disposable { try { this.resolveKeybinding(binding); - if (this.containsKeybinding(this.keymaps[scope], binding)) { + if (this.containsKeybinding(this.keymaps[scope], binding) && scope !== KeybindingScope.DEFAULT_OVERRIDING) { throw new Error(`"${binding.keybinding}" is in collision with something else [scope:${scope}]`); } this.keymaps[scope].push(binding); @@ -452,6 +454,10 @@ export class KeybindingRegistry { matches.partial = matches.partial.filter( binding => this.getKeybindingCollisions(result.partial, binding).partial.length === 0); + if (scope === KeybindingScope.DEFAULT_OVERRIDING) { + matches.full.reverse(); + matches.partial.reverse(); + } result.merge(matches); } this.sortKeybindingsByPriority(result.full); @@ -622,7 +628,7 @@ export class KeybindingRegistry { this.keySequence.push(keyCode); const bindings = this.getKeybindingsForKeySequence(this.keySequence); - if (this.tryKeybindingExecution(bindings.full, event)) { + if (bindings.partial.length === 0 && this.tryKeybindingExecution(bindings.full, event)) { this.keySequence = []; this.statusBar.removeElement('keybinding-status'); diff --git a/packages/core/src/browser/keyboard/keys.ts b/packages/core/src/browser/keyboard/keys.ts index 866fdbb1bbc95..b5a0a92822af2 100644 --- a/packages/core/src/browser/keyboard/keys.ts +++ b/packages/core/src/browser/keyboard/keys.ts @@ -236,7 +236,7 @@ export class KeyCode { } const schema: KeyCodeSchema = {}; - const keys = keybinding.trim().toLowerCase().split('+'); + const keys = keybinding.trim().toLowerCase().split(/[-+]/g); /* If duplicates i.e ctrl+ctrl+a or alt+alt+b or b+alt+b it is invalid */ if (keys.length !== new Set(keys).size) { throw new Error(`Can't parse keybinding ${keybinding} Duplicate modifiers`); diff --git a/packages/plugin-ext-vscode/src/browser/plugin-vscode-commands-contribution.ts b/packages/plugin-ext-vscode/src/browser/plugin-vscode-commands-contribution.ts index cffc578c1e39f..b4295876bf244 100644 --- a/packages/plugin-ext-vscode/src/browser/plugin-vscode-commands-contribution.ts +++ b/packages/plugin-ext-vscode/src/browser/plugin-vscode-commands-contribution.ts @@ -15,7 +15,15 @@ ********************************************************************************/ import { Command, CommandContribution, CommandRegistry, ResourceProvider } from '@theia/core'; -import { ApplicationShell, NavigatableWidget, open, OpenerService, Saveable } from '@theia/core/lib/browser'; +import { + ApplicationShell, + CommonCommands, + NavigatableWidget, + open, + OpenerService, + PrefixQuickOpenService, + Saveable +} from '@theia/core/lib/browser'; import { ContextKeyService } from '@theia/core/lib/browser/context-key-service'; import { ApplicationShellMouseTracker } from '@theia/core/lib/browser/shell/application-shell-mouse-tracker'; import { CommandService } from '@theia/core/lib/common/command'; @@ -64,6 +72,8 @@ export class PluginVscodeCommandsContribution implements CommandContribution { protected readonly openerService: OpenerService; @inject(ApplicationShellMouseTracker) protected readonly mouseTracker: ApplicationShellMouseTracker; + @inject(PrefixQuickOpenService) + protected readonly quickOpen: PrefixQuickOpenService; registerCommands(commands: CommandRegistry): void { commands.registerCommand(VscodeCommands.OPEN, { @@ -138,6 +148,21 @@ export class PluginVscodeCommandsContribution implements CommandContribution { commands.registerCommand({ id: 'workbench.action.files.openFolder' }, { execute: () => commands.executeCommand(WorkspaceCommands.OPEN_FOLDER.id) }); + commands.registerCommand({ id: 'workbench.action.gotoLine' }, { + execute: () => commands.executeCommand('editor.action.gotoLine') + }); + commands.registerCommand({ id: 'actions.find' }, { + execute: () => commands.executeCommand(CommonCommands.FIND.id) + }); + commands.registerCommand({ id: 'undo' }, { + execute: () => commands.executeCommand(CommonCommands.UNDO.id) + }); + commands.registerCommand({ id: 'editor.action.startFindReplaceAction' }, { + execute: () => commands.executeCommand(CommonCommands.REPLACE.id) + }); + commands.registerCommand({ id: 'workbench.action.quickOpen' }, { + execute: () => this.quickOpen.open('') + }); commands.registerCommand({ id: 'default:type' }, { execute: args => { const editor = MonacoEditor.getCurrent(this.editorManager); diff --git a/packages/plugin-ext/src/common/known-commands.ts b/packages/plugin-ext/src/common/known-commands.ts index e26cfed226d76..8dd548ad58b2e 100644 --- a/packages/plugin-ext/src/common/known-commands.ts +++ b/packages/plugin-ext/src/common/known-commands.ts @@ -199,8 +199,10 @@ export namespace KnownCommands { mappings['scrollPageUp'] = ['scrollPageUp', MONACO_CONVERSION_IDENTITY]; mappings['tab'] = ['tab', MONACO_CONVERSION_IDENTITY]; mappings['removeSecondaryCursors'] = ['removeSecondaryCursors', MONACO_CONVERSION_IDENTITY]; + mappings['cursorWordRight'] = ['cursorWordEndRight', MONACO_CONVERSION_IDENTITY]; mappings['cursorWordEndRight'] = ['cursorWordEndRight', MONACO_CONVERSION_IDENTITY]; mappings['cursorWordEndRightSelect'] = ['cursorWordEndRightSelect', MONACO_CONVERSION_IDENTITY]; + mappings['cursorWordLeft'] = ['cursorWordStartLeft', MONACO_CONVERSION_IDENTITY]; mappings['cursorWordStartLeft'] = ['cursorWordStartLeft', MONACO_CONVERSION_IDENTITY]; mappings['cursorWordStartLeftSelect'] = ['cursorWordStartLeftSelect', MONACO_CONVERSION_IDENTITY]; mappings['deleteWordLeft'] = ['deleteWordLeft', MONACO_CONVERSION_IDENTITY]; diff --git a/packages/plugin-ext/src/main/browser/keybindings/keybindings-contribution-handler.ts b/packages/plugin-ext/src/main/browser/keybindings/keybindings-contribution-handler.ts index 2cd13363a57af..24d3307afdfce 100644 --- a/packages/plugin-ext/src/main/browser/keybindings/keybindings-contribution-handler.ts +++ b/packages/plugin-ext/src/main/browser/keybindings/keybindings-contribution-handler.ts @@ -36,7 +36,7 @@ export class KeybindingsContributionPointHandler { for (const raw of contributions.keybindings) { const keybinding = this.toKeybinding(raw); if (keybinding) { - toDispose.push(this.keybindingRegistry.registerKeybinding(keybinding)); + toDispose.push(this.keybindingRegistry.registerKeybinding(keybinding, true)); } } return toDispose;