diff --git a/ftl/core/preferences.ftl b/ftl/core/preferences.ftl index 3e6f436b6..e1bb61f33 100644 --- a/ftl/core/preferences.ftl +++ b/ftl/core/preferences.ftl @@ -36,3 +36,5 @@ preferences-user-interface-size = User interface size preferences-when-adding-default-to-current-deck = When adding, default to current deck preferences-you-can-restore-backups-via-fileswitch = You can restore backups via File>Switch Profile. preferences-legacy-timezone-handling = Legacy timezone handling (buggy, but required for AnkiDroid <= 2.14) +preferences-default-search-text = Default search text +preferences-default-search-text-example = eg. 'deck:current ' diff --git a/qt/aqt/browser/browser.py b/qt/aqt/browser/browser.py index 0e2faae5f..f284cf22d 100644 --- a/qt/aqt/browser/browser.py +++ b/qt/aqt/browser/browser.py @@ -333,10 +333,16 @@ class Browser(QMainWindow): self.onSearchActivated() def _default_search(self, card: Optional[Card] = None) -> None: - search = self.col.build_search_string(SearchNode(deck="current")) + default = self.col.get_config_string(Config.String.DEFAULT_SEARCH_TEXT) + if default.strip(): + search = default + prompt = default + else: + search = self.col.build_search_string(SearchNode(deck="current")) + prompt = "" if card is not None: search = gui_hooks.default_search(search, card) - self.search_for(search, "") + self.search_for(search, prompt) def onReset(self) -> None: self.sidebar.refresh() diff --git a/qt/aqt/forms/preferences.ui b/qt/aqt/forms/preferences.ui index 5ebe7bc49..83ee430b8 100644 --- a/qt/aqt/forms/preferences.ui +++ b/qt/aqt/forms/preferences.ui @@ -7,7 +7,7 @@ 0 0 640 - 419 + 480 @@ -114,6 +114,20 @@ + + + + preferences_default_search_text + + + + + + + preferences_default_search_text_example + + + @@ -603,6 +617,7 @@ nightMode useCurrent recording_driver + default_search_text uiScale showEstimates showProgress diff --git a/qt/aqt/preferences.py b/qt/aqt/preferences.py index 347b5d40e..1a41315e7 100644 --- a/qt/aqt/preferences.py +++ b/qt/aqt/preferences.py @@ -82,6 +82,7 @@ class Preferences(QDialog): ) form.paste_strips_formatting.setChecked(editing.paste_strips_formatting) form.pastePNG.setChecked(editing.paste_images_as_png) + form.default_search_text.setText(editing.default_search_text) def update_collection(self) -> None: form = self.form @@ -104,6 +105,7 @@ class Preferences(QDialog): editing.adding_defaults_to_current_deck = not form.useCurrent.currentIndex() editing.paste_images_as_png = self.form.pastePNG.isChecked() editing.paste_strips_formatting = self.form.paste_strips_formatting.isChecked() + editing.default_search_text = self.form.default_search_text.text() self.mw.col.set_preferences(self.prefs) self.mw.apply_collection_options() diff --git a/rslib/backend.proto b/rslib/backend.proto index 2ee556de5..7d72276b4 100644 --- a/rslib/backend.proto +++ b/rslib/backend.proto @@ -1213,6 +1213,7 @@ message Preferences { bool adding_defaults_to_current_deck = 1; bool paste_images_as_png = 2; bool paste_strips_formatting = 3; + string default_search_text = 4; } Scheduling scheduling = 1; @@ -1468,6 +1469,7 @@ message Config { enum Key { SET_DUE_BROWSER = 0; SET_DUE_REVIEWER = 1; + DEFAULT_SEARCH_TEXT = 2; } Key key = 1; } diff --git a/rslib/src/backend/config.rs b/rslib/src/backend/config.rs index 36bef5d95..f28a43d86 100644 --- a/rslib/src/backend/config.rs +++ b/rslib/src/backend/config.rs @@ -42,6 +42,7 @@ impl From for StringKey { match k { StringKeyProto::SetDueBrowser => StringKey::SetDueBrowser, StringKeyProto::SetDueReviewer => StringKey::SetDueReviewer, + StringKeyProto::DefaultSearchText => StringKey::DefaultSearchText, } } } diff --git a/rslib/src/config/string.rs b/rslib/src/config/string.rs index a2dc43016..10da7c206 100644 --- a/rslib/src/config/string.rs +++ b/rslib/src/config/string.rs @@ -10,6 +10,7 @@ use crate::prelude::*; pub enum StringKey { SetDueBrowser, SetDueReviewer, + DefaultSearchText, } impl Collection { @@ -17,7 +18,7 @@ impl Collection { let default = match key { StringKey::SetDueBrowser => "0", StringKey::SetDueReviewer => "1", - // other => "", + _other => "", }; self.get_config_optional(key) .unwrap_or_else(|| default.to_string()) diff --git a/rslib/src/preferences.rs b/rslib/src/preferences.rs index 47e71cfd6..20d4a6b9f 100644 --- a/rslib/src/preferences.rs +++ b/rslib/src/preferences.rs @@ -7,7 +7,7 @@ use crate::{ Preferences, }, collection::Collection, - config::BoolKey, + config::{BoolKey, StringKey}, error::Result, prelude::*, scheduler::timing::local_minutes_west_for_stamp, @@ -131,6 +131,7 @@ impl Collection { .get_config_bool(BoolKey::AddingDefaultsToCurrentDeck), paste_images_as_png: self.get_config_bool(BoolKey::PasteImagesAsPng), paste_strips_formatting: self.get_config_bool(BoolKey::PasteStripsFormatting), + default_search_text: self.get_config_string(StringKey::DefaultSearchText), }) } @@ -142,6 +143,7 @@ impl Collection { )?; self.set_config_bool_inner(BoolKey::PasteImagesAsPng, s.paste_images_as_png)?; self.set_config_bool_inner(BoolKey::PasteStripsFormatting, s.paste_strips_formatting)?; + self.set_config_string_inner(StringKey::DefaultSearchText, &s.default_search_text)?; Ok(()) } }