From 834a8f71b3fe9df989846e1913b67d39f77ee3dc Mon Sep 17 00:00:00 2001 From: CAI Zhichun <54977532+braincident@users.noreply.github.com> Date: Thu, 7 May 2020 18:41:48 +0800 Subject: [PATCH] Fix the bug #6421 (#6438) * Update EditAction.java Fix the bug #6421 * Update CHANGELOG.md --- CHANGELOG.md | 1 + .../java/org/jabref/gui/edit/EditAction.java | 105 +++++++++--------- 2 files changed, 55 insertions(+), 51 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5f4e34895c..762f841e60d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We now show the number of items found and selected to import in the online search dialog. [#6248](https://github.com/JabRef/jabref/pull/6248) - We created a new install screen for macOS. [#5759](https://github.com/JabRef/jabref/issues/5759) - We implemented an option to download fulltext files while importing. [#6381](https://github.com/JabRef/jabref/pull/6381) +- We fixed the bug when strike the delete key in the text field. [#6421](https://github.com/JabRef/jabref/issues/6421) ### Changed diff --git a/src/main/java/org/jabref/gui/edit/EditAction.java b/src/main/java/org/jabref/gui/edit/EditAction.java index 36794f64ab7..1b40c0d621e 100644 --- a/src/main/java/org/jabref/gui/edit/EditAction.java +++ b/src/main/java/org/jabref/gui/edit/EditAction.java @@ -14,63 +14,66 @@ */ public class EditAction extends SimpleCommand { - private final JabRefFrame frame; - private final StandardActions action; - private final StateManager stateManager; + private final JabRefFrame frame; + private final StandardActions action; + private final StateManager stateManager; - public EditAction(StandardActions action, JabRefFrame frame, StateManager stateManager) { - this.action = action; - this.frame = frame; - this.stateManager = stateManager; + public EditAction(StandardActions action, JabRefFrame frame, StateManager stateManager) { + this.action = action; + this.frame = frame; + this.stateManager = stateManager; - this.executable.bind(ActionHelper.needsEntriesSelected(stateManager)); - } + this.executable.bind(ActionHelper.needsEntriesSelected(stateManager)); + } - @Override - public String toString() { - return this.action.toString(); - } + @Override + public String toString() { + return this.action.toString(); + } - @Override - public void execute() { - stateManager.getFocusOwner().ifPresent(focusOwner -> { - if (focusOwner instanceof TextInputControl) { - // Focus is on text field -> copy/paste/cut selected text - TextInputControl textInput = (TextInputControl) focusOwner; - switch (action) { - case COPY: - textInput.copy(); - break; - case CUT: - textInput.cut(); - break; - case PASTE: - // handled by FX in TextInputControl#paste - break; - default: - throw new IllegalStateException("Only cut/copy/paste supported in TextInputControl but got " + action); - } - } else { - // Not sure what is selected -> copy/paste/cut selected entries + @Override + public void execute() { + stateManager.getFocusOwner().ifPresent(focusOwner -> { + if (focusOwner instanceof TextInputControl) { + // Focus is on text field -> copy/paste/cut selected text + TextInputControl textInput = (TextInputControl) focusOwner; + switch (action) { + case COPY: + textInput.copy(); + break; + case CUT: + textInput.cut(); + break; + case PASTE: + // handled by FX in TextInputControl#paste + break; + case DELETE_ENTRY: + // DELETE_ENTRY in text field should do forward delete + textInput.deleteNextChar(); + default: + throw new IllegalStateException("Only cut/copy/paste supported in TextInputControl but got " + action); + } + } else { + // Not sure what is selected -> copy/paste/cut selected entries - // ToDo: Should be handled by BibDatabaseContext instead of BasePanel - switch (action) { - case COPY: - frame.getCurrentBasePanel().copy(); - break; - case CUT: - frame.getCurrentBasePanel().cut(); - break; - case PASTE: - frame.getCurrentBasePanel().paste(); - break; - case DELETE_ENTRY: - frame.getCurrentBasePanel().delete(false); - break; - default: - throw new IllegalStateException("Only cut/copy/paste supported but got " + action); - } + // ToDo: Should be handled by BibDatabaseContext instead of BasePanel + switch (action) { + case COPY: + frame.getCurrentBasePanel().copy(); + break; + case CUT: + frame.getCurrentBasePanel().cut(); + break; + case PASTE: + frame.getCurrentBasePanel().paste(); + break; + case DELETE_ENTRY: + frame.getCurrentBasePanel().delete(false); + break; + default: + throw new IllegalStateException("Only cut/copy/paste supported but got " + action); } + } }); } }