Skip to content

Commit

Permalink
Merge pull request #5432 from JabRef/fixCursorJump
Browse files Browse the repository at this point in the history
Fix cursor jump
  • Loading branch information
Siedlerchr committed Oct 12, 2019
2 parents f8bc10b + c655310 commit 08cddc8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We fixed an error where the number of matched entries shown in the group pane was not updated correctly. [#4441](https://github.com/JabRef/jabref/issues/4441)
- We fixed an issue where empty keywords lead to a strange display of automatic keyword groups. [#5333](https://github.com/JabRef/jabref/issues/5333)
- We fixed an error where the default color of a new group was white instead of dark gray. [#4868](https://github.com/JabRef/jabref/issues/4868)
- We fixed an issue where the first field in the entry editor got the focus while performing a different action (like searching). [#5084](https://github.com/JabRef/jabref/issues/5084)
- We fixed an error mentioning "javafx.controls/com.sun.javafx.scene.control" that was thrown when interacting with the toolbar.
- We fixed an error where a cleared search was restored after switching libraries. [#4846](https://github.com/JabRef/jabref/issues/4846)
- We fixed an exception which occurred when trying to open a non-existing file from the "Recent files"-menu [#5334](https://github.com/JabRef/jabref/issues/5334)
Expand Down
30 changes: 1 addition & 29 deletions src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.SortedSet;
import java.util.stream.Stream;

import javax.swing.undo.UndoManager;

import javafx.application.Platform;
import javafx.geometry.VPos;
import javafx.scene.Node;
import javafx.scene.Parent;
Expand Down Expand Up @@ -46,7 +44,6 @@ abstract class FieldsEditorTab extends EntryEditorTab {
private final SuggestionProviders suggestionProviders;
private final DialogService dialogService;
private PreviewPanel previewPanel;
private FieldEditorFX activeField;
private UndoManager undoManager;
private Collection<Field> fields = new ArrayList<>();
private GridPane gridPane;
Expand Down Expand Up @@ -82,19 +79,13 @@ private void setupPanel(BibEntry entry, boolean compressed, SuggestionProviders
fields = determineFieldsToShow(entry);

List<Label> labels = new ArrayList<>();
boolean isFirstField = true;
for (Field field : fields) {
FieldEditorFX fieldEditor = FieldEditors.getForField(field, Globals.TASK_EXECUTOR, dialogService,
Globals.journalAbbreviationLoader.getRepository(Globals.prefs.getJournalAbbreviationPreferences()),
Globals.prefs, databaseContext, entry.getType(), suggestionProviders, undoManager);
fieldEditor.bindToEntry(entry);

editors.put(field, fieldEditor);
if (isFirstField) {
activeField = fieldEditor;
isFirstField = false;
}

labels.add(new FieldNameLabel(field));
}

Expand Down Expand Up @@ -161,8 +152,7 @@ private void setCompressedRowLayout(GridPane gridPane, int rows) {
*/
public void requestFocus(Field fieldName) {
if (editors.containsKey(fieldName)) {
activeField = editors.get(fieldName);
activeField.focus();
editors.get(fieldName).focus();
}
}

Expand All @@ -171,30 +161,12 @@ public boolean shouldShow(BibEntry entry) {
return !determineFieldsToShow(entry).isEmpty();
}

@Override
public void handleFocus() {
if (activeField != null) {
activeField.focus();
}
}

@Override
protected void bindToEntry(BibEntry entry) {
Optional<Field> selectedFieldName = editors.entrySet()
.stream()
.filter(editor -> editor.getValue().childIsFocused())
.map(Map.Entry::getKey)
.findFirst();

initPanel();
setupPanel(entry, isCompressed, suggestionProviders, undoManager);

previewPanel.setEntry(entry);

Platform.runLater(() -> {
// Restore focus to field (run this async so that editor is already initialized correctly)
selectedFieldName.ifPresent(this::requestFocus);
});
}

@Override
Expand Down

0 comments on commit 08cddc8

Please sign in to comment.