From 6c3bff883d41db67b3722d6d93e23f6036c01d64 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sun, 22 Nov 2020 19:06:34 +0100 Subject: [PATCH] Fix saving in codeArea without leaving the field Refactor globals fixes #6622 --- CHANGELOG.md | 1 + .../org/jabref/gui/entryeditor/SourceTab.java | 21 +++++++++++++++---- .../gui/keyboard/CodeAreaKeyBindings.java | 4 +--- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 355e11dfa0c..38c9e5bd2dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -73,6 +73,7 @@ inserting new citations in a OpenOffic/LibreOffice document. [#6957](https://git - We fixed an issue where errors from imports were not shown to the user [#7084](https://github.com/JabRef/jabref/pull/7084) - We fixed an issue where the EndNote XML Import would fail on empty keywords tags [forum#2387](https://discourse.jabref.org/t/importing-in-unknown-format-fails-to-import-xml-library-from-bookends-export/2387) - We fixed an issue where the color of groups of type "free search expression" not persisting after restarting the application [#6999](https://github.com/JabRef/jabref/issues/6999) +- We fixed an issue where modifications in the source tab where not saved without switching to another field before saving the library [#6622](https://github.com/JabRef/jabref/issues/6622) ### Removed diff --git a/src/main/java/org/jabref/gui/entryeditor/SourceTab.java b/src/main/java/org/jabref/gui/entryeditor/SourceTab.java index 9161758a58d..94f04a3f236 100644 --- a/src/main/java/org/jabref/gui/entryeditor/SourceTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/SourceTab.java @@ -116,7 +116,7 @@ public SourceTab(BibDatabaseContext bibDatabaseContext, CountingUndoManager undo } private void highlightSearchPattern() { - if (searchHighlightPattern.isPresent() && codeArea != null) { + if (searchHighlightPattern.isPresent() && (codeArea != null)) { codeArea.setStyleClass(0, codeArea.getLength(), "text"); Matcher matcher = searchHighlightPattern.get().matcher(codeArea.getText()); while (matcher.find()) { @@ -172,7 +172,8 @@ private void setupSourceEditor() { } }); codeArea.setId("bibtexSourceCodeArea"); - codeArea.addEventFilter(KeyEvent.KEY_PRESSED, event -> CodeAreaKeyBindings.call(codeArea, event)); + codeArea.addEventFilter(KeyEvent.KEY_PRESSED, event -> CodeAreaKeyBindings.call(codeArea, event, keyBindingRepository)); + codeArea.addEventFilter(KeyEvent.KEY_PRESSED, this::listenForSaveKeybinding ); ActionFactory factory = new ActionFactory(keyBindingRepository); ContextMenu contextMenu = new ContextMenu(); @@ -197,7 +198,7 @@ private void setupSourceEditor() { }); codeArea.focusedProperty().addListener((obs, oldValue, onFocus) -> { - if (!onFocus && currentEntry != null) { + if (!onFocus && (currentEntry != null)) { storeSource(currentEntry, codeArea.textProperty().getValue()); } }); @@ -232,7 +233,7 @@ private void updateCodeArea() { @Override protected void bindToEntry(BibEntry entry) { - if (previousEntry != null && codeArea != null) { + if ((previousEntry != null) && (codeArea != null)) { storeSource(previousEntry, codeArea.textProperty().getValue()); } this.previousEntry = entry; @@ -321,4 +322,16 @@ private void storeSource(BibEntry outOfFocusEntry, String text) { LOGGER.debug("Incorrect source", ex); } } + + private void listenForSaveKeybinding(KeyEvent event) { + keyBindingRepository.mapToKeyBinding(event).ifPresent(binding -> { + + switch (binding) { + case SAVE_DATABASE, SAVE_ALL, SAVE_DATABASE_AS -> { + storeSource(currentEntry, codeArea.textProperty().getValue()); + } + } + }); + } + } diff --git a/src/main/java/org/jabref/gui/keyboard/CodeAreaKeyBindings.java b/src/main/java/org/jabref/gui/keyboard/CodeAreaKeyBindings.java index d055eaed84c..8c199b02c97 100644 --- a/src/main/java/org/jabref/gui/keyboard/CodeAreaKeyBindings.java +++ b/src/main/java/org/jabref/gui/keyboard/CodeAreaKeyBindings.java @@ -2,7 +2,6 @@ import javafx.scene.input.KeyEvent; -import org.jabref.gui.Globals; import org.jabref.logic.util.strings.StringManipulator; import org.jabref.model.util.ResultingStringState; @@ -11,8 +10,7 @@ public class CodeAreaKeyBindings { - public static void call(CodeArea codeArea, KeyEvent event) { - KeyBindingRepository keyBindingRepository = Globals.getKeyPrefs(); + public static void call(CodeArea codeArea, KeyEvent event, KeyBindingRepository keyBindingRepository) { keyBindingRepository.mapToKeyBinding(event).ifPresent(binding -> { switch (binding) { case EDITOR_DELETE -> {