mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget: - proper line scrolling when moving cursor or inserting/deleting text to behave like most text editors do - fix cursor navigation, optimize refreshes when moving only the cursor, don't recreate the textwidget when moving cursor up/down - optimize refresh areas, stick to "ui" to avoid a "partial" black flash every 6 appended or deleted chars InputText: - fix issue when toggling Show password multiple times - new option: InputText.cursor_at_end (default: true) - if no InputText.height provided, measure the text widget height that we would start with, and use a ScrollTextWidget with that fixed height, so widget does not overflow container if we extend the text and increase the number of lines - as we are using "ui" refreshes while text editing, allows refreshing the InputText with a diagonal swipe on it (actually, refresh the whole screen, which allows refreshing the keyboard too if needed) ScrollTextWidget: - properly align scrollbar with its TextBoxWidget TextBoxWidget: - some cleanup (added new properties to avoid many method calls), added proxy methods for upper widgets to get them - reordered/renamed/refactored the *CharPos* methods for easier reading (sorry for the diff that won't help reviewing, but that was needed) InputDialog: - new options: allow_newline = false, -- allow entering new lines cursor_at_end = true, -- starts with cursor at end of text, ready to append fullscreen = false, -- adjust to full screen minus keyboard condensed = false, -- true will prevent adding air and balance between elements add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons add_nav_bar = false, -- append a row of page navigation buttons - find the most adequate text height, when none provided or fullscreen, to not overflow screen (and not be stuck with Cancel/Save buttons hidden) - had to disable the use of a MovableContainer (many issues like becoming transparent when a PathChooser comes in front, Hold to paste from clipboard, moving the InputDialog under the keyboard and getting stuck...) GestureRange: fix possible crash (when event processed after widget destruction ?) LoginDialog: fix some ui stack increase and possible crash when switching focus many times.
This commit is contained in:
@@ -19,6 +19,7 @@ local ScrollTextWidget = InputContainer:new{
|
||||
text = nil,
|
||||
charlist = nil,
|
||||
charpos = nil,
|
||||
top_line_num = nil,
|
||||
editable = false,
|
||||
justified = false,
|
||||
face = nil,
|
||||
@@ -36,6 +37,8 @@ function ScrollTextWidget:init()
|
||||
text = self.text,
|
||||
charlist = self.charlist,
|
||||
charpos = self.charpos,
|
||||
top_line_num = self.top_line_num,
|
||||
dialog = self.dialog,
|
||||
editable = self.editable,
|
||||
justified = self.justified,
|
||||
face = self.face,
|
||||
@@ -52,9 +55,10 @@ function ScrollTextWidget:init()
|
||||
low = 0,
|
||||
high = visible_line_count / total_line_count,
|
||||
width = self.scroll_bar_width,
|
||||
height = self.height,
|
||||
height = self.text_widget:getTextHeight(),
|
||||
}
|
||||
local horizontal_group = HorizontalGroup:new{}
|
||||
self:updateScrollBar()
|
||||
local horizontal_group = HorizontalGroup:new{ align = "top" }
|
||||
table.insert(horizontal_group, self.text_widget)
|
||||
table.insert(horizontal_group, HorizontalSpan:new{width=self.text_scroll_span})
|
||||
table.insert(horizontal_group, self.v_scroll_bar)
|
||||
@@ -92,38 +96,93 @@ function ScrollTextWidget:focus()
|
||||
self.text_widget:focus()
|
||||
end
|
||||
|
||||
function ScrollTextWidget:moveCursor(x, y)
|
||||
return self.text_widget:moveCursor(x, y)
|
||||
function ScrollTextWidget:getTextHeight()
|
||||
return self.text_widget:getTextHeight()
|
||||
end
|
||||
|
||||
function ScrollTextWidget:getLineHeight()
|
||||
return self.text_widget:getLineHeight()
|
||||
end
|
||||
|
||||
function ScrollTextWidget:getCharPos()
|
||||
return self.text_widget:getCharPos()
|
||||
end
|
||||
|
||||
function ScrollTextWidget:updateScrollBar()
|
||||
local low, high = self.text_widget:getVisibleHeightRatios()
|
||||
if low ~= self.prev_low or high ~= self.prev_high then
|
||||
self.prev_low = low
|
||||
self.prev_high = high
|
||||
self.v_scroll_bar:set(low, high)
|
||||
UIManager:setDirty(self.dialog, function()
|
||||
return "partial", self.dimen
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
function ScrollTextWidget:moveCursorToCharPos(charpos)
|
||||
self.text_widget:moveCursorToCharPos(charpos)
|
||||
self:updateScrollBar()
|
||||
end
|
||||
|
||||
function ScrollTextWidget:moveCursorToXY(x, y, no_overflow)
|
||||
self.text_widget:moveCursorToXY(x, y, no_overflow)
|
||||
self:updateScrollBar()
|
||||
end
|
||||
|
||||
function ScrollTextWidget:moveCursorLeft()
|
||||
self.text_widget:moveCursorLeft();
|
||||
self:updateScrollBar()
|
||||
end
|
||||
|
||||
function ScrollTextWidget:moveCursorRight()
|
||||
self.text_widget:moveCursorRight();
|
||||
self:updateScrollBar()
|
||||
end
|
||||
|
||||
function ScrollTextWidget:moveCursorUp()
|
||||
return self.text_widget:moveCursorUp();
|
||||
self.text_widget:moveCursorUp();
|
||||
self:updateScrollBar()
|
||||
end
|
||||
|
||||
function ScrollTextWidget:moveCursorDown()
|
||||
return self.text_widget:moveCursorDown();
|
||||
self.text_widget:moveCursorDown();
|
||||
self:updateScrollBar()
|
||||
end
|
||||
|
||||
function ScrollTextWidget:scrollDown()
|
||||
self.text_widget:scrollDown();
|
||||
self:updateScrollBar()
|
||||
end
|
||||
|
||||
function ScrollTextWidget:scrollUp()
|
||||
self.text_widget:scrollUp();
|
||||
self:updateScrollBar()
|
||||
end
|
||||
|
||||
function ScrollTextWidget:scrollToTop()
|
||||
self.text_widget:scrollToTop();
|
||||
self:updateScrollBar()
|
||||
end
|
||||
|
||||
function ScrollTextWidget:scrollToBottom()
|
||||
self.text_widget:scrollToBottom();
|
||||
self:updateScrollBar()
|
||||
end
|
||||
|
||||
function ScrollTextWidget:scrollText(direction)
|
||||
if direction == 0 then return end
|
||||
local low, high
|
||||
if direction > 0 then
|
||||
low, high = self.text_widget:scrollDown()
|
||||
self.text_widget:scrollDown()
|
||||
else
|
||||
low, high = self.text_widget:scrollUp()
|
||||
self.text_widget:scrollUp()
|
||||
end
|
||||
self.v_scroll_bar:set(low, high)
|
||||
UIManager:setDirty(self.dialog, function()
|
||||
return "partial", self.dimen
|
||||
end)
|
||||
self:updateScrollBar()
|
||||
end
|
||||
|
||||
function ScrollTextWidget:scrollToRatio(ratio)
|
||||
local low, high = self.text_widget:scrollToRatio(ratio)
|
||||
self.v_scroll_bar:set(low, high)
|
||||
UIManager:setDirty(self.dialog, function()
|
||||
return "partial", self.dimen
|
||||
end)
|
||||
self.text_widget:scrollToRatio(ratio)
|
||||
self:updateScrollBar()
|
||||
end
|
||||
|
||||
function ScrollTextWidget:onScrollText(arg, ges)
|
||||
@@ -139,6 +198,10 @@ function ScrollTextWidget:onScrollText(arg, ges)
|
||||
end
|
||||
|
||||
function ScrollTextWidget:onTapScrollText(arg, ges)
|
||||
if self.editable then
|
||||
-- Tap is used to position cursor
|
||||
return false
|
||||
end
|
||||
-- same tests as done in TextBoxWidget:scrollUp/Down
|
||||
if ges.pos.x < Screen:getWidth()/2 then
|
||||
if self.text_widget.virtual_line_num > 1 then
|
||||
|
||||
Reference in New Issue
Block a user