Skip to content

Commit

Permalink
Fix saving in codeArea without leaving the field
Browse files Browse the repository at this point in the history
Refactor  globals

fixes #6622
  • Loading branch information
Siedlerchr committed Nov 22, 2020
1 parent b0af521 commit 6c3bff8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 17 additions & 4 deletions src/main/java/org/jabref/gui/entryeditor/SourceTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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();
Expand All @@ -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());
}
});
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 -> {
Expand Down

0 comments on commit 6c3bff8

Please sign in to comment.