mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Merge pull request #125 from chrox/highlight
bugfix: remove selected word only if hold moves out of word box
This commit is contained in:
@@ -141,7 +141,6 @@ function ReaderHighlight:onHold(arg, ges)
|
||||
end
|
||||
|
||||
function ReaderHighlight:onHoldPan(arg, ges)
|
||||
self.selected_word = nil
|
||||
if not self.page_boxes or #self.page_boxes == 0 then
|
||||
DEBUG("no page boxes detected")
|
||||
return true
|
||||
@@ -152,6 +151,11 @@ function ReaderHighlight:onHoldPan(arg, ges)
|
||||
--DEBUG("selected text:", self.selected_text)
|
||||
if self.selected_text then
|
||||
self.view.highlight.temp[self.hold_pos.page] = self.selected_text.boxes
|
||||
-- remove selected word if hold moves out of word box
|
||||
if self.selected_word and
|
||||
not self.selected_word.box:contains(self.selected_text.boxes[1]) then
|
||||
self.selected_word = nil
|
||||
end
|
||||
UIManager:setDirty(self.dialog, "partial")
|
||||
end
|
||||
end
|
||||
@@ -219,11 +223,31 @@ function ReaderHighlight:saveHighlight()
|
||||
local hl_item = {}
|
||||
hl_item["text"] = self.selected_text.text
|
||||
hl_item["boxes"] = self.selected_text.boxes
|
||||
hl_item["datetime"] = os.date("%Y-%m-%d %H:%M:%S"),
|
||||
table.insert(self.view.highlight.saved[page], hl_item)
|
||||
if self.selected_text.text ~= "" then
|
||||
self:exportToClippings(page, hl_item)
|
||||
end
|
||||
end
|
||||
--DEBUG("saved hightlights", self.view.highlight.saved[page])
|
||||
end
|
||||
|
||||
function ReaderHighlight:exportToClippings(page, item)
|
||||
DEBUG("export highlight to My Clippings")
|
||||
local clippings = io.open("/mnt/us/documents/My Clippings.txt", "a+")
|
||||
if clippings then
|
||||
local current_locale = os.setlocale()
|
||||
os.setlocale("C")
|
||||
clippings:write(self.document.file:gsub("(.*/)(.*)", "%2").."\n")
|
||||
clippings:write("- Koreader Highlight Page "..page.." ")
|
||||
clippings:write("| Added on "..os.date("%A, %b %d, %Y %I:%M:%S %p\n\n"))
|
||||
clippings:write(item["text"].."\n")
|
||||
clippings:write("==========\n")
|
||||
clippings:close()
|
||||
os.setlocale(current_locale)
|
||||
end
|
||||
end
|
||||
|
||||
function ReaderHighlight:addNote()
|
||||
DEBUG("add Note")
|
||||
UIManager:close(self.highlight_dialog)
|
||||
|
||||
@@ -18,6 +18,7 @@ ReaderView = OverlapGroup:new{
|
||||
outer_page_color = 0,
|
||||
-- hightlight
|
||||
highlight = {
|
||||
lighten_color = 0.2, -- color range [0.0, 1.0]
|
||||
temp_drawer = "invert",
|
||||
temp = {},
|
||||
saved_drawer = "lighten",
|
||||
@@ -236,7 +237,7 @@ end
|
||||
function ReaderView:getScrollPageRect(page, rect_p)
|
||||
local rect_s = Geom:new{}
|
||||
for _, state in ipairs(self.page_states) do
|
||||
local trans_p = Geom:new(rect_p)
|
||||
local trans_p = Geom:new(rect_p):copy()
|
||||
trans_p:transformByScale(state.zoom, state.zoom)
|
||||
if page == state.page and state.visible_area:contains(trans_p) then
|
||||
rect_s.x = rect_s.x + state.offset.x + trans_p.x - state.visible_area.x
|
||||
@@ -286,7 +287,7 @@ end
|
||||
|
||||
function ReaderView:getSinglePageRect(rect_p)
|
||||
local rect_s = Geom:new{}
|
||||
local trans_p = Geom:new(rect_p)
|
||||
local trans_p = Geom:new(rect_p):copy()
|
||||
trans_p:transformByScale(self.state.zoom, self.state.zoom)
|
||||
if self.visible_area:contains(trans_p) then
|
||||
rect_s.x = self.state.offset.x + trans_p.x - self.visible_area.x
|
||||
@@ -352,7 +353,7 @@ function ReaderView:drawHighlightRect(bb, x, y, rect, drawer)
|
||||
self.highlight.line_width,
|
||||
self.highlight.line_color)
|
||||
elseif drawer == "lighten" then
|
||||
bb:lightenRect(x, y, w, h, 0.1)
|
||||
bb:lightenRect(x, y, w, h, self.highlight.lighten_color)
|
||||
elseif drawer == "invert" then
|
||||
bb:invertRect(x, y, w, h)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user