From 7419820c0993c705b7213d9a0b5083ad60d82eb6 Mon Sep 17 00:00:00 2001 From: hius07 <62179190+hius07@users.noreply.github.com> Date: Sun, 23 May 2021 00:25:14 +0300 Subject: [PATCH] VirtualKeyboard: hold left/right arrows moves to start/end of line (#7730) --- frontend/ui/widget/inputtext.lua | 12 ++++++++++++ frontend/ui/widget/virtualkeyboard.lua | 16 ++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/frontend/ui/widget/inputtext.lua b/frontend/ui/widget/inputtext.lua index 5cb66b0a3..2483b76ab 100644 --- a/frontend/ui/widget/inputtext.lua +++ b/frontend/ui/widget/inputtext.lua @@ -755,6 +755,18 @@ function InputText:rightChar() self.charpos, self.top_line_num = self.text_widget:getCharPos() end +function InputText:goToStartOfLine() + local new_pos = select(1, self:getStringPos({"\n", "\r"}, {"\n", "\r"})) + self.text_widget:moveCursorToCharPos(new_pos) + self.charpos, self.top_line_num = self.text_widget:getCharPos() +end + +function InputText:goToEndOfLine() + local new_pos = select(2, self:getStringPos({"\n", "\r"}, {"\n", "\r"})) + 1 + self.text_widget:moveCursorToCharPos(new_pos) + self.charpos, self.top_line_num = self.text_widget:getCharPos() +end + function InputText:goToHome() self.text_widget:moveCursorToCharPos(1) end diff --git a/frontend/ui/widget/virtualkeyboard.lua b/frontend/ui/widget/virtualkeyboard.lua index 4129be48d..519a30c7d 100644 --- a/frontend/ui/widget/virtualkeyboard.lua +++ b/frontend/ui/widget/virtualkeyboard.lua @@ -113,8 +113,16 @@ function VirtualKey:init() --self.skiphold = true elseif self.label =="←" then self.callback = function() self.keyboard:leftChar() end + self.hold_callback = function() + self.ignore_key_release = true + self.keyboard:goToStartOfLine() + end elseif self.label == "→" then self.callback = function() self.keyboard:rightChar() end + self.hold_callback = function() + self.ignore_key_release = true + self.keyboard:goToEndOfLine() + end elseif self.label == "↑" then self.callback = function() self.keyboard:upLine() end elseif self.label == "↓" then @@ -899,6 +907,14 @@ function VirtualKeyboard:rightChar() self.inputbox:rightChar() end +function VirtualKeyboard:goToStartOfLine() + self.inputbox:goToStartOfLine() +end + +function VirtualKeyboard:goToEndOfLine() + self.inputbox:goToEndOfLine() +end + function VirtualKeyboard:upLine() self.inputbox:upLine() end