Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[keybinding] Keybindings represented as string should be case-insensitive #8170

Open
kittaakos opened this issue Jul 14, 2020 · 0 comments
Open
Labels
bug bugs found in the application keybindings issues related to keybindings

Comments

@kittaakos
Copy link
Contributor

Bug Description:

CtrCmd+N is not the same as ctrlcmd+n. When it comes to the execution, yes they are, but when one has to customize the app and unregister bindings, the case sensitivity and order has to be considered.

Here is a diff describing the issue:

diff --git a/examples/api-samples/src/browser/api-samples-frontend-module.ts b/examples/api-samples/src/browser/api-samples-frontend-module.ts
index 1a397ab0a..ea7023c48 100644
--- a/examples/api-samples/src/browser/api-samples-frontend-module.ts
+++ b/examples/api-samples/src/browser/api-samples-frontend-module.ts
@@ -14,15 +14,43 @@
  * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
  ********************************************************************************/
 
-import { ContainerModule } from 'inversify';
+import { injectable, ContainerModule } from 'inversify';
 import { bindDynamicLabelProvider } from './label/sample-dynamic-label-provider-command-contribution';
 import { bindSampleUnclosableView } from './view/sample-unclosable-view-contribution';
 import { bindSampleOutputChannelWithSeverity } from './output/sample-output-channel-with-severity';
 import { bindSampleMenu } from './menu/sample-menu-contribution';
+import { environment } from '@theia/application-package/lib/environment';
+import { CommonMenus } from '@theia/core/lib/browser/common-frontend-contribution';
+import { KeybindingContribution, KeybindingRegistry } from '@theia/core/lib/browser';
+import { MenuContribution, MenuModelRegistry, CommandContribution, CommandRegistry } from '@theia/core/lib/common';
 
 export default new ContainerModule(bind => {
     bindDynamicLabelProvider(bind);
     bindSampleUnclosableView(bind);
     bindSampleOutputChannelWithSeverity(bind);
     bindSampleMenu(bind);
+    bind(RebindKeybinding).toSelf().inSingletonScope();
+    bind(CommandContribution).toService(RebindKeybinding);
+    bind(MenuContribution).toService(RebindKeybinding);
+    bind(KeybindingContribution).toService(RebindKeybinding);
 });
+
+@injectable()
+class RebindKeybinding implements KeybindingContribution, MenuContribution, CommandContribution {
+
+    registerCommands(r: CommandRegistry): void {
+        r.registerCommand({ id: 'my-command' }, { execute: () => console.log('my-command') });
+    }
+
+    registerMenus(r: MenuModelRegistry): void {
+        r.registerMenuAction([...CommonMenus.FILE, '999_my_command'], { commandId: 'my-command' });
+    }
+
+    registerKeybindings(r: KeybindingRegistry): void {
+        const kb = environment.electron.is() ? 'ctrlcmd+n' : 'alt+n'; // this works
+        // const kb = environment.electron.is() ? 'CtrlCmd+N' : 'Alt+N'; // this does not
+        r.unregisterKeybinding(kb);
+        r.registerKeybinding({ command: 'my-command', keybinding: kb });
+    }
+
+}

One has to use the exact same string when unregistering menu action.

keybinding: this.isElectron() ? 'ctrlcmd+n' : 'alt+n',

Acceptance criteria:
CtrlCmd+Shift+X should be the same as shift+ctrlCmd+x

Steps to Reproduce:

Additional Information

  • Operating System:
  • Theia Version:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug bugs found in the application keybindings issues related to keybindings
Projects
None yet
Development

No branches or pull requests

1 participant