JabRef / jabref

Graphical Java application for managing BibTeX and biblatex (.bib) databases
https://devdocs.jabref.org
MIT License
3.47k stars 2.44k forks source link

Ctrl+Z (undo) not working any more #11420

Open koppor opened 1 week ago

koppor commented 1 week ago

Originally reported at https://github.com/JabRef/jabref/pull/11282#issuecomment-2177466526

An exception is thrown when trying to use Ctrl+Z on any text field in the entry editor.

2024-06-19 06:13:03 [JavaFX Application Thread] org.jabref.gui.FallbackExceptionHandler.uncaughtException()
ERROR: Uncaught exception occurred in Thread[#54,JavaFX Application Thread,5,main]: java.lang.NullPointerException: Cannot read field "next" because "this.undoChange" is null
    at javafx.controls@22.0.1/javafx.scene.control.TextInputControl.updateUndoRedoState(TextInputControl.java:1250)

A work-around is to disable the key combinations Ctrl+Z and Ctrrl+Y for the field:

        // We need to consume the key event to avoid the default behavior of undo/redo and enable JabRef's undo/redo
        // Source: https://stackoverflow.com/a/37575818/873282
        textInputControl.addEventFilter(KeyEvent.ANY, e -> {
            if (e.getCode() == KeyCode.Z && e.isShortcutDown()) {
                e.consume();
            }
        });

However, the undo/redo should still work. I went through the code a bit, but org.jabref.gui.frame.JabRefFrame.UndoRedoEventManager#updateTexts is "dead" code and I don't know further (yet).

koppor commented 1 week ago

In parallel to a fix, we should create an MWE showing the error inside (!) JavaFX and report a bug.

Siedlerchr commented 1 week ago

I think when previously the field was empty, and you now enter something ctrl + z exception occurs

Now type again and ctrl + z again it works fine

ryan-carpenter commented 1 week ago

I think when previously the field was empty, and you now enter something ctrl + z exception occurs

Now type again and ctrl + z again it works fine

I think when previously the field was empty, and you now enter something ctrl + z exception occurs

Now type again and ctrl + z again it works fine

The exception also occurs when there is text in the field.

koppor commented 1 week ago

I think, it was introduced with our bindings

https://github.com/JabRef/jabref/pull/11282/files#diff-12c8d5c64666483ab38360768d084135c872d59c6798fe13184dfdec888d99eb

As said at https://github.com/JabRef/jabref/pull/11421#issuecomment-2186841645: New reproducer (I started to work on one but did not push 🙈)

LoayGhreeb commented 5 days ago

Using the menu bar (Edit -> Undo) to undo changes works without any exceptions.

Another issue, which may or may not be related, is that when updating a field using the context menu (Clear, Change Case, Normalize) and using Ctrl+Z to undo this change, nothing happens and no exception occurs. I can only undo this change from the menu bar. However, when using "Protect Selection" from the context menu, this change is undoable but with the exception.