diff --git a/resources/default_tweaks.py b/resources/default_tweaks.py index 6648938310..5dad666a16 100644 --- a/resources/default_tweaks.py +++ b/resources/default_tweaks.py @@ -504,7 +504,13 @@ tab_accepts_uncompleted_text = False # There is also a 'word-prefix' mode that matches only at the start of words, # so typing 'asi' will match Asimov and "Isaac Asimov" but not Quasimodo. # Similarly, typing 'cat' will match cathedral and "tabby cat" but not education. +# +# If completion_mode is 'word-prefix', you can specify additionals word break chars +# with the extra_word_break_chars list. +# For example, for extra_word_break_chars = ['-'], typing 'fic' will match +# both "Science Fiction" and "Science-Fiction", instead of only the first one. completion_mode = 'prefix' +extra_word_break_chars = [] #: Sort the list of libraries alphabetically # The list of libraries in the Copy to library and Quick switch menus are diff --git a/src/calibre/gui2/complete2.py b/src/calibre/gui2/complete2.py index c310b23bca..f76b01d6bd 100644 --- a/src/calibre/gui2/complete2.py +++ b/src/calibre/gui2/complete2.py @@ -63,6 +63,10 @@ class CompleteModel(QAbstractListModel): # {{{ completion_mode = get_completion_mode() self.use_startswith_search = completion_mode == 'prefix' self.use_word_prefix_search = completion_mode == 'word-prefix' + ewbc = tweaks['extra_word_break_chars'] or '' + if not isinstance(ewbc, str): + ewbc = ''.join(ewbc) + self.extra_word_break_chars = ''.join(set(ewbc)) def set_items(self, items): if self.strip_completion_entries: @@ -87,7 +91,8 @@ class CompleteModel(QAbstractListModel): # {{{ return subset = prefix.startswith(old_prefix) universe = self.current_items if subset else self.all_items - word_iterator = get_word_break_iterator_with_extra_chars(extra_break_chars=hierarchy_separator) + extra_break_chars = hierarchy_separator + self.extra_word_break_chars + word_iterator = get_word_break_iterator_with_extra_chars(extra_break_chars=extra_break_chars) collator = primary_collator() word_prefix_match = partial(word_prefix_matcher, collator, word_iterator) if self.use_word_prefix_search: