Always use substring search in the Languages completer

See #2130804 (Unable to set Greek as the language of a new book)
This commit is contained in:
Kovid Goyal 2025-11-06 22:44:34 +05:30
parent 29ae85d118
commit 9f1d6619a7
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 6 additions and 1 deletions

View File

@ -51,6 +51,7 @@ class CompleteModel(QAbstractListModel): # {{{
self.sort_func = sort_func
self.all_items = self.current_items = ()
self.current_prefix = ''
self.use_startswith_search = tweaks['completion_mode'] == 'prefix'
def set_items(self, items):
if self.strip_completion_entries:
@ -75,7 +76,7 @@ class CompleteModel(QAbstractListModel): # {{{
return
subset = prefix.startswith(old_prefix)
universe = self.current_items if subset else self.all_items
func = primary_startswith if tweaks['completion_mode'] == 'prefix' else containsq
func = primary_startswith if self.use_startswith_search else containsq
if func is primary_startswith and hierarchy_separator:
if hierarchy_separator != '.':
func = partial(hierarchy_startswith, sep=hierarchy_separator)
@ -353,6 +354,9 @@ class LineEdit(QLineEdit, LineEditECM):
self.no_popup = False
# Interface {{{
def set_use_startswith_search(self, yes: bool) -> None:
self.mcompleter.model().use_startswith_search = yes
def set_sort_func(self, sort_func):
self.mcompleter.model().sort_func = sort_func

View File

@ -30,6 +30,7 @@ class LanguagesEdit(EditWithComplete):
self._rmap = {lower(v):k for k,v in iteritems(self._lang_map)}
self.init_langs(db)
self.item_selected.connect(self.update_recently_used)
self.lineEdit().set_use_startswith_search(False)
def init_langs(self, db):
self.update_items_cache(itervalues(self._lang_map))