fix #1373 by checking the pos0 and pos1 of selected text

pull/1408/head
chrox 9 years ago
parent 02d61115dc
commit ca6b3d7e33

@ -262,6 +262,21 @@ function ReaderBookmark:getDogearBookmarkIndex(pn_or_xp)
end
end
function ReaderBookmark:isBookmarkSame(item1, item2)
if item1.notes ~= item2.notes then return end
if self.ui.document.info.has_pages then
if not item2.pos0 or not item2.pos1 then return end
local zoom1 = item1.pos0.zoom
local zoom1 = item2.pos0.zoom
return item2.pos0 and item2.pos1 and item1.pos0.page == item2.pos0.page
and item1.pos0.x == item2.pos0.x and item1.pos0.y == item2.pos0.y
and item1.pos1.x == item2.pos1.x and item1.pos1.y == item2.pos1.y
else
return item1.page == item2.page
and item1.pos0 == item2.pos0 and item1.pos1 == item2.pos1
end
end
-- binary insert of sorted bookmarks
function ReaderBookmark:addBookmark(item)
local _start, _middle, _end, direction = 1, 1, #self.bookmarks, 0
@ -269,7 +284,10 @@ function ReaderBookmark:addBookmark(item)
local v = self.bookmarks[_middle]
_middle = math.floor((_start + _end)/2)
-- won't add duplicated bookmarks
if item.page == self.bookmarks[_middle].page then return end
if self:isBookmarkSame(item, self.bookmarks[_middle]) then
DEBUG("skip adding duplicated bookmark")
return
end
if self:isBookmarkInPageOrder(item, self.bookmarks[_middle]) then
_end, direction = _middle - 1, 0
else

@ -392,7 +392,8 @@ end
function ReaderHighlight:saveHighlight()
DEBUG("save highlight")
local page = self.hold_pos.page
if self.hold_pos and self.selected_text then
if self.hold_pos and self.selected_text and self.selected_text.pos0
and self.selected_text.pos1 then
if not self.view.highlight.saved[page] then
self.view.highlight.saved[page] = {}
end
@ -408,6 +409,8 @@ function ReaderHighlight:saveHighlight()
table.insert(self.view.highlight.saved[page], hl_item)
self.ui.bookmark:addBookmark({
page = self.ui.document.info.has_pages and page or self.selected_text.pos0,
pos0 = self.selected_text.pos0,
pos1 = self.selected_text.pos1,
datetime = datetime,
notes = self.selected_text.text,
highlighted = true,

Loading…
Cancel
Save