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-07-17 22:15:49 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-07-17 22:29:37 -0700
commit82cdd9ddd17f2ba1a637232fe22f790c5a769728 (patch)
tree0a31556e0cf705911bb9d2c9e4fcba36276b0720 /text_tests.lua
parent29dac6a6eccf5e5f09debe789fb4f314e460088b (diff)
downloadtext.love-82cdd9ddd17f2ba1a637232fe22f790c5a769728.tar.gz
bugfix: couple of margin-relative computations
Diffstat (limited to 'text_tests.lua')
-rw-r--r--text_tests.lua62
1 files changed, 61 insertions, 1 deletions
diff --git a/text_tests.lua b/text_tests.lua
index 37deec9..e9741c9 100644
--- a/text_tests.lua
+++ b/text_tests.lua
@@ -265,10 +265,31 @@ function test_click_with_mouse()
   edit.draw(Editor_state)
   edit.run_after_mouse_click(Editor_state, Editor_state.left+8,Editor_state.top+5, 1)
   -- cursor moves
-  check_eq(Editor_state.cursor1.line, 1, 'F - test_click_with_mouse/cursor')
+  check_eq(Editor_state.cursor1.line, 1, 'F - test_click_with_mouse/cursor:line')
+  check_eq(Editor_state.cursor1.pos, 2, 'F - test_click_with_mouse/cursor:pos')
   check_nil(Editor_state.selection1.line, 'F - test_click_with_mouse/selection is empty to avoid perturbing future edits')
 end
 
+function test_click_with_mouse_takes_margins_into_account()
+  io.write('\ntest_click_with_mouse_takes_margins_into_account')
+  -- display two lines with cursor on one of them
+  App.screen.init{width=100, height=80}
+  Editor_state = edit.initialize_test_state()
+  Editor_state.left = 50  -- occupy only right side of screen
+  Editor_state.lines = load_array{'abc', 'def'}
+  Text.redraw_all(Editor_state)
+  Editor_state.cursor1 = {line=2, pos=1}
+  Editor_state.screen_top1 = {line=1, pos=1}
+  Editor_state.screen_bottom1 = {}
+  -- click on the other line
+  edit.draw(Editor_state)
+  edit.run_after_mouse_click(Editor_state, Editor_state.left+8,Editor_state.top+5, 1)
+  -- cursor moves
+  check_eq(Editor_state.cursor1.line, 1, 'F - test_click_with_mouse_takes_margins_into_account/cursor:line')
+  check_eq(Editor_state.cursor1.pos, 2, 'F - test_click_with_mouse_takes_margins_into_account/cursor:pos')
+  check_nil(Editor_state.selection1.line, 'F - test_click_with_mouse_takes_margins_into_account/selection is empty to avoid perturbing future edits')
+end
+
 function test_click_with_mouse_on_empty_line()
   io.write('\ntest_click_with_mouse_on_empty_line')
   -- display two lines with the first one empty
@@ -340,6 +361,45 @@ function test_draw_word_wrapping_text()
   App.screen.check(y, 'ghi', 'F - test_draw_word_wrapping_text/screen:3')
 end
 
+function test_click_with_mouse_on_wrapping_line()
+  io.write('\ntest_click_with_mouse_on_wrapping_line')
+  -- display two lines with cursor on one of them
+  App.screen.init{width=50, height=80}
+  Editor_state = edit.initialize_test_state()
+  Editor_state.lines = load_array{'abc def ghi jkl mno pqr stu'}
+  Text.redraw_all(Editor_state)
+  Editor_state.cursor1 = {line=1, pos=20}
+  Editor_state.screen_top1 = {line=1, pos=1}
+  Editor_state.screen_bottom1 = {}
+  -- click on the other line
+  edit.draw(Editor_state)
+  edit.run_after_mouse_click(Editor_state, Editor_state.left+8,Editor_state.top+5, 1)
+  -- cursor moves
+  check_eq(Editor_state.cursor1.line, 1, 'F - test_click_with_mouse_on_wrapping_line/cursor:line')
+  check_eq(Editor_state.cursor1.pos, 2, 'F - test_click_with_mouse_on_wrapping_line/cursor:pos')
+  check_nil(Editor_state.selection1.line, 'F - test_click_with_mouse_on_wrapping_line/selection is empty to avoid perturbing future edits')
+end
+
+function test_click_with_mouse_on_wrapping_line_takes_margins_into_account()
+  io.write('\ntest_click_with_mouse_on_wrapping_line_takes_margins_into_account')
+  -- display two lines with cursor on one of them
+  App.screen.init{width=100, height=80}
+  Editor_state = edit.initialize_test_state()
+  Editor_state.left = 50  -- occupy only right side of screen
+  Editor_state.lines = load_array{'abc def ghi jkl mno pqr stu'}
+  Text.redraw_all(Editor_state)
+  Editor_state.cursor1 = {line=1, pos=20}
+  Editor_state.screen_top1 = {line=1, pos=1}
+  Editor_state.screen_bottom1 = {}
+  -- click on the other line
+  edit.draw(Editor_state)
+  edit.run_after_mouse_click(Editor_state, Editor_state.left+8,Editor_state.top+5, 1)
+  -- cursor moves
+  check_eq(Editor_state.cursor1.line, 1, 'F - test_click_with_mouse_on_wrapping_line_takes_margins_into_account/cursor:line')
+  check_eq(Editor_state.cursor1.pos, 2, 'F - test_click_with_mouse_on_wrapping_line_takes_margins_into_account/cursor:pos')
+  check_nil(Editor_state.selection1.line, 'F - test_click_with_mouse_on_wrapping_line_takes_margins_into_account/selection is empty to avoid perturbing future edits')
+end
+
 function test_draw_text_wrapping_within_word()
   -- arrange a screen line that needs to be split within a word
   io.write('\ntest_draw_text_wrapping_within_word')