From 4b312528f78b6bf21fcf31dff9b98de1870b9f10 Mon Sep 17 00:00:00 2001 From: chrox Date: Mon, 28 Oct 2013 20:01:44 +0800 Subject: [PATCH 1/3] fix lost refresh in inputdialog enter callback --- frontend/ui/widget/inputtext.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/ui/widget/inputtext.lua b/frontend/ui/widget/inputtext.lua index 7e4258424..8eb11ec61 100644 --- a/frontend/ui/widget/inputtext.lua +++ b/frontend/ui/widget/inputtext.lua @@ -99,7 +99,7 @@ end function InputText:addChar(char) if self.enter_callback and char == '\n' then - UIManager:scheduleIn(0.1, function() self.enter_callback() end) + UIManager:scheduleIn(0.3, function() self.enter_callback() end) return end table.insert(self.charlist, self.charpos, char) From 2f2d3553ff0a6595dce93122fb6c964e569f4685 Mon Sep 17 00:00:00 2001 From: chrox Date: Mon, 28 Oct 2013 21:48:17 +0800 Subject: [PATCH 2/3] fix cannot highlight text with only one word in the first line --- frontend/ui/reader/readerhighlight.lua | 95 +++++++++++++------------- 1 file changed, 48 insertions(+), 47 deletions(-) diff --git a/frontend/ui/reader/readerhighlight.lua b/frontend/ui/reader/readerhighlight.lua index b8247f121..beb080c5d 100644 --- a/frontend/ui/reader/readerhighlight.lua +++ b/frontend/ui/reader/readerhighlight.lua @@ -12,6 +12,52 @@ local Input = require("ui/input") local DEBUG = require("dbg") local _ = require("gettext") +local HighlightDialog = InputContainer:new{ + buttons = nil, + tap_close_callback = nil, +} + +function HighlightDialog:init() + if Device:hasKeyboard() then + self.key_events = { + AnyKeyPressed = { { Input.group.Any }, + seqtext = "any key", doc = _("close dialog") } + } + else + self.ges_events.TapClose = { + GestureRange:new{ + ges = "tap", + range = Geom:new{ + x = 0, y = 0, + w = Screen:getWidth(), + h = Screen:getHeight(), + } + } + } + end + self[1] = CenterContainer:new{ + dimen = Screen:getSize(), + FrameContainer:new{ + ButtonTable:new{ + width = Screen:getWidth()*0.9, + buttons = self.buttons, + }, + background = 0, + bordersize = 2, + radius = 7, + padding = 2, + } + } +end + +function HighlightDialog:onTapClose() + UIManager:close(self) + if self.tap_close_callback then + self.tap_close_callback() + end + return true +end + local ReaderHighlight = InputContainer:new{} function ReaderHighlight:init() @@ -168,7 +214,8 @@ function ReaderHighlight:onHoldPan(arg, ges) self.view.highlight.temp[self.hold_pos.page] = self.selected_text.sboxes -- remove selected word if hold moves out of word box if self.selected_word and - not self.selected_word.sbox:contains(self.selected_text.sboxes[1]) then + not self.selected_word.sbox:contains(self.selected_text.sboxes[1]) or + #self.selected_text.sboxes > 1 then self.selected_word = nil end UIManager:setDirty(self.dialog, "partial") @@ -198,52 +245,6 @@ function ReaderHighlight:translate(selected_text) end end -HighlightDialog = InputContainer:new{ - buttons = nil, - tap_close_callback = nil, -} - -function HighlightDialog:init() - if Device:hasKeyboard() then - key_events = { - AnyKeyPressed = { { Input.group.Any }, - seqtext = "any key", doc = _("close dialog") } - } - else - self.ges_events.TapClose = { - GestureRange:new{ - ges = "tap", - range = Geom:new{ - x = 0, y = 0, - w = Screen:getWidth(), - h = Screen:getHeight(), - } - } - } - end - self[1] = CenterContainer:new{ - dimen = Screen:getSize(), - FrameContainer:new{ - ButtonTable:new{ - width = Screen:getWidth()*0.9, - buttons = self.buttons, - }, - background = 0, - bordersize = 2, - radius = 7, - padding = 2, - } - } -end - -function HighlightDialog:onTapClose() - UIManager:close(self) - if self.tap_close_callback then - self.tap_close_callback() - end - return true -end - function ReaderHighlight:onHoldRelease(arg, ges) if self.selected_word then self:lookup(self.selected_word) From 5bf56cbf4c3a057ff325763eb919a54f728d949f Mon Sep 17 00:00:00 2001 From: chrox Date: Mon, 28 Oct 2013 21:49:54 +0800 Subject: [PATCH 3/3] check position nullity in getTextFromBoxes --- frontend/document/koptinterface.lua | 45 ++++++++++++++--------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/frontend/document/koptinterface.lua b/frontend/document/koptinterface.lua index 2cc454c35..50bcf1ede 100644 --- a/frontend/document/koptinterface.lua +++ b/frontend/document/koptinterface.lua @@ -532,29 +532,29 @@ end --[[ get index of nearest word box around pos --]] -local function getWordBoxIndices(boxes, pos) - local function inside_box(box) - local x, y = pos.x, pos.y - if box.x0 <= x and box.y0 <= y and box.x1 >= x and box.y1 >= y then - return true - end - return false +local function inside_box(box, pos) + local x, y = pos.x, pos.y + if box.x0 <= x and box.y0 <= y and box.x1 >= x and box.y1 >= y then + return true end - local function box_distance(i, j) - local wb = boxes[i][j] - if inside_box(wb) then - return 0 - else - local x0, y0 = pos.x, pos.y - local x1, y1 = (wb.x0 + wb.x1) / 2, (wb.y0 + wb.y1) / 2 - return (x0 - x1)*(x0 - x1) + (y0 - y1)*(y0 - y1) - end + return false +end + +local function box_distance(box, pos) + if inside_box(box, pos) then + return 0 + else + local x0, y0 = pos.x, pos.y + local x1, y1 = (box.x0 + box.x1) / 2, (box.y0 + box.y1) / 2 + return (x0 - x1)*(x0 - x1) + (y0 - y1)*(y0 - y1) end +end +local function getWordBoxIndices(boxes, pos) local m, n = 1, 1 for i = 1, #boxes do for j = 1, #boxes[i] do - if box_distance(i, j) < box_distance(m, n) then + if box_distance(boxes[i][j], pos) < box_distance(boxes[m][n], pos) then m, n = i, j end end @@ -586,6 +586,7 @@ end get text and text boxes between pos0 and pos1 --]] function KoptInterface:getTextFromBoxes(boxes, pos0, pos1) + if not pos0 or not pos1 then return {} end local line_text = "" local line_boxes = {} local i_start, j_start = getWordBoxIndices(boxes, pos0) @@ -706,12 +707,10 @@ function KoptInterface:nativeToReflowPosTransform(doc, pageno, pos) local kctx_hash = "kctx|"..context_hash local cached = Cache:check(kctx_hash) local kc = self:waitForContext(cached.kctx) - --kc:setDebug() - --DEBUG("transform native pos", pos) - local rpos = {} - rpos.x, rpos.y = kc:nativeToReflowPosTransform(pos.x, pos.y) - --DEBUG("transformed reflowed pos", rpos) - return rpos + local x, y = kc:nativeToReflowPosTransform(pos.x, pos.y) + if x ~= nil and y ~= nil then + return {x=x, y=y} + end end --[[