Skip to content
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: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv

### Fixed

- We fixed an issue where pressing <kbd>Tab</kbd> in the last text field of a tab did not move the focus to the next tab in the entry editor. [#11937](https://github.com/JabRef/jabref/issues/11937)
- We fixed an issue where "Specify Bib(La)TeX" tab was not focused when Bib(La)TeX was in the clipboard [#13597](https://github.com/JabRef/jabref/issues/13597)
- We fixed an issue whereby the 'About' dialog was not honouring the user's configured font preferences. [#13558](https://github.com/JabRef/jabref/issues/13558)
- We fixed an issue where the Pagetotal column was sorting the values alphabetically instead of numerically. [#12533](https://github.com/JabRef/jabref/issues/12533)
Expand Down
105 changes: 0 additions & 105 deletions jabgui/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.File;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
Expand All @@ -19,16 +18,12 @@
import javafx.beans.InvalidationListener;
import javafx.fxml.FXML;
import javafx.geometry.Side;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.control.Button;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.Label;
import javafx.scene.control.MenuItem;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.control.TextField;
import javafx.scene.control.TextInputControl;
import javafx.scene.input.DataFormat;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.TransferMode;
Expand All @@ -43,7 +38,6 @@
import org.jabref.gui.entryeditor.fileannotationtab.FileAnnotationTab;
import org.jabref.gui.entryeditor.fileannotationtab.FulltextSearchResultsTab;
import org.jabref.gui.externalfiles.ExternalFilesEntryLinker;
import org.jabref.gui.fieldeditors.EditorTextField;
import org.jabref.gui.help.HelpAction;
import org.jabref.gui.importer.GrobidUseDialogHelper;
import org.jabref.gui.keyboard.KeyBinding;
Expand Down Expand Up @@ -169,11 +163,6 @@ public EntryEditor(Supplier<LibraryTab> tabSupplier, UndoAction undoAction, Redo

setupDragAndDrop();

EditorTextField.setupTabNavigation(
this::isLastFieldInCurrentTab,
this::moveToNextTabAndFocus
);

EasyBind.subscribe(tabbed.getSelectionModel().selectedItemProperty(), tab -> {
EntryEditorTab activeTab = (EntryEditorTab) tab;
if (activeTab != null) {
Expand Down Expand Up @@ -539,98 +528,4 @@ public void nextPreviewStyle() {
public void previousPreviewStyle() {
this.previewPanel.previousPreviewStyle();
}

/**
* Checks if the given TextField is the last field in the currently selected tab.
*
* @param textField the TextField to check
* @return true if this is the last field in the current tab, false otherwise
*/
private boolean isLastFieldInCurrentTab(TextField textField) {
if (textField == null || tabbed.getSelectionModel().getSelectedItem() == null) {
return false;
}

Tab selectedTab = tabbed.getSelectionModel().getSelectedItem();
if (!(selectedTab instanceof FieldsEditorTab currentTab)) {
return false;
}

Collection<Field> shownFields = currentTab.getShownFields();
if (shownFields.isEmpty() || textField.getId() == null) {
return false;
}

Optional<Field> lastField = shownFields.stream()
.reduce((first, second) -> second);

return lastField.map(Field::getDisplayName)
.map(displayName -> displayName.equalsIgnoreCase(textField.getId()))
.orElse(false);
}

/**
* Moves to the next tab and focuses on its first field.
*/
private void moveToNextTabAndFocus() {
tabbed.getSelectionModel().selectNext();

UiTaskExecutor.runInJavaFXThread(() -> {
Tab selectedTab = tabbed.getSelectionModel().getSelectedItem();
if (selectedTab instanceof FieldsEditorTab currentTab) {
focusFirstFieldInTab(currentTab);
}
});
}

private void focusFirstFieldInTab(FieldsEditorTab tab) {
Node tabContent = tab.getContent();
if (tabContent instanceof Parent parent) {
// First try to find field by ID (preferred method)
Collection<Field> shownFields = tab.getShownFields();
if (!shownFields.isEmpty()) {
Field firstField = shownFields.iterator().next();
String firstFieldId = firstField.getDisplayName();
Optional<TextInputControl> firstTextInput = findTextInputById(parent, firstFieldId);
if (firstTextInput.isPresent()) {
firstTextInput.get().requestFocus();
return;
}
}

Optional<TextInputControl> anyTextInput = findAnyTextInput(parent);
if (anyTextInput.isPresent()) {
anyTextInput.get().requestFocus();
}
}
}

/// Recursively searches for a TextInputControl (TextField or TextArea) with the given ID.
private Optional<TextInputControl> findTextInputById(Parent parent, String id) {
for (Node child : parent.getChildrenUnmodifiable()) {
if (child instanceof TextInputControl textInput && id.equalsIgnoreCase(textInput.getId())) {
return Optional.of(textInput);
} else if (child instanceof Parent childParent) {
Optional<TextInputControl> found = findTextInputById(childParent, id);
if (found.isPresent()) {
return found;
}
}
}
return Optional.empty();
}

private Optional<TextInputControl> findAnyTextInput(Parent parent) {
for (Node child : parent.getChildrenUnmodifiable()) {
if (child instanceof TextInputControl textInput) {
return Optional.of(textInput);
} else if (child instanceof Parent childParent) {
Optional<TextInputControl> found = findAnyTextInput(childParent);
if (found.isPresent()) {
return found;
}
}
}
return Optional.empty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ public CitationKeyEditor(Field field,
undoManager,
dialogService);

textField.setId(field.getDisplayName());

establishBinding(textField, viewModel.textProperty(), keyBindingRepository, undoAction, redoAction);
textField.initContextMenu(Collections::emptyList, keyBindingRepository);
new EditorValidator(preferences).configureValidation(viewModel.getFieldValidator().getValidationStatus(), textField);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@
import java.util.List;
import java.util.Objects;
import java.util.ResourceBundle;
import java.util.function.Predicate;
import java.util.function.Supplier;

import javafx.fxml.Initializable;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;

Expand All @@ -22,26 +19,13 @@

public class EditorTextField extends TextField implements Initializable, ContextMenuAddable {

private static Runnable nextTabSelector;
private static Predicate<TextField> isLastFieldChecker;
private final ContextMenu contextMenu = new ContextMenu();

private Runnable additionalPasteActionHandler = () -> {
// No additional paste behavior
};

public EditorTextField() {
this("");
this.addEventFilter(KeyEvent.KEY_PRESSED, event -> {
if (event.getCode() == KeyCode.TAB &&
isLastFieldChecker != null &&
isLastFieldChecker.test(this)) {
if (nextTabSelector != null) {
nextTabSelector.run();
}
event.consume();
}
});
}

public EditorTextField(final String text) {
Expand All @@ -54,11 +38,6 @@ public EditorTextField(final String text) {
ClipBoardManager.addX11Support(this);
}

public static void setupTabNavigation(Predicate<TextField> isLastFieldChecker, Runnable nextTabSelector) {
EditorTextField.isLastFieldChecker = isLastFieldChecker;
EditorTextField.nextTabSelector = nextTabSelector;
}

@Override
public void initContextMenu(final Supplier<List<MenuItem>> items, KeyBindingRepository keyBindingRepository) {
setOnContextMenuRequested(event -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public MarkdownEditor(Field field, SuggestionProvider<?> suggestionProvider, Fie
}

@Override
protected TextInputControl createTextInputControl(Field field) {
protected TextInputControl createTextInputControl() {
return new EditorTextArea() {
@Override
public void paste() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public PersonsEditor(final Field field,

this.viewModel = new PersonsEditorViewModel(field, suggestionProvider, preferences.getAutoCompletePreferences(), fieldCheckers, undoManager);
textInput = isMultiLine ? new EditorTextArea() : new EditorTextField();
textInput.setId(field.getName());
decoratedStringProperty = new UiThreadStringProperty(viewModel.textProperty());
establishBinding(textInput, decoratedStringProperty, keyBindingRepository, undoAction, redoAction);
((ContextMenuAddable) textInput).initContextMenu(EditorMenus.getNameMenu(textInput), keyBindingRepository);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public SimpleEditor(final Field field,
this.viewModel = new SimpleEditorViewModel(field, suggestionProvider, fieldCheckers, undoManager);
this.isMultiLine = isMultiLine;

textInput = createTextInputControl(field);
textInput = createTextInputControl();
HBox.setHgrow(textInput, Priority.ALWAYS);

establishBinding(textInput, viewModel.textProperty(), preferences.getKeyBindingRepository(), undoAction, redoAction);
Expand All @@ -54,10 +54,8 @@ public SimpleEditor(final Field field,
new EditorValidator(preferences).configureValidation(viewModel.getFieldValidator().getValidationStatus(), textInput);
}

protected TextInputControl createTextInputControl(Field field) {
TextInputControl inputControl = isMultiLine ? new EditorTextArea() : new EditorTextField();
inputControl.setId(field.getName());
return inputControl;
protected TextInputControl createTextInputControl() {
return isMultiLine ? new EditorTextArea() : new EditorTextField();
}

@Override
Expand Down
Loading