-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
StillAbeginnerr
wants to merge
3
commits into
openstreetmap:develop
Choose a base branch
from
StillAbeginnerr:fix-issue-4090
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+9
−6
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
34d48e6
Fix for issue #4090: cmd.js line 20-26 replaced with OS-specific keyb…
StillAbeginnerr 959399e
Fix for issue #4090: cmd.js line 20-26 replaced with OS-specific keyb…
StillAbeginnerr 672b376
Fix for issue #4090: cmd.js line 20-26 replaced with OS-specific keyb…
StillAbeginnerr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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:iD/modules/ui/full_screen.js
Lines 72 to 73 in 3025d4f
iD/modules/ui/zoom.js
Lines 102 to 110 in 3025d4f
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:
iD/modules/ui/sections/data_layers.js
Line 404 in b5d45e3
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 touiCmd
, deciding whether it should be replaced with a call touiCmd.display
.There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@1ec5
While working, I found these 2 issues/bug
It seems that the keyboard shortcut for ? isn’t functioning as expected. Based on testing, it appears the shortcut should be labeled as Shift + ? instead of just ?, as pressing ? alone triggers the black overlay below the inspect button in the top-left corner.
Image 1 :
In Image 2, The Keyboard Shortcut should also be labeled as Shift + ?.
Image 2 :
When the Quality Assurance tab is open in the Help section, the Keyboard Shortcuts option becomes unclickable. Interestingly, this behavior is not observed with other tabs, which allow seamless access to the keyboard shortcuts.
Image 1 : For example, the Keyboard Shortcuts options is clickable in case of points tab.
Image 2 : When the Quality Assurance tab is open in the Help section, the Keyboard Shortcuts option becomes unclickable.
Checked with latest changes on both local host and online deployment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Help/Keyboard Shortcuts.
I’ve resolved the labeling issue mentioned in the previous comment (Issue 1, Image 2) by replacing
?
withShift + ?
in the relevant file for "Show Keyboard Shortcuts". Should I create a separate issue and raise a PR for this fix, or is it okay to include it as part of this current work?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think spelling it as just “?” is a standard convention, at least on macOS. If you’re using an English keyboard layout, pressing that key alone would be /, not ?. A user-selectable keyboard layout could conceivably have ? as the primary function of a key, or it could require a modifier key other than Shift. All that matters to a Web application like iD is whether the user has pressed the some key combination that would input “?” into a text field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reference undo_redo.js
Line 4 :
if we check by using console.log(uiCmd('⌘Z')); // Outputs either '⌘Z' on Mac or 'Ctrl+Z' on Windows/Linux
and now if we replace that with console.log(uiCmd.display('⌘Z')); // Outputs either '⌘Z' on Mac or '⌘Z' on Windows/Linux
Now, I observed that uiCmd outputs 'CTRL+Z' on German localization or any other regional language, like in case of german it should be STRG+Z when using uiCmd.display but this function shows Outputs either '⌘Z' on Mac or '⌘Z' on Windows/Linux.
It looks like there's some inconsistency with uiCmd.display when handling localization for keyboard shortcuts. While uiCmd correctly adapts to regional differences (e.g., showing "STRG+Z" in German locales) on applying t('shortcuts.key.ctrl') there, uiCmd.display seems to bypass this behavior and hardcodes "⌘Z" for both Mac and Windows/Linux.
I tried to fix this bug using the localization function t(), and it worked with uiCmd but not with uiCmd.display. I'm a bit unsure whether using uiCmd.display for this undo action is a bad idea, or if it's an exception due to hardcoding, or if there's something else I'm missing.
@1ec5 I'm kind of stuck on this, the problem I'm facing is like whether there's need for a smaller fix in the uiCmd function, not sure if its a exceptional case or I should think from a new implementation perspective which can be very challenging for a new contributor like me as I should be reviewing calls to these and deciding which function to be used ( uiCmd or uiCmd.display )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How are you testing Windows or Linux? Are you testing on an actual Windows or Linux machine, spoofing the user agent string, or something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use macOS 15.1.1 to test how things work on Windows and Linux by spoofing the user agent string. When I need to double-check or confirm any issues or assumptions, I rely on a real Windows 10 PC of my friend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Keyboard Shortcuts pane has already been using
uiCmd.display
; is it also showing macOS key names on Windows or Linux?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked throughly, there are no signs of macOS key names on Windows and Linux.
But since, the keyboard shortcuts pane been using uiCmd.display and there's no problems with it,
I see, it could be just a unique case for undo_redo.js because German localization is not happening on this part,
As we can see there's CTRL + Z on Linux System(I used Parallels Desktop to set up Debian OS) on Firefox Browser which should have been STRG + Z.
console.log('Detected OS:', mac ? 'mac' : 'not mac'); // Works Correctly
console.log('Detected OS:', utilDetect().os); // Works Correctly
console.log('Current Language:', detected.language);
console.log('Translated CTRL:', t('shortcuts.key.ctrl')); // Works Correctly
console.log('uiCmd: ⌘Z is', uiCmd('⌘Z')); // Works Correctly except Translation.
console.log('uiCmd.display: ⌘Z is', uiCmd.display('⌘Z')); // not working properly because of code.length issues otherwise would have displayed STRG + Z in German localization.
So I think that this line
if (code.length !== 1) return code;
returns the non-translated value because for ('⌘Z') length is 2 and replacement doesn't take place in uiCmd.display in cmd.jsBut If I change it to like
if (code.length !== 2) return code;
[the stack calls exceed](init.js:501 RangeError: Maximum call stack size exceeded) and crashes the webpage.
It uses the uiCmd Function right now in undo_redo.js, but if I want to localise it using uiCmd.display, For Mac/Windows/Linux, ⌘Z appears.
My LocalHost :