Bookmarks: fix compare invalid xpointers (#8690)

reviewable/pr8694/r1
hius07 2 years ago committed by GitHub
parent b21dc4dcc6
commit 1c2b01a51e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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

@ -643,6 +643,7 @@ end
function CreDocument:compareXPointers(xp1, xp2)
-- Returns 1 if XPointers are ordered (if xp2 is after xp1), -1 if not, 0 if same
-- Returns nil if any of XPointers are invalid
return self._document:compareXPointers(xp1, xp2)
end

Loading…
Cancel
Save