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.
4VKEE43Z7MUPNIAOCK36INVBNHRTSWRRN37TIKRPXPH3DRKGHHAQC
U52E2XZNDEMIX5QJC6TREX5BSLNYG23Y4XQVFFKS6OFB2KIBW7BAC
MHOUX5JFGBFYMOULX3NZA2JXH6PF2227DT54EEXLBUZQFO7NDI2AC
J2SVGR2EQEROXDDMYZOCELD2VDYQALGZYRSZ4WGMTACAGMRPJ7UAC
RMKMPFT5L67WIFWIO4GTC6XESX6UPKNL4GPNQLOBC5CXSUZABEHQC
GCEF4N3VW2JFTWVXU2ND5XA63BNTMEGRBQQXYA3HULAKGYOYJP7AC
LXTTOB33N2HCUZFIUDRQGGBVHK2HODRG4NBLH6RXRQZDCHF27BSAC
3TFEAQSWVFGSH3ISZ4Q3DFR3YPPWHEIBUEVR3XWB7QX6VKHW455QC
XOAHJ6M3QKHSE5F7ICLPXN3RMH7JQEZXDKTOTIOBYKJFVT6PMYRAC
BULPIBEGL7TMK6CVIE7IS7WGAHGOSUJBGJSFQK542MOWGHP2ADQQC
GN3IF4WF352YK5K4YHVMAIMPL7PNTCEMDWW22PTKDOXKV2FZJ7NQC
5FW7YOFTLKHRND6IOR4HG4X3C5BO2WV5KTEUW3PPKCRU5L5GXKXQC
5L7K4GBDEAFH44LMLNKVFMHLWDNXXBKRPEI347VE5ZLXVFSMD2FAC
HOSPP2ANSW654DYRTC6CQUQA2GUKV6T2FI7QBKXD2DZS3R32IMGAC
BOFNXP5GZDCUMQG3LQVTSSFEQP7REQ4RIRJLDLETFSAGFTVDVEKAC
R53OF3ONKT5VL5BGK63YSN6GXIIAVNYDG4UMHITK72WXFWPJ25MQC
73OCE2MCBJJZZMN2KYPJTBOUCKBZAOQ2QIAMTGCNOOJ2AJAXFT2AC
OTIBCAUJ3KDQJLVDN3A536DLZGNRYMGJLORZVR3WLCGXGO6UGO6AC
AJB4LFRBMIRBEDWJ3OW7GQIMD2BZBVQ62GH4TE2FISWZKSAHRF4QC
R6GUSTBY5ZHR7E46DSIDQDNZDJI6QMZQDC7RPQMQWLGWQKXU6HVQC
NEXUNNCF5PJC57XAMQGMSSYNI7MJ4ARWDY3HFGVYMGWG3MPHG7CQC
Z4XRNDTRTGSZHNB65WNHOVUBFW4QWQABLVSK4RM3QJHGK33DMRJAC
QZH3PQFUBL2ISJBJ4PBALVKUPKQ4QKGNKSFASEXWYB5J7ODL42KQC
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
local s = string.sub(line.data, screen_line_starting_pos)
local screen_line_starting_byte_offset = utf8.offset(line.data, screen_line_starting_pos)
assert(screen_line_starting_byte_offset)
local s = string.sub(line.data, screen_line_starting_byte_offset)
--? print('return', mx, Text.nearest_cursor_pos(s, mx), '=>', screen_line_starting_pos + Text.nearest_cursor_pos(s, mx) - 1)