From befbcb112fce68f8c272962a4cff34ad7e86b8f3 Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Fri, 14 Jul 2023 14:15:11 +0100 Subject: [PATCH] Enhancement #2027727: Accented characters in tag browser find --- src/calibre/gui2/tag_browser/model.py | 23 ++++++++++++++++------- src/calibre/gui2/tag_browser/ui.py | 26 +++++++++++++++++--------- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src/calibre/gui2/tag_browser/model.py b/src/calibre/gui2/tag_browser/model.py index 622b276b10..c86ea4494b 100644 --- a/src/calibre/gui2/tag_browser/model.py +++ b/src/calibre/gui2/tag_browser/model.py @@ -1249,13 +1249,21 @@ class TagsModel(QAbstractItemModel): # {{{ else: use_exact_match = False filter_by = self.filter_categories_by + + if prefs['use_primary_find_in_search']: + final_equals = lambda x, y: primary_strcmp(x, y) == 0 + final_contains = primary_contains + else: + final_equals = lambda x, y: strcmp(x, y) == 0 + final_contains = lambda filt, txt: contains(filt, icu_lower(txt)) + for category in data.keys(): if use_exact_match: data[category] = [t for t in data[category] - if lower(t.name) == filter_by] + if final_equals(t.name, filter_by)] else: data[category] = [t for t in data[category] - if lower(t.name).find(filter_by) >= 0] + if final_contains(filter_by, t.name)] # Build a dict of the keys that have data. # Always add user categories so that the constructed hierarchy works. @@ -1843,12 +1851,13 @@ class TagsModel(QAbstractItemModel): # {{{ self.path_found = None if start_path is None: start_path = [] + if prefs['use_primary_find_in_search']: - final_strcmp = primary_strcmp + final_equals = lambda x, y: primary_strcmp(x, y) == 0 final_contains = primary_contains else: - final_strcmp = strcmp - final_contains = contains + final_equals = lambda x, y: strcmp(x, y) == 0 + final_contains = lambda filt, txt: contains(filt, icu_lower(txt)) def process_tag(depth, tag_index, tag_item, start_path): path = self.path_for_index(tag_index) @@ -1858,8 +1867,8 @@ class TagsModel(QAbstractItemModel): # {{{ if tag is None: return False name = tag.original_name - if (equals_match and final_strcmp(name, txt) == 0) or \ - (not equals_match and final_contains(txt, name)): + if ((equals_match and final_equals(name, txt)) or + (not equals_match and final_contains(txt, name))): self.path_found = path return True for i,c in enumerate(tag_item.children): diff --git a/src/calibre/gui2/tag_browser/ui.py b/src/calibre/gui2/tag_browser/ui.py index 7f3405eb6a..c219fba897 100644 --- a/src/calibre/gui2/tag_browser/ui.py +++ b/src/calibre/gui2/tag_browser/ui.py @@ -577,15 +577,23 @@ class TagBrowserBar(QWidget): # {{{ self.item_search.initialize('tag_browser_search') self.item_search.completer().setCaseSensitivity(Qt.CaseSensitivity.CaseSensitive) self.item_search.setToolTip( - '

' +_( - 'Search for items. If the text begins with equals (=) the search is ' - 'exact match, otherwise it is "contains" finding items containing ' - 'the text anywhere in the item name. Both exact and contains ' - 'searches ignore case. You can limit the search to particular ' - 'categories using syntax similar to search. For example, ' - 'tags:foo will find foo in any tag, but not in authors etc. Entering ' - '*foo will collapse all categories then showing only those categories ' - 'with items containing the text "foo"') + '

') + _('

' + 'Search for items in the Tag browser. If the search text begins ' + 'with an equals sign (=) then the search is "equals", otherwise ' + 'it is "contains". Both the equals and contains searches ignore ' + 'case. If the preference Preferences / Searching / Unaccented ' + 'characters match accented characters ... is checked then a ' + 'Character variant search is used, where characters ' + 'match regardless of accents, and punctuation is significant. See ' + 'The search interface in the calibre manual for more explanation.' + '

' + 'You can limit the search to particular categories using syntax ' + "similar to calibre's Search. For example, tags:foo will " + 'find foo in tags but not in authors etc.' + '

' + 'Entering *foo will collapse all categories before doing the ' + 'search.' + '

')) ac = QAction(parent) parent.addAction(ac) parent.keyboard.register_shortcut('tag browser find box',