Allow navigating `read`'s input using the mouse

This commit is contained in:
SquidDev 2019-11-23 13:21:07 +00:00
parent a8fadabaf1
commit c4d18aa9ca
1 changed files with 9 additions and 1 deletions

View File

@ -326,7 +326,7 @@ function read( _sReplaceChar, _tHistory, _fnComplete, _sDefault )
nScroll = (sx + nPos) - w
end
local cx,cy = term.getCursorPos()
local _, cy = term.getCursorPos()
term.setCursorPos( sx, cy )
local sReplace = (_bClear and " ") or _sReplaceChar
if sReplace then
@ -523,6 +523,14 @@ function read( _sReplaceChar, _tHistory, _fnComplete, _sDefault )
end
elseif sEvent == "mouse_click" or sEvent == "mouse_drag" and param == 1 then
local _, cy = term.getCursorPos()
if param2 >= sx and param2 <= w and param2 == cy then
-- Then ensure we don't scroll beyond the current line
nPos = math.min(math.max(nScroll + x - sx, 0, #sLine))
redraw()
end
elseif sEvent == "term_resize" then
-- Terminal resized
w = term.getSize()