Skip to content

Commit 7d6485d

Browse files
harii55subhramit
andauthored
Initialize search bar auto-completion with real database context (no tab switch needed) (#13816)
* Initialize search bar auto-completion with real database context (no tab switch needed) * fix checkstyle * Add CHANGELOG.md entry * fix * Add nullability annotation to autoCompleterChangedListener parameter * Update CHANGELOG.md Co-authored-by: Subhramit Basu <[email protected]> * Remove unused autoCompleterChangedListener field from JabRefFrame --------- Co-authored-by: Subhramit Basu <[email protected]>
1 parent 39ae99e commit 7d6485d

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
126126
- We improved consistency in the Add Buttons. [#13791](https://github.com/JabRef/jabref/pull/13791)
127127
- We fixed an issue where theme or font size are not respected for all dialogs [#13558](https://github.com/JabRef/jabref/issues/13558)
128128
- We removed unnecessary spacing and margin in the AutomaticFieldEditor. [#13792](https://github.com/JabRef/jabref/pull/13792)
129+
- We fixed an issue where global search auto-completion only worked after switching tabs. [#11428](https://github.com/JabRef/jabref/issues/11428)
129130

130131
### Removed
131132

jabgui/src/main/java/org/jabref/gui/LibraryTab.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ public class LibraryTab extends Tab implements CommandSelectionTab {
161161

162162
private final AiService aiService;
163163

164+
private Runnable autoCompleterChangedListener;
165+
164166
/**
165167
* @param isDummyContext Indicates whether the database context is a dummy. A dummy context is used to display a progress indicator while parsing the database.
166168
* If the context is a dummy, the Lucene index should not be created, as both the dummy context and the actual context share the same index path {@link BibDatabaseContext#getFulltextIndexPath()}.
@@ -258,6 +260,10 @@ private void initializeComponentsAndListeners(boolean isDummyContext) {
258260
});
259261
}
260262

263+
public void setAutoCompleterChangedListener(@NonNull Runnable listener) {
264+
this.autoCompleterChangedListener = listener;
265+
}
266+
261267
private static void addChangedInformation(StringBuilder text) {
262268
text.append("\n");
263269
text.append(Localization.lang("The library has been modified."));
@@ -303,7 +309,10 @@ private void onDatabaseLoadingSucceed(ParserResult result) {
303309
}
304310

305311
setDatabaseContext(result.getDatabaseContext());
306-
312+
// Notify listeners that the auto-completer may have changed
313+
if (autoCompleterChangedListener != null) {
314+
autoCompleterChangedListener.run();
315+
}
307316
LOGGER.trace("loading.set(false);");
308317
loading.set(false);
309318
dataLoadingTask = null;

jabgui/src/main/java/org/jabref/gui/frame/JabRefFrame.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,9 @@ private void initBindings() {
403403
stateManager.searchResultSize(SearchType.NORMAL_SEARCH).bind(libraryTab.resultSizeProperty());
404404
globalSearchBar.setAutoCompleter(libraryTab.getAutoCompleter());
405405

406+
// Listen for auto-completer changes after real context is loaded
407+
libraryTab.setAutoCompleterChangedListener(() -> globalSearchBar.setAutoCompleter(libraryTab.getAutoCompleter()));
408+
406409
// [impl->req~maintable.focus~1]
407410
Platform.runLater(() -> libraryTab.getMainTable().requestFocus());
408411

0 commit comments

Comments
 (0)