Bookmarks: fix compare invalid xpointers (#8690)

This commit is contained in:
hius07
2022-01-19 15:18:03 +02:00
committed by GitHub
parent b21dc4dcc6
commit 1c2b01a51e
2 changed files with 9 additions and 5 deletions

View File

@@ -232,13 +232,16 @@ function ReaderBookmark:isBookmarkInPositionOrder(a, b)
local b_page = self.ui.document:getPageFromXPointer(b.page)
if a_page == b_page then -- both bookmarks in the same page
local compare_xp = self.ui.document:compareXPointers(a.page, b.page)
if compare_xp == 0 then -- both bookmarks with the same start
if a.highlighted and b.highlighted then -- both are highlights, compare ends
return self.ui.document:compareXPointers(a.pos1, b.pos1) < 0
if compare_xp then
if compare_xp == 0 then -- both bookmarks with the same start
if a.highlighted and b.highlighted then -- both are highlights, compare ends
return self.ui.document:compareXPointers(a.pos1, b.pos1) < 0
end
return a.highlighted -- have page bookmarks before highlights
end
return a.highlighted -- have page bookmarks before highlights
return compare_xp < 0
end
return compare_xp < 0
-- if compare_xp is nil, some xpointer is invalid and will be sorted first to page 1
end
return a_page > b_page
end