From ca6a4868069c2ddb58bedf8497690440d1440d1f Mon Sep 17 00:00:00 2001 From: Frans de Jonge Date: Sat, 17 Feb 2018 06:31:32 +0100 Subject: [PATCH] [UX] InputText: Paste on hold (#3682) See https://github.com/koreader/koreader/issues/3441 --- frontend/ui/widget/inputtext.lua | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/frontend/ui/widget/inputtext.lua b/frontend/ui/widget/inputtext.lua index b64a28e3e..7cef22784 100644 --- a/frontend/ui/widget/inputtext.lua +++ b/frontend/ui/widget/inputtext.lua @@ -48,7 +48,13 @@ if Device.isTouchDevice() then ges = "tap", range = self.dimen } - } + }, + HoldTextBox = { + GestureRange:new{ + ges = "hold", + range = self.dimen + } + }, } end @@ -65,6 +71,23 @@ if Device.isTouchDevice() then end) end end + + function InputText:onHoldTextBox(arg, ges) + if self.parent.onSwitchFocus then + self.parent:onSwitchFocus(self) + end + local x = ges.pos.x - self._frame_textwidget.dimen.x - self.bordersize - self.padding + local y = ges.pos.y - self._frame_textwidget.dimen.y - self.bordersize - self.padding + if x > 0 and y > 0 then + self.charpos = self.text_widget:moveCursor(x, y) + if Device:hasClipboard() and Device.input.hasClipboardText() then + self:addChar(Device.input.getClipboardText()) + end + UIManager:setDirty(self.parent, function() + return "ui", self.dimen + end) + end + end else Keyboard = require("ui/widget/physicalkeyboard") function InputText:initEventListener() end @@ -230,7 +253,7 @@ function InputText:addChar(char) return end table.insert(self.charlist, self.charpos, char) - self.charpos = self.charpos + 1 + self.charpos = self.charpos + string.len(char) self:initTextBox(table.concat(self.charlist), true) end