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 for issue #4090: cmd.js line 20-26 replaced with OS-specific keyboard shortcut mappings with localization. #10570

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

StillAbeginnerr
Copy link

@StillAbeginnerr StillAbeginnerr commented Nov 30, 2024

Description of Code Change
The proposed change enhances keyboard shortcut mappings to dynamically adapt based on the operating system.

Original Code

The replacements object statically maps symbols (e.g., ⌘, ⇧) to generic labels (e.g., Ctrl, Shift), with no differentiation for macOS.

image

This shows CTRL + Shift + C on German language.


Proposed Change :

OS Detection
Introduces a mac variable to determine if the operating system is macOS (detected.os === 'mac').

Dynamic Mapping
For macOS:
Uses macOS-specific symbols and labels (e.g., ⌘ Cmd, ⇧ Shift).
Prepends symbols to enhance clarity.

For Others:
Defaults to generic labels like Ctrl, Alt, and Shift.

Localization:
Integrates t() to fetch OS-specific, human-readable labels, supporting multiple languages.

image

This newly proposed shows STRG + Umschalt + C on German language.

…specific keyboard shortcut mappings with localization
…specific keyboard shortcut mappings with localization
…specific keyboard shortcut mappings with localization
Comment on lines +20 to +24
'⌘': mac ? '⌘ ' : t('shortcuts.key.ctrl'),
'⇧': mac ? '⇧ ' : t('shortcuts.key.shift'),
'⌥': mac ? '⌥ ' : t('shortcuts.key.alt'),
'⌫': mac ? '⌫ ' : t('shortcuts.key.backspace'),
'⌦': mac ? '⌦ ' : t('shortcuts.key.del'),
Copy link
Collaborator

@1ec5 1ec5 Dec 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is essentially the same as what c22fa60 did in uiCmd.display down below to fix the Keyboard Shortcuts screen. I suspect c22fa60 didn’t touch this function because it’s also being used in places where raw key identifiers are needed rather than human-readable labels. For example, the following code uses the return value to register the actual keyboard shortcut:

var keys = (detected.os === 'mac' ? [uiCmd('⌃⌘F'), 'f11'] : ['f11']);
context.keybinding().on(keys, fullScreen);

iD/modules/ui/zoom.js

Lines 102 to 110 in 3025d4f

utilKeybinding.plusKeys.forEach(function(key) {
context.keybinding().on([key], zoomIn);
context.keybinding().on([uiCmd('⌥' + key)], zoomInFurther);
});
utilKeybinding.minusKeys.forEach(function(key) {
context.keybinding().on([key], zoomOut);
context.keybinding().on([uiCmd('⌥' + key)], zoomOutFurther);
});

If you run this branch on macOS, or on Windows with the German localization, will the shortcuts function correctly when you press them? If not, then maybe we need to revert this function to what it was previously. If we look back at the code I pointed to earlier, notice how it’s only being used to create the tooltip – so it’s probably only for display purposes:

.keys([uiCmd('⌘⇧' + t('info_panels.history.key'))])

If that’s the case, then changing that code to call uiCmd.display instead might fix the issue for that particular tooltip. So instead of implementing anything new, you’d be reviewing each of the calls to uiCmd, deciding whether it should be replaced with a call to uiCmd.display.

Copy link
Author

@StillAbeginnerr StillAbeginnerr Dec 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank very much for the detailed explanation, it's very helpful and I now understood with more clarity, gotta read more about this codebase, and I've marked the calls where uiCmd been called and now checking how useful, the uiCmd.display would be for a particular tooltip...will submit a pull request again after high detailed review of each call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Localize keyboard button texts (e.g. "Ctrl" -> "Strg")
2 participants