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:
poire-z
2018-08-10 18:05:09 +02:00
committed by GitHub
parent d222fe25b6
commit adceda15b7
5 changed files with 71 additions and 0 deletions

View File

@@ -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