Skip to content

Commit

Permalink
Fix the bug #6421 (#6438)
Browse files Browse the repository at this point in the history
* Update EditAction.java

Fix the bug #6421

* Update CHANGELOG.md
  • Loading branch information
braincident committed May 7, 2020
1 parent a5412b3 commit 834a8f7
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 51 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
105 changes: 54 additions & 51 deletions src/main/java/org/jabref/gui/edit/EditAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
});
}
}

0 comments on commit 834a8f7

Please sign in to comment.