about summary refs log tree commit diff stats
path: root/text_tests.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-06-13 17:23:21 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-06-14 08:02:25 -0700
commite20935ad7a6a18e901200eac1ac7cdcedcc7a1dc (patch)
tree6c365831238ec56f209026d9c6fb25cfcf0a888e /text_tests.lua
parent9b0577f79eb87be1d2f3a8af09dc9830b14e63c1 (diff)
downloadlines.love-e20935ad7a6a18e901200eac1ac7cdcedcc7a1dc.tar.gz
bugfix
manifestation: clicking past end of a long, wrapping line containing
non-ASCII would cause the cursor to disappear rather than position past
end of screen line. Hitting enter would then throw an assertion with the
following stack trace:

  Error: text.lua:381: bad argument #2 to 'sub' (number expected, got nil)
  stack traceback:
    [love "boot.lua"]:345: in function <[love "boot.lua"]:341>
    [C]: in function 'sub'
    text.lua:381: in function 'insert_return'
    text.lua:179: in function 'keychord_pressed'
    main.lua:495: in function 'keychord_pressed'
    keychord.lua:10: in function <keychord.lua:5>
    app.lua:34: in function <app.lua:25>
    [C]: in function 'xpcall'

cause: the click caused a call to Text.to_pos_on_line whose result was
not on a UTF-8 character boundary.

fix: make to_pos_on_line utf8-aware.
Diffstat (limited to 'text_tests.lua')
-rw-r--r--text_tests.lua25
1 files changed, 25 insertions, 0 deletions
diff --git a/text_tests.lua b/text_tests.lua
index 8aa7085..676b139 100644
--- a/text_tests.lua
+++ b/text_tests.lua
@@ -127,6 +127,31 @@ function test_draw_wrapping_text_containing_non_ascii()
   App.screen.check(y, 'm ad', 'F - test_draw_wrapping_text_containing_non_ascii/screen:3')
 end
 
+function test_click_on_wrapping_line_containing_non_ascii()
+  io.write('\ntest_click_on_wrapping_line_containing_non_ascii')
+  -- display a wrapping line containing non-ASCII
+  App.screen.init{width=80, height=80}
+                  --  12345678901234
+  Lines = load_array{'madam I’m adam'}  -- notice the non-ASCII apostrophe
+  Line_width = 75
+  Cursor1 = {line=1, pos=1}
+  Screen_top1 = {line=1, pos=1}
+  Screen_bottom1 = {}
+  App.draw()
+  local y = Margin_top
+  App.screen.check(y, 'madam ', 'F - test_click_on_wrapping_line_containing_non_ascii/baseline/screen:1')
+  y = y + Line_height
+  App.screen.check(y, 'I’m ada', 'F - test_click_on_wrapping_line_containing_non_ascii/baseline/screen:2')
+  y = y + Line_height
+  App.screen.check(y, 'm', 'F - test_click_on_wrapping_line_containing_non_ascii/baseline/screen:3')
+  y = y + Line_height
+  -- click past the end of it
+  App.draw()
+  App.run_after_mouse_click(App.screen.width-2,y-2, '1')
+  -- cursor moves to end of line
+  check_eq(Cursor1.pos, 15, 'F - test_click_on_wrapping_line_containing_non_ascii/cursor')  -- one more than the number of UTF-8 code-points
+end
+
 function test_edit_wrapping_text()
   io.write('\ntest_edit_wrapping_text')
   App.screen.init{width=50, height=60}