diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2024-02-08 02:54:28 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2024-02-08 02:54:28 -0800 |
commit | 9d1bea29411b63509daeff5e873840069a379213 (patch) | |
tree | e578ac43677921c74eb43c5c93117928ff3e439f | |
parent | d27c03373ccf10e3f0ee7b4e613099062062036e (diff) | |
parent | 6b33c9e22310cd50c5e68b411e6473a8309ffe00 (diff) | |
download | view.love-9d1bea29411b63509daeff5e873840069a379213.tar.gz |
Merge text.love
-rw-r--r-- | source_text.lua | 2 | ||||
-rw-r--r-- | source_text_tests.lua | 12 | ||||
-rw-r--r-- | text.lua | 2 | ||||
-rw-r--r-- | text_tests.lua | 12 |
4 files changed, 14 insertions, 14 deletions
diff --git a/source_text.lua b/source_text.lua index b22d358..7c1838c 100644 --- a/source_text.lua +++ b/source_text.lua @@ -798,7 +798,7 @@ function Text.to_pos_on_line(State, line_index, mx, my) -- (The final screen line positions past end of screen line as always.) if screen_line_index < #line_cache.screen_line_starting_pos and mx > State.left + Text.screen_line_width(State, line_index, screen_line_index) then --? print('past end of non-final line; return') - return line_cache.screen_line_starting_pos[screen_line_index+1]-1 + return line_cache.screen_line_starting_pos[screen_line_index+1] end local s = string.sub(line.data, screen_line_starting_byte_offset) --? print('return', mx, Text.nearest_cursor_pos(State.font, s, mx, State.left), '=>', screen_line_starting_pos + Text.nearest_cursor_pos(State.font, s, mx, State.left) - 1) diff --git a/source_text_tests.lua b/source_text_tests.lua index c0edeab..6376ec8 100644 --- a/source_text_tests.lua +++ b/source_text_tests.lua @@ -485,9 +485,9 @@ function test_click_past_end_of_screen_line() y = y + Editor_state.line_height -- click past end of second screen line edit.run_after_mouse_click(Editor_state, App.screen.width-2,y-2, 1) - -- cursor moves to end of screen line + -- cursor moves to end of screen line (one more than final character shown) check_eq(Editor_state.cursor1.line, 1, 'cursor:line') - check_eq(Editor_state.cursor1.pos, 12, 'cursor:pos') + check_eq(Editor_state.cursor1.pos, 13, 'cursor:pos') end function test_click_on_wrapping_line_rendered_from_partway_at_top_of_screen() @@ -506,9 +506,9 @@ function test_click_on_wrapping_line_rendered_from_partway_at_top_of_screen() y = y + Editor_state.line_height -- click past end of second screen line edit.run_after_mouse_click(Editor_state, App.screen.width-2,y-2, 1) - -- cursor moves to end of screen line + -- cursor moves to end of screen line (one more than final character shown) check_eq(Editor_state.cursor1.line, 1, 'cursor:line') - check_eq(Editor_state.cursor1.pos, 12, 'cursor:pos') + check_eq(Editor_state.cursor1.pos, 13, 'cursor:pos') end function test_click_past_end_of_wrapping_line() @@ -576,8 +576,8 @@ function test_click_past_end_of_word_wrapping_line() y = y + Editor_state.line_height -- click past the end of the screen line edit.run_after_mouse_click(Editor_state, App.screen.width-2,y-2, 1) - -- cursor moves to end of screen line - check_eq(Editor_state.cursor1.pos, 20, 'cursor') + -- cursor moves to end of screen line (one more than final character shown) + check_eq(Editor_state.cursor1.pos, 21, 'cursor') end function test_select_text() diff --git a/text.lua b/text.lua index 0531044..ad86378 100644 --- a/text.lua +++ b/text.lua @@ -544,7 +544,7 @@ function Text.to_pos_on_line(State, line_index, mx, my) -- (The final screen line positions past end of screen line as always.) if screen_line_index < #line_cache.screen_line_starting_pos and mx > State.left + Text.screen_line_width(State, line_index, screen_line_index) then --? print('past end of non-final line; return') - return line_cache.screen_line_starting_pos[screen_line_index+1]-1 + return line_cache.screen_line_starting_pos[screen_line_index+1] end local s = string.sub(line.data, screen_line_starting_byte_offset) --? print('return', mx, Text.nearest_cursor_pos(State.font, s, mx, State.left), '=>', screen_line_starting_pos + Text.nearest_cursor_pos(State.font, s, mx, State.left) - 1) diff --git a/text_tests.lua b/text_tests.lua index a331f2b..541a056 100644 --- a/text_tests.lua +++ b/text_tests.lua @@ -421,9 +421,9 @@ function test_click_past_end_of_screen_line() y = y + Editor_state.line_height -- click past end of second screen line edit.run_after_mouse_click(Editor_state, App.screen.width-2,y-2, 1) - -- cursor moves to end of screen line + -- cursor moves to end of screen line (one more than final character shown) check_eq(Editor_state.cursor1.line, 1, 'cursor:line') - check_eq(Editor_state.cursor1.pos, 12, 'cursor:pos') + check_eq(Editor_state.cursor1.pos, 13, 'cursor:pos') end function test_click_on_wrapping_line_rendered_from_partway_at_top_of_screen() @@ -442,9 +442,9 @@ function test_click_on_wrapping_line_rendered_from_partway_at_top_of_screen() y = y + Editor_state.line_height -- click past end of second screen line edit.run_after_mouse_click(Editor_state, App.screen.width-2,y-2, 1) - -- cursor moves to end of screen line + -- cursor moves to end of screen line (one more than final character shown) check_eq(Editor_state.cursor1.line, 1, 'cursor:line') - check_eq(Editor_state.cursor1.pos, 12, 'cursor:pos') + check_eq(Editor_state.cursor1.pos, 13, 'cursor:pos') end function test_click_past_end_of_wrapping_line() @@ -512,8 +512,8 @@ function test_click_past_end_of_word_wrapping_line() y = y + Editor_state.line_height -- click past the end of the screen line edit.run_after_mouse_click(Editor_state, App.screen.width-2,y-2, 1) - -- cursor moves to end of screen line - check_eq(Editor_state.cursor1.pos, 20, 'cursor') + -- cursor moves to end of screen line (one more than final character shown) + check_eq(Editor_state.cursor1.pos, 21, 'cursor') end function test_select_text() |