mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
TextEditor: allow scrolling by lines with Pan (#4145)
Feature of ScrollTextWidget, only used for now by TextEditor. Pan is like Swipe, but wait a bit at end of gesture to release: the line on which Pan was started will be moved to where Pan is released. May conflict with MovableContainer (so not enabled for DictQuickLookup, where it could have been nice - but it would work only with text dictionaries, not with HTML ones, as ScrollHtmlWidget can't really do that).
This commit is contained in:
@@ -684,6 +684,32 @@ function TextBoxWidget:scrollUp()
|
||||
end
|
||||
end
|
||||
|
||||
function TextBoxWidget:scrollLines(nb_lines)
|
||||
-- nb_lines can be negative
|
||||
if nb_lines == 0 then
|
||||
return
|
||||
end
|
||||
self.image_show_alt_text = nil
|
||||
local new_line_num = self.virtual_line_num + nb_lines
|
||||
if new_line_num < 1 then
|
||||
new_line_num = 1
|
||||
end
|
||||
if new_line_num > #self.vertical_string_list - self.lines_per_page + 1 then
|
||||
new_line_num = #self.vertical_string_list - self.lines_per_page + 1
|
||||
end
|
||||
self.virtual_line_num = new_line_num
|
||||
self:free()
|
||||
self:_renderText(self.virtual_line_num, self.virtual_line_num + self.lines_per_page - 1)
|
||||
if self.editable then
|
||||
local x, y = self:_getXYForCharPos() -- luacheck: no unused
|
||||
if y < 0 or y >= self.text_height then
|
||||
-- move cursor to first line of visible area
|
||||
local ln = self.height == nil and 1 or self.virtual_line_num
|
||||
self:moveCursorToCharPos(self.vertical_string_list[ln] and self.vertical_string_list[ln].offset or 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function TextBoxWidget:scrollToTop()
|
||||
self.image_show_alt_text = nil
|
||||
if self.virtual_line_num > 1 then
|
||||
|
||||
Reference in New Issue
Block a user