mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Annotations browser: Sort the entries in order of position in book.
Fixes #1922691 [Calibre Viewer annotations/highlights are not sorted correctly](https://bugs.launchpad.net/calibre/+bug/1922691)
This commit is contained in:
parent
53e42361d5
commit
d447613b2b
@ -114,6 +114,28 @@ class AnnotsResultsDelegate(ResultsDelegate):
|
|||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
|
||||||
|
def sorted_items(items):
|
||||||
|
from calibre.ebooks.epub.cfi.parse import cfi_sort_key
|
||||||
|
def_spine = 999999999
|
||||||
|
defval = cfi_sort_key(f'/{def_spine}')
|
||||||
|
|
||||||
|
def sort_key(x):
|
||||||
|
x = x['annotation']
|
||||||
|
atype = x['type']
|
||||||
|
if atype == 'highlight':
|
||||||
|
cfi = x.get('start_cfi')
|
||||||
|
if cfi:
|
||||||
|
spine_idx = x.get('spine_index', def_spine)
|
||||||
|
cfi = f'/{spine_idx}/{cfi}'
|
||||||
|
return cfi_sort_key(cfi, only_path=False)
|
||||||
|
elif atype == 'bookmark':
|
||||||
|
if x.get('pos_type') == 'epubcfi':
|
||||||
|
return cfi_sort_key(x['pos'], only_path=False)
|
||||||
|
return defval
|
||||||
|
|
||||||
|
return sorted(items, key=sort_key)
|
||||||
|
|
||||||
|
|
||||||
class Export(Dialog): # {{{
|
class Export(Dialog): # {{{
|
||||||
|
|
||||||
prefs = gprefs
|
prefs = gprefs
|
||||||
@ -309,7 +331,7 @@ class ResultsList(QTreeWidget):
|
|||||||
section.setData(0, Qt.ItemDataRole.UserRole, book_id)
|
section.setData(0, Qt.ItemDataRole.UserRole, book_id)
|
||||||
self.addTopLevelItem(section)
|
self.addTopLevelItem(section)
|
||||||
section.setExpanded(True)
|
section.setExpanded(True)
|
||||||
for result in entry['matches']:
|
for result in sorted_items(entry['matches']):
|
||||||
item = QTreeWidgetItem(section, [' '], 2)
|
item = QTreeWidgetItem(section, [' '], 2)
|
||||||
self.item_map.append(item)
|
self.item_map.append(item)
|
||||||
item.setFlags(Qt.ItemFlag.ItemIsSelectable | Qt.ItemFlag.ItemIsEnabled | Qt.ItemFlag.ItemNeverHasChildren)
|
item.setFlags(Qt.ItemFlag.ItemIsSelectable | Qt.ItemFlag.ItemIsEnabled | Qt.ItemFlag.ItemNeverHasChildren)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user