Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the bug #6421 #6438

Merged
merged 2 commits into from
May 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
});
}
}