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

fix(useKeyboardShortcuts): allow for shift key plus special characters #629

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/composables/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const setTool = (tool: Tools) => () => {

const showKeyboardShortcuts = () => {
const keyboardStore = useKeyboardShortcutsStore();
keyboardStore.settingsOpen = true;
keyboardStore.settingsOpen = !keyboardStore.settingsOpen;
};

export const ACTION_TO_FUNC = {
Expand Down
20 changes: 18 additions & 2 deletions src/composables/useKeyboardShortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,25 @@ export function useKeyboardShortcuts() {
unwatchFuncs.forEach((unwatch) => unwatch());

unwatchFuncs = getEntries(actionMap).map(([action, key]) => {
const individualKeys = key.split('+');
const lastKey = individualKeys[individualKeys.length - 1];

return whenever(keys[key], () => {
// basic detection for exact modifier match
if (keys.current.size === key.split('+').length) {
const shiftPressed = keys.current.has('shift');
const lastPressedKey = Array.from(keys.current).pop();
const currentKeyWithCase = shiftPressed
? lastPressedKey?.toUpperCase() ?? lastPressedKey
: lastPressedKey;

// keyCountMatches checks for exact modifier match
const keyCountMatches = keys.current.size === individualKeys.length;
const lastKeyMatches = lastKey === currentKeyWithCase;
const shiftCaseMatches =
shiftPressed &&
keys.current.size - 1 === individualKeys.length &&
lastKeyMatches;

if ((keyCountMatches && lastKeyMatches) || shiftCaseMatches) {
ACTION_TO_FUNC[action]();
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ export const LAYER_PRESET_BY_MODALITY: Record<string, string> = {
};
export const LAYER_PRESET_DEFAULT = 'Blue to Red Rainbow';

// Keyboard shortcuts/hotkeys. Can add modifiers: 'Shift+Ctrl+A'
// Keyboard shortcuts/hotkeys. Can add modifiers: 'Shift+Ctrl+a'
export const ACTION_TO_KEY = {
windowLevel: 'l',
pan: 'n',
Expand Down
Loading