From a3e19581f6242edc303e71cb5d79e598b4b4e3f0 Mon Sep 17 00:00:00 2001 From: shouya <526598+shouya@users.noreply.github.com> Date: Fri, 23 May 2025 10:08:24 +0900 Subject: [PATCH 1/2] Improve highlight grouping with recurring chapter names --- src/calibre/gui2/viewer/highlights.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/viewer/highlights.py b/src/calibre/gui2/viewer/highlights.py index b49b3375f2..1fc50d9d8e 100644 --- a/src/calibre/gui2/viewer/highlights.py +++ b/src/calibre/gui2/viewer/highlights.py @@ -336,14 +336,15 @@ class Highlights(QTreeWidget): for h in self.sorted_highlights(highlights): tfam = tuple(h.get('toc_family_titles') or ()) + spine_index = h.get('spine_index', -1) if tfam: tsec = tfam[0] lsec = tfam[-1] - key = tfam + key = (spine_index, tsec or '', lsec or '') else: tsec = h.get('top_level_section_title') lsec = h.get('lowest_level_section_title') - key = (tsec or '', lsec or '') + key = (spine_index, tsec or '', lsec or '') short_title = lsec or tsec or _('Unknown') section = { 'title': short_title, 'tfam': tfam, 'tsec': tsec, 'lsec': lsec, 'items': [], 'tooltip': tooltip_for(tfam), 'key': key, From 8fa9b5778e18a095651d43287d477672c1b79367 Mon Sep 17 00:00:00 2001 From: shouya <526598+shouya@users.noreply.github.com> Date: Fri, 23 May 2025 11:06:49 +0900 Subject: [PATCH 2/2] preserve tfam group key when it exists --- src/calibre/gui2/viewer/highlights.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/gui2/viewer/highlights.py b/src/calibre/gui2/viewer/highlights.py index 1fc50d9d8e..dea1794b51 100644 --- a/src/calibre/gui2/viewer/highlights.py +++ b/src/calibre/gui2/viewer/highlights.py @@ -340,7 +340,7 @@ class Highlights(QTreeWidget): if tfam: tsec = tfam[0] lsec = tfam[-1] - key = (spine_index, tsec or '', lsec or '') + key = (spine_index,) + tfam else: tsec = h.get('top_level_section_title') lsec = h.get('lowest_level_section_title')