diff --git a/frontend/apps/reader/modules/readerbookmark.lua b/frontend/apps/reader/modules/readerbookmark.lua index e3256696f..776a87594 100644 --- a/frontend/apps/reader/modules/readerbookmark.lua +++ b/frontend/apps/reader/modules/readerbookmark.lua @@ -213,7 +213,7 @@ function ReaderBookmark:onShowBookmark() { text = _("Remove this bookmark"), callback = function() - bookmark:removeBookmark(item) + bookmark:removeHightligit(item) bm_menu:switchItemTable(nil, bookmark.bookmarks, -1) UIManager:close(self.remove_bookmark_dialog) end, @@ -315,6 +315,14 @@ function ReaderBookmark:isBookmarkAdded(item) return false end +function ReaderBookmark:removeHightligit(item) + if item.pos0 then + self.ui:handleEvent(Event:new("Unhighlight", item)) + else + self:removeBookmark(item) + end +end + -- binary search to remove bookmark function ReaderBookmark:removeBookmark(item) local _middle diff --git a/frontend/apps/reader/modules/readerhighlight.lua b/frontend/apps/reader/modules/readerhighlight.lua index a1c1a6b39..24ae424fc 100644 --- a/frontend/apps/reader/modules/readerhighlight.lua +++ b/frontend/apps/reader/modules/readerhighlight.lua @@ -1,11 +1,11 @@ -local InputContainer = require("ui/widget/container/inputcontainer") +local ButtonDialog = require("ui/widget/buttondialog") +local ConfirmBox = require("ui/widget/confirmbox") local Device = require("device") local Event = require("ui/event") +local InputContainer = require("ui/widget/container/inputcontainer") local UIManager = require("ui/uimanager") -local ButtonDialog = require("ui/widget/buttondialog") local logger = require("logger") local _ = require("gettext") -local ConfirmBox = require("ui/widget/confirmbox") local ReaderHighlight = InputContainer:new{} @@ -402,6 +402,34 @@ function ReaderHighlight:onHighlight() self:saveHighlight() end +function ReaderHighlight:onUnhighlight(item) + local page + local sel_text + local sel_pos0 + local idx + if item then + local bookmark_text = item.text + local words = {} + for word in bookmark_text:gmatch("%S+") do table.insert(words, word) end + page = tonumber(words[2]) + sel_text = item.notes + sel_pos0 = item.pos0 + else + page = self.hold_pos.page + sel_text = self.selected_text.text + sel_pos0 = self.selected_text.pos0 + end + for index = 1, #self.view.highlight.saved[page] do + if self.view.highlight.saved[page][index].text == sel_text and + self.view.highlight.saved[page][index].pos0 == sel_pos0 then + idx = index + break + end + end + self:deleteHighlight(page, idx) + return true +end + function ReaderHighlight:getHighlightBookmarkItem() if self.hold_pos and not self.selected_text then self:highlightFromHoldPos() diff --git a/frontend/ui/widget/dictquicklookup.lua b/frontend/ui/widget/dictquicklookup.lua index e53d60047..e8bcf34f1 100644 --- a/frontend/ui/widget/dictquicklookup.lua +++ b/frontend/ui/widget/dictquicklookup.lua @@ -329,9 +329,13 @@ function DictQuickLookup:update() }, { text = self:getHighlightText(), - enabled = select(2, self:getHighlightText()), + enabled = true, callback = function() - self.ui:handleEvent(Event:new("Highlight")) + if self:getHighlightText() == "Highlight" then + self.ui:handleEvent(Event:new("Highlight")) + else + self.ui:handleEvent(Event:new("Unhighlight")) + end self:update() end, },