Fix macOS cursor shortcuts in BibTeX source editor (#5937)#15358
Conversation
|
Hey @AnvitaPrasad! 👋 Thank you for contributing to JabRef! We have automated checks in place, based on which you will soon get feedback if any of them are failing. We also use Qodo for review assistance. It will update your pull request description with a review help and offer suggestions to improve the pull request. After all automated checks pass, a maintainer will also review your contribution. Once that happens, you can go through their comments in the "Files changed" tab and act on them, or reply to the conversation if you have further inputs. You can read about the whole pull request process in our contribution guide. Please ensure that your pull request is in line with our AI Usage Policy and make necessary disclosures. |
Review Summary by QodoFix macOS cursor shortcuts in BibTeX source editor
WalkthroughsDescription• Fixes macOS Command+Left/Right cursor navigation in BibTeX source editor • Implements proper line start/end movement matching native macOS behavior • Adds Option+Left/Right word navigation support for consistency • Detects macOS platform and handles cursor shortcuts separately Diagramflowchart LR
A["KeyEvent in CodeArea"] --> B["Check if macOS"]
B -->|Yes| C["Handle Cursor Shortcuts"]
B -->|No| D["Use Default Bindings"]
C --> E["Command+Left/Right<br/>Line Start/End"]
C --> F["Option+Left/Right<br/>Word Navigation"]
E --> G["Consume Event"]
F --> G
D --> H["Process via<br/>KeyBindingRepository"]
File Changes1. jabgui/src/main/java/org/jabref/gui/keyboard/CodeAreaKeyBindings.java
|
Code Review by Qodo
1. Back shortcut blocked
|
There was a problem hiding this comment.
Pull request overview
Fixes macOS-specific cursor navigation in the BibTeX source editor (CodeArea) so standard macOS shortcuts behave as expected (Cmd+Left/Right to line start/end, Opt+Left/Right to word boundaries).
Changes:
- Added a macOS-only key handling path for Left/Right arrow keys with Cmd/Opt (and Shift selection extension).
- Consumes handled key events before they reach the keybinding repository / default handlers.
You can also share your feedback on Copilot code review. Take the survey.
| import javafx.scene.input.KeyEvent; | ||
| import javafx.scene.input.KeyCode; |
| public static void call(CodeArea codeArea, KeyEvent event, KeyBindingRepository keyBindingRepository) { | ||
| if (handleMacCursorMovementShortcuts(codeArea, event)) { | ||
| return; | ||
| } |
This comment has been minimized.
This comment has been minimized.
|
Command left/right works for me, but option left/right which should move the caret to the word, doesn't work for me here on macOS Sequoia 15.7.3 (Macbook pro) but that option doesn't work in text fields either (seems to also not work on main) |
k3KAW8Pnf7mkmdSMPHz27
left a comment
There was a problem hiding this comment.
Tested and working on macOS 26.3. A few suggestions below.
| public class CodeAreaKeyBindings { | ||
|
|
||
| public static void call(CodeArea codeArea, KeyEvent event, KeyBindingRepository keyBindingRepository) { | ||
| if (handleMacCursorMovementShortcuts(codeArea, event)) { |
There was a problem hiding this comment.
The method both calls event.consume() and returns true, which are two signals for the same thing. Since event.consume() is required regardless to stop JavaFX event propagation, the boolean return is redundant. If they ever diverge (e.g. calling consume() but forgetting return true), you have a bug. Consider changing to void and checking event.isConsumed() instead as a single source of truth.
|
|
||
| KeyCode code = event.getCode(); | ||
| if ((code != KeyCode.LEFT) && (code != KeyCode.RIGHT)) { | ||
| return false; |
There was a problem hiding this comment.
Suggestion, possibly outside the scope of this PR: Per Apple's keyboard shortcuts, standard macOS text editing also includes:
- Command+Up/Down for document start/end
- Option+Up/Down for paragraph start/end
- Shift variants for selection
All needed CodeArea methods exist (start(policy), end(policy), paragraphStart(policy), paragraphEnd(policy)).
|
|
||
| boolean optionOnly = event.isAltDown() && !event.isMetaDown() && !event.isControlDown(); | ||
| boolean commandOnly = event.isMetaDown() && !event.isAltDown() && !event.isControlDown(); | ||
|
|
There was a problem hiding this comment.
Nice touch. The named booleans optionOnly and commandOnly document the macOS intent clearly and make the modifier checks readable without needing comments.
This comment has been minimized.
This comment has been minimized.
b9055c7 to
2b5302f
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
- Fix ternary operator indentation in CodeAreaKeyBindings to match JabRef code style (aligns ? and : with the start of the condition value) - Add CodeAreaKeyBindingsTest with 8 unit tests covering all macOS cursor shortcut cases (Cmd+Left/Right, Option+Left/Right, Shift variants, non-Mac, non-arrow key) - Add CHANGELOG entry for the macOS cursor shortcuts fix Closes JabRef#5937 Made-with: Cursor
- Remove duplicate JabRef#5937 CHANGELOG entry (keep single descriptive entry) - Add Ctrl+Left/Right as word navigation shortcut (in addition to Option+Left/Right) for users who have macOS Mission Control shortcuts disabled - Add tests for Ctrl+Left/Right word navigation behavior Made-with: Cursor
This comment has been minimized.
This comment has been minimized.
e3178a2 to
a974ecd
Compare
This comment has been minimized.
This comment has been minimized.
|
@k3KAW8Pnf7mkmdSMPHz27 @Siedlerchr |
|
Ah great that makes my PR then obsolte! |
Made-with: Cursor
✅ All tests passed ✅🏷️ Commit: 90b00af Learn more about TestLens at testlens.app. |
|
The only thing that doesn't yet work in the CodeArea is paragraph up/down using Option + up/down as @k3KAW8Pnf7mkmdSMPHz27 mentioned, the rest works fine and also fixes the normal text input fields! |
|
@Siedlerchr Sorry for the overlap with your PR 😅. About the Option + Up/Down. I wasn’t sure if that should be in scope for this PR since #5937 was mainly about left/right navigation.Should I add it here or open a small follow up PR for that? |
|
No worries, your solution is more elegant :) |
…Ref#15358) * Refine macOS source-editor cursor shortcuts * fix formatting * Address review feedback: fix formatting, add tests, update changelog - Fix ternary operator indentation in CodeAreaKeyBindings to match JabRef code style (aligns ? and : with the start of the condition value) - Add CodeAreaKeyBindingsTest with 8 unit tests covering all macOS cursor shortcut cases (Cmd+Left/Right, Option+Left/Right, Shift variants, non-Mac, non-arrow key) - Add CHANGELOG entry for the macOS cursor shortcuts fix Closes JabRef#5937 Made-with: Cursor * Remove duplicate changelog entry, add Ctrl+Left/Right word navigation - Remove duplicate JabRef#5937 CHANGELOG entry (keep single descriptive entry) - Add Ctrl+Left/Right as word navigation shortcut (in addition to Option+Left/Right) for users who have macOS Mission Control shortcuts disabled - Add tests for Ctrl+Left/Right word navigation behavior Made-with: Cursor * Fix Option+Left/Right in source editor by allowing it past BACK/FORWARD Made-with: Cursor * fix import order for checkstyle Made-with: Cursor
Related issues and pull requests
Closes #5937
PR Description
This PR fixes macOS cursor navigation behavior in the BibTeX source editor so it matches standard macOS text editing. Command+Left/Right now moves to line start/end in that editor as expected. This makes editing BibTeX source on macOS consistent with other text fields and with native app behavior.
Steps to test
.biblibrary.mainbranch to confirm the fix.Before
Screen.Recording.2026-03-18.at.12.06.52.AM.mov
After
Screen.Recording.2026-03-18.at.12.12.33.AM.mov
Checklist
CHANGELOG.mdin a way that can be understood by the average user (if change is visible to the user)