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 undo (CTRL + Z) and redo for inserting an entry #9777

Merged
merged 9 commits into from
May 7, 2023
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed the log text color in the event log console when using dark mode. [#9732](https://github.com/JabRef/jabref/issues/9732)
- We fixed an issue where searching for unlinked files would include the current library's .bib file [#9735](https://github.com/JabRef/jabref/issues/9735)
- We fixed an issue where it was no longer possible to connect to a shared mysql database due to an exception [#9761](https://github.com/JabRef/jabref/issues/9761)
- We fixed an issue where an exception was thrown for the user after <kbd>Ctrl</kbd>+<kbd>Z</kbd> command [#9737](https://github.com/JabRef/jabref/issues/9737)
- We fixed the citation key generation for (`[authors]`, `[authshort]`, `[authorsAlpha]`, `authIniN`, `authEtAl`, `auth.etal`)[https://docs.jabref.org/setup/citationkeypatterns#special-field-markers] to handle `and others` properly. [koppor#626](https://github.com/koppor/jabref/issues/626)

### Removed
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/org/jabref/gui/edit/EditAction.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jabref.gui.edit;

import javafx.scene.control.TextField;
import javafx.scene.control.TextInputControl;
import javafx.scene.web.WebView;

Expand All @@ -23,7 +22,6 @@ public class EditAction extends SimpleCommand {
private static final Logger LOGGER = LoggerFactory.getLogger(EditAction.class);

private final JabRefFrame frame;
private TextField text;
private final StandardActions action;
private final StateManager stateManager;

Expand All @@ -47,7 +45,8 @@ public String toString() {
@Override
public void execute() {
stateManager.getFocusOwner().ifPresent(focusOwner -> {
LOGGER.debug("focusOwner: {}; Action: {}", focusOwner.toString(), action.getText());
LOGGER.debug("focusOwner: {}; Action: {}", focusOwner, action.getText());

if (focusOwner instanceof TextInputControl) {
// Focus is on text field -> copy/paste/cut selected text
TextInputControl textInput = (TextInputControl) focusOwner;
Expand Down Expand Up @@ -75,7 +74,10 @@ public void execute() {
case CUT -> frame.getCurrentLibraryTab().cut();
case PASTE -> frame.getCurrentLibraryTab().paste();
case DELETE_ENTRY -> frame.getCurrentLibraryTab().delete(false);
default -> throw new IllegalStateException("Only cut/copy/paste supported but got " + action);
case REDO -> frame.getUndoManager().redo();
case UNDO -> frame.getUndoManager().undo();
default -> LOGGER.debug("Only cut/copy/paste supported but got: {} and focus owner {}", action, focusOwner);
// default -> throw new IllegalStateException("Only cut/copy/paste supported but got " + action);
Siedlerchr marked this conversation as resolved.
Show resolved Hide resolved
}
}
});
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/org/jabref/gui/search/GlobalSearchBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,16 @@ public class GlobalSearchBar extends HBox {
private final BooleanProperty globalSearchActive = new SimpleBooleanProperty(false);
private GlobalSearchResultDialog globalSearchResultDialog;

private final JabRefFrame frame;

public GlobalSearchBar(JabRefFrame frame, StateManager stateManager, PreferencesService preferencesService, CountingUndoManager undoManager, DialogService dialogService) {
super();
this.stateManager = stateManager;
this.preferencesService = preferencesService;
this.searchPreferences = preferencesService.getSearchPreferences();
this.undoManager = undoManager;
this.dialogService = dialogService;
this.frame = frame;

searchField.disableProperty().bind(needsDatabase(stateManager).not());

Expand Down Expand Up @@ -143,14 +146,16 @@ public GlobalSearchBar(JabRefFrame frame, StateManager stateManager, Preferences
searchField.setContextMenu(SearchFieldRightClickMenu.create(
keyBindingRepository,
stateManager,
searchField));
searchField,
frame));

ObservableList<String> search = stateManager.getWholeSearchHistory();
search.addListener((ListChangeListener.Change<? extends String> change) -> {
searchField.setContextMenu(SearchFieldRightClickMenu.create(
keyBindingRepository,
stateManager,
searchField));
searchField,
frame));
});

ClipBoardManager.addX11Support(searchField);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import javafx.scene.control.MenuItem;
import javafx.scene.control.SeparatorMenuItem;

import org.jabref.gui.JabRefFrame;
import org.jabref.gui.StateManager;
import org.jabref.gui.actions.ActionFactory;
import org.jabref.gui.actions.SimpleCommand;
Expand All @@ -18,17 +19,18 @@
public class SearchFieldRightClickMenu {
public static ContextMenu create(KeyBindingRepository keyBindingRepository,
StateManager stateManager,
CustomTextField searchField) {
CustomTextField searchField,
JabRefFrame frame) {
ActionFactory factory = new ActionFactory(keyBindingRepository);
ContextMenu contextMenu = new ContextMenu();

contextMenu.getItems().addAll(
factory.createMenuItem(StandardActions.UNDO, new EditAction(StandardActions.UNDO, null, stateManager)),
factory.createMenuItem(StandardActions.REDO, new EditAction(StandardActions.REDO, null, stateManager)),
factory.createMenuItem(StandardActions.CUT, new EditAction(StandardActions.CUT, null, stateManager)),
factory.createMenuItem(StandardActions.COPY, new EditAction(StandardActions.COPY, null, stateManager)),
factory.createMenuItem(StandardActions.PASTE, new EditAction(StandardActions.PASTE, null, stateManager)),
factory.createMenuItem(StandardActions.DELETE, new EditAction(StandardActions.DELETE, null, stateManager)),
factory.createMenuItem(StandardActions.UNDO, new EditAction(StandardActions.UNDO, frame, stateManager)),
factory.createMenuItem(StandardActions.REDO, new EditAction(StandardActions.REDO, frame, stateManager)),
factory.createMenuItem(StandardActions.CUT, new EditAction(StandardActions.CUT, frame, stateManager)),
factory.createMenuItem(StandardActions.COPY, new EditAction(StandardActions.COPY, frame, stateManager)),
factory.createMenuItem(StandardActions.PASTE, new EditAction(StandardActions.PASTE, frame, stateManager)),
factory.createMenuItem(StandardActions.DELETE, new EditAction(StandardActions.DELETE, frame, stateManager)),

new SeparatorMenuItem(),

Expand Down