From 445ffedf021bbd68f6a919661c5af930ad03a5af Mon Sep 17 00:00:00 2001 From: Akos Kitta Date: Tue, 21 Jul 2020 09:31:45 +0200 Subject: [PATCH] patched the keybinding registry Signed-off-by: Akos Kitta --- .../browser/arduino-ide-frontend-module.ts | 5 +++- .../src/browser/theia/core/keybindings.ts | 28 +++++++++++++++++++ .../theia/navigator/navigator-contribution.ts | 10 +++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 arduino-ide-extension/src/browser/theia/core/keybindings.ts diff --git a/arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts b/arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts index d206389f..2b5e9801 100644 --- a/arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts +++ b/arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts @@ -39,7 +39,8 @@ import { ApplicationShell as TheiaApplicationShell, ShellLayoutRestorer as TheiaShellLayoutRestorer, KeybindingContribution, - CommonFrontendContribution as TheiaCommonFrontendContribution + CommonFrontendContribution as TheiaCommonFrontendContribution, + KeybindingRegistry as TheiaKeybindingRegistry } from '@theia/core/lib/browser'; import { MenuContribution } from '@theia/core/lib/common/menu'; import { ApplicationShell } from './theia/core/application-shell'; @@ -103,6 +104,7 @@ import { PreferencesContribution } from './theia/preferences/preference-contribu import { QuitApp } from './contributions/quit-app'; import { SketchControl } from './contributions/sketch-control-contributions'; import { Settings } from './contributions/settings'; +import { KeybindingRegistry } from './theia/core/keybindings'; const ElementQueries = require('css-element-queries/src/ElementQueries'); @@ -278,6 +280,7 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => { rebind(TheiaFileMenuContribution).to(ArduinoFileMenuContribution).inSingletonScope(); rebind(TheiaCommonFrontendContribution).to(CommonFrontendContribution).inSingletonScope(); rebind(TheiaPreferencesContribution).to(PreferencesContribution).inSingletonScope(); + rebind(TheiaKeybindingRegistry).to(KeybindingRegistry).inSingletonScope(); // Show a disconnected status bar, when the daemon is not available bind(ApplicationConnectionStatusContribution).toSelf().inSingletonScope(); diff --git a/arduino-ide-extension/src/browser/theia/core/keybindings.ts b/arduino-ide-extension/src/browser/theia/core/keybindings.ts new file mode 100644 index 00000000..40c83318 --- /dev/null +++ b/arduino-ide-extension/src/browser/theia/core/keybindings.ts @@ -0,0 +1,28 @@ +import { injectable } from 'inversify'; +import { Command } from '@theia/core/lib/common/command'; +import { Keybinding } from '@theia/core/lib/common/keybinding'; +import { KeybindingRegistry as TheiaKeybindingRegistry, KeybindingScope } from '@theia/core/lib/browser/keybinding'; + +@injectable() +export class KeybindingRegistry extends TheiaKeybindingRegistry { + + // https://github.com/eclipse-theia/theia/issues/8209 + unregisterKeybinding(key: string): void; + unregisterKeybinding(keybinding: Keybinding): void; + unregisterKeybinding(command: Command): void; + unregisterKeybinding(arg: string | Keybinding | Command): void { + const keymap = this.keymaps[KeybindingScope.DEFAULT]; + const filter = Command.is(arg) + ? ({ command }: Keybinding) => command === arg.id + : ({ keybinding }: Keybinding) => Keybinding.is(arg) + ? keybinding === arg.keybinding + : keybinding === arg; + for (const binding of keymap.filter(filter)) { + const idx = keymap.indexOf(binding); + if (idx !== -1) { + keymap.splice(idx, 1); + } + } + } + +} diff --git a/arduino-ide-extension/src/browser/theia/navigator/navigator-contribution.ts b/arduino-ide-extension/src/browser/theia/navigator/navigator-contribution.ts index 1f1b18fa..58226058 100644 --- a/arduino-ide-extension/src/browser/theia/navigator/navigator-contribution.ts +++ b/arduino-ide-extension/src/browser/theia/navigator/navigator-contribution.ts @@ -1,4 +1,6 @@ import { injectable, inject } from 'inversify'; +import { WorkspaceCommands } from '@theia/workspace/lib/browser/workspace-commands'; +import { KeybindingRegistry } from '@theia/core/lib/browser/keybinding'; import { FrontendApplication } from '@theia/core/lib/browser/frontend-application'; import { FileNavigatorContribution as TheiaFileNavigatorContribution } from '@theia/navigator/lib/browser/navigator-contribution'; import { EditorMode } from '../../editor-mode'; @@ -15,4 +17,12 @@ export class FileNavigatorContribution extends TheiaFileNavigatorContribution { } } + registerKeybindings(registry: KeybindingRegistry): void { + super.registerKeybindings(registry); + [ + WorkspaceCommands.FILE_RENAME, + WorkspaceCommands.FILE_DELETE + ].forEach(registry.unregisterKeybinding.bind(registry)); + } + }