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 cursor jump #5432

Merged
merged 1 commit into from
Oct 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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