diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2022-05-20 08:02:03 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2022-05-20 08:02:03 -0700 |
commit | 1c20d514f246903185b8df27dd3388e2147b7e5e (patch) | |
tree | e3a62f4c7769bc3e978cf872d3925a61807a3b4f | |
parent | 3ec8019cc0c1b212cc84ad69c0d8024f1b4c9eb5 (diff) | |
download | text.love-1c20d514f246903185b8df27dd3388e2147b7e5e.tar.gz |
bugfix
I'd wrapped currx in two conditionals, and not noticed that it gets reclaimed within the other. The hint is clearly more work than it's worth. Just take it out.
-rw-r--r-- | text.lua | 19 |
1 files changed, 3 insertions, 16 deletions
diff --git a/text.lua b/text.lua index 12f1b5d..b704b0d 100644 --- a/text.lua +++ b/text.lua @@ -226,7 +226,7 @@ function Text.keychord_pressed(chord) if Lines[new_cursor_line].mode == 'text' then local old_x = Text.cursor_x(Lines[new_cursor_line].data, Cursor_pos) Cursor_line = new_cursor_line - Cursor_pos = Text.nearest_cursor_pos(Lines[Cursor_line].data, old_x, Cursor_pos) + Cursor_pos = Text.nearest_cursor_pos(Lines[Cursor_line].data, old_x) break end end @@ -242,7 +242,7 @@ function Text.keychord_pressed(chord) if Lines[new_cursor_line].mode == 'text' then local old_x = Text.cursor_x(Lines[new_cursor_line].data, Cursor_pos) Cursor_line = new_cursor_line - Cursor_pos = Text.nearest_cursor_pos(Lines[Cursor_line].data, old_x, Cursor_pos) + Cursor_pos = Text.nearest_cursor_pos(Lines[Cursor_line].data, old_x) break end end @@ -336,7 +336,7 @@ end -- nearest_cursor_pos('gh', mx) = 2 -- Cursor_pos = 7 + 2 - 1 = 8 -function Text.nearest_cursor_pos(line, x, hint) +function Text.nearest_cursor_pos(line, x) if x == 0 then return 1 end @@ -345,20 +345,7 @@ function Text.nearest_cursor_pos(line, x, hint) if x > max_x then return len+1 end - 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, len+1 - if hint then - if currx > x then - right = hint - else - left = hint - end - end --? print('--') while true do local curr = math.floor((left+right)/2) |