Fix the working of shortcut keys for linked files#15261
Conversation
Review Summary by QodoFix shortcut keys for linked files in entry editor
WalkthroughsDescription• Fixed shortcut key handling for linked files in entry editor • Added proper key binding mapping for file operations • Implemented keyboard event handlers for rename, open, copy actions • Created new RENAME_FILE_TO_NAME key binding with shortcut+P Diagramflowchart LR
KB["KeyBinding.java<br/>Add RENAME_FILE_TO_NAME"] -->|maps to| SA["StandardActions.java<br/>Fix key binding reference"]
SA -->|used by| LFE["LinkedFilesEditor.java<br/>Implement key event handlers"]
LFE -->|executes| CA["ContextAction<br/>File operations"]
LFE -->|executes| CFA["CopyLinkedFilesAction<br/>Copy files"]
File Changes1. jabgui/src/main/java/org/jabref/gui/keyboard/KeyBinding.java
|
Code Review by Qodo
1. Rename shortcut conflict
|
| LOOKUP_DOC_IDENTIFIER("Search document identifier online", Localization.lang("Search document identifier online"), "alt+F", KeyBindingCategory.EDIT), | ||
| RENAME_FILE_TO_NAME("Rename file(s) to configured filename format pattern", Localization.lang("Rename file(s) to configured filename format pattern"), "shortcut+P", KeyBindingCategory.EDIT); |
There was a problem hiding this comment.
1. Rename shortcut conflict 🐞 Bug ✓ Correctness
The new key binding for renaming linked files defaults to "shortcut+P", which conflicts with the Bash preset mapping "shortcut+P" to EDITOR_UP; due to first-match resolution by enum order, RENAME_FILE_TO_NAME may never be detected. Result: the rename shortcut won’t work for users using that preset (or any configuration with duplicate bindings).
Agent Prompt
### Issue description
`RENAME_FILE_TO_NAME` uses `shortcut+P`, which conflicts with the Bash preset’s `EDITOR_UP`. Because shortcut resolution uses the *first* matching enum constant, the linked-files rename shortcut may never fire.
### Issue Context
`LinkedFilesEditor` currently uses `mapToKeyBinding(event)` (first-match) and then switches on a single resolved binding.
### Fix Focus Areas
- jabgui/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java[268-317]
- jabgui/src/main/java/org/jabref/gui/keyboard/KeyBindingRepository.java[110-136]
- jabgui/src/main/java/org/jabref/gui/preferences/keybindings/presets/BashKeyBindingPreset.java[15-36]
- jabgui/src/main/java/org/jabref/gui/keyboard/KeyBinding.java[128-132]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| case RENAME_FILE_TO_NAME -> { | ||
| LinkedFileViewModel selectedFile = listView.getSelectionModel().getSelectedItem(); | ||
| if (selectedFile != null) { | ||
| new ContextAction(StandardActions.RENAME_FILE_TO_NAME, selectedFile, databaseContext, bibEntry, preferences, viewModel).execute(); | ||
| event.consume(); | ||
| } | ||
| } | ||
| case OPEN_FILE -> { | ||
| LinkedFileViewModel selectedFile = listView.getSelectionModel().getSelectedItem(); | ||
| if (selectedFile != null) { | ||
| new ContextAction(StandardActions.OPEN_FILE, selectedFile, databaseContext, bibEntry, preferences, viewModel).execute(); | ||
| event.consume(); | ||
| } | ||
| } | ||
| case OPEN_FOLDER -> { | ||
| LinkedFileViewModel selectedFile = listView.getSelectionModel().getSelectedItem(); | ||
| if (selectedFile != null) { | ||
| new ContextAction(StandardActions.OPEN_FOLDER, selectedFile, databaseContext, bibEntry, preferences, viewModel).execute(); | ||
| event.consume(); | ||
| } | ||
| } | ||
| case OPEN_CLOSE_ENTRY_EDITOR -> { | ||
| LinkedFileViewModel selectedFile = listView.getSelectionModel().getSelectedItem(); | ||
| if (selectedFile != null) { | ||
| new ContextAction(StandardActions.EDIT_FILE_LINK, selectedFile, databaseContext, bibEntry, preferences, viewModel).execute(); | ||
| event.consume(); | ||
| } | ||
| } | ||
| case COPY -> { | ||
| LinkedFileViewModel selectedFile = listView.getSelectionModel().getSelectedItem(); | ||
| if (selectedFile != null) { | ||
| new CopyLinkedFilesAction(selectedFile.getFile(), dialogService, databaseContext, preferences.getFilePreferences()).execute(); | ||
| event.consume(); | ||
| } |
There was a problem hiding this comment.
2. Executes disabled actions 🐞 Bug ⛯ Reliability
The new linked-files shortcut handler runs ContextAction/CopyLinkedFilesAction without checking executableProperty, so users can trigger actions that are disabled in the context menu (e.g., copy-to-folder on missing/online links), causing confusing dialogs and failures. Keyboard shortcuts should generally respect the same enable/disable conditions as the UI actions they mirror.
Agent Prompt
### Issue description
The linked-files key handler executes commands even when they are not executable (the same commands that would be disabled in the context menu). This can trigger directory choosers and error flows for missing/online links.
### Issue Context
`CopyLinkedFilesAction` and `ContextAction` both compute `executable` preconditions, but `LinkedFilesEditor` calls `execute()` directly on keypress.
### Fix Focus Areas
- jabgui/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java[268-311]
- jabgui/src/main/java/org/jabref/gui/copyfiles/CopyLinkedFilesAction.java[47-71]
- jabgui/src/main/java/org/jabref/gui/fieldeditors/contextmenu/ContextAction.java[43-128]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
This comment has been minimized.
This comment has been minimized.
|
Your pull request conflicts with the target branch. Please merge with your code. For a step-by-step guide to resolve merge conflicts, see https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/addressing-merge-conflicts/resolving-a-merge-conflict-using-the-command-line. |
✅ All tests passed ✅🏷️ Commit: df6082e Learn more about TestLens at testlens.app. |
Co-authored-by: Christoph <siedlerkiller@gmail.com>
Fixes #12564
This PR ensures that the shortcut keys that were not working for the linked files in the entry editor works as expected, they were not being triggered properly.
expected_behavior_linked_files.mov
Checklist
CHANGELOG.mdin a way that can be understood by the average user (if change is visible to the user)