Skip to content

Commit

Permalink
Merge pull request #40 from PRGfx/bugfix/hotkey-listener
Browse files Browse the repository at this point in the history
BUGFIX: directly register event-listener for ctrl-k
  • Loading branch information
Sebobo committed Mar 15, 2023
2 parents 2155293 + 3a651f3 commit 0f9776a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 22 deletions.
8 changes: 0 additions & 8 deletions Configuration/Settings.Neos.yaml
Expand Up @@ -19,9 +19,6 @@ Neos:
loadTestCommands: false
hotkeys:
filter:
# Hide the command bar hotkeys
- 'Shel.Neos.CommandBar.toggle.CMD'
- 'Shel.Neos.CommandBar.toggle.CTRL'
# Hide Neos hotkeys which are not relevant in the command bar
- 'UI.AddNodeModal.close'
- 'UI.InsertionModeModal.cancel'
Expand All @@ -35,11 +32,6 @@ Neos:
- 'UI.NodeVariantCreationDialog.createEmpty'
- 'UI.NodeVariantCreationDialog.createAndCopy'
- 'CR.Nodes.unfocus'
hotkeys:
# MacOS
'Shel.Neos.CommandBar.toggle.CMD': 'command+k'
# Linux & Windows
'Shel.Neos.CommandBar.toggle.CTRL': 'ctrl+k'

modules:
administration:
Expand Down
9 changes: 9 additions & 0 deletions packages/ui-plugin/src/CommandBarUiPlugin.tsx
Expand Up @@ -277,6 +277,15 @@ class CommandBarUiPlugin extends React.PureComponent<CommandBarUiPluginProps, Co
...preferences,
commands: { ...prev.commands, ...commands, ...pluginCommands },
}));

// add event-listener directly as the neos-ui hotkey-handling can't prevent defaults
document.addEventListener('keydown', (e) => {
if (e.key === 'k' && (e.metaKey || e.ctrlKey)) {
e.stopPropagation();
e.preventDefault();
this.props.toggleCommandBar();
}
});
}

buildCommandsFromHotkeys = (): HierarchicalCommandList => {
Expand Down
15 changes: 1 addition & 14 deletions packages/ui-plugin/src/manifest.js
@@ -1,6 +1,6 @@
import manifest, { SynchronousRegistry } from '@neos-project/neos-ui-extensibility';

import { reducer, actions } from './actions';
import { reducer } from './actions';
import CommandBarUiPlugin from './CommandBarUiPlugin';

manifest('Shel.Neos.CommandBar:CommandBar', {}, (globalRegistry, { frontendConfiguration }) => {
Expand All @@ -25,17 +25,4 @@ manifest('Shel.Neos.CommandBar:CommandBar', {}, (globalRegistry, { frontendConfi

// Register reducer
globalRegistry.get('reducers').set('Shel.Neos.CommandBar', { reducer });

// Register hotkeys
if (frontendConfiguration.hotkeys !== null && frontendConfiguration.hotkeys.length !== 0) {
const hotkeyRegistry = globalRegistry.get('hotkeys');
hotkeyRegistry.set('Shel.Neos.CommandBar.toggle.CMD', {
description: 'Toggle command bar',
action: actions.toggleCommandBar,
});
hotkeyRegistry.set('Shel.Neos.CommandBar.toggle.CTRL', {
description: 'Toggle command bar',
action: actions.toggleCommandBar,
});
}
});

0 comments on commit 0f9776a

Please sign in to comment.