fix(keyboard): use key codes for undo/redo to support all keyboard la… #980
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.
Keyboard Layout Support Fix for Undo/Redo Operations
Related Issue
Closes #928
Overview
This fix addresses the issue where undo/redo keyboard shortcuts (Ctrl+Z/Ctrl+Y) were not working correctly on non-English keyboard layouts, particularly German layouts where the Z and Y keys are swapped.
Problem
The original implementation used
event.key
to detect keyboard shortcuts, which depends on the keyboard layout:Ctrl+Z
= undo,Ctrl+Y
= redoCtrl+Y
(German Y key) = undo,Ctrl+Z
(German Z key) = redoThis caused confusion and inconsistent behavior across different keyboard layouts.
Solution
Implemented a universal solution using
event.code
instead ofevent.key
:KeyZ
code always represents the Z key position (regardless of layout)KeyY
code always represents the Y key position (regardless of layout)This ensures consistent behavior across all keyboard layouts.
Changes Made
1. Updated
lib/features/keyboard/KeyboardUtil.js
Added
KEY_CODES
constant for key codes:Modified
isUndo()
function to support both key letters and key codes:Modified
isRedo()
function to support both key letters and key codes:2. Updated
lib/features/keyboard/KeyboardBindings.js
KEY_CODES
to exports3. Updated Tests
test/spec/features/keyboard/UndoSpec.js
KeyZ
code supporttest/spec/features/keyboard/RedoSpec.js
KeyY
andKeyZ
code supportBenefits
Testing
All tests pass successfully:
Technical Details
event.code
for layout-independent key detectionevent.key
support for backward compatibilityisKey()
utility functionFiles Modified
lib/features/keyboard/KeyboardUtil.js
lib/features/keyboard/KeyboardBindings.js
test/spec/features/keyboard/UndoSpec.js
test/spec/features/keyboard/RedoSpec.js
Commit Message