diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2022-05-17 22:53:09 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2022-05-17 22:53:09 -0700 |
commit | 92bd6839c769b70e75c37c363a13789c8c0823e6 (patch) | |
tree | d3b2b7bbbd1429ff6a044c9723e942c197ae45c7 /text.lua | |
parent | 222a11a8dd0c8b5b68b5628928a38f05d0a3d13c (diff) | |
download | lines.love-92bd6839c769b70e75c37c363a13789c8c0823e6.tar.gz |
split mouse_pressed events between Text and Drawing
Diffstat (limited to 'text.lua')
-rw-r--r-- | text.lua | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/text.lua b/text.lua index d46edca..6888fda 100644 --- a/text.lua +++ b/text.lua @@ -143,6 +143,15 @@ function Text.keychord_pressed(chord) end end +function Text.in_line(line, x,y) + return x >= 16 and y >= line.y and y < line.y+15*Zoom +end + +function Text.move_cursor(line_index, line, x, hint) + Cursor_line = line_index + Cursor_pos = Text.nearest_cursor_pos(line.data, x) +end + function Text.nearest_cursor_pos(line, x, hint) if x == 0 then return 1 @@ -151,15 +160,19 @@ function Text.nearest_cursor_pos(line, x, hint) if x > max_x then return #line+1 end - local currx = Text.cursor_x(line, hint) - if currx > x-2 and currx < x+2 then - return hint + if hint then + local currx = Text.cursor_x(line, hint) + if currx > x-2 and currx < x+2 then + return hint + end end local left, right = 1, #line+1 - if currx > x then - right = hint - else - left = hint + if hint then + if currx > x then + right = hint + else + left = hint + end end while left < right-1 do local curr = math.floor((left+right)/2) |