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-20 11:25:00 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-06-20 11:31:14 -0700
commit3986e99fe0586e35a0c649114a07e6dd90f769fc (patch)
tree240a7e744e8566905d28dd93ad123f4e9db073d3 /text_tests.lua
parent3be413602a59ed735a33712380cedbdb8f5603df (diff)
downloadtext.love-3986e99fe0586e35a0c649114a07e6dd90f769fc.tar.gz
no, that's not right
Bugfix: we want selections to persist even when we lift up the shift
key.

This requires hoisting some code inside every case inside the whole
keypress hierarchy, to ensure we never clear selections before
textinput events can handle them.

Current cross-cutting concerns we're explicitly scattering code for.
  - autosave
  - undo
  - selection management
Diffstat (limited to 'text_tests.lua')
-rw-r--r--text_tests.lua22
1 files changed, 22 insertions, 0 deletions
diff --git a/text_tests.lua b/text_tests.lua
index 95fbd78..7c0ce7d 100644
--- a/text_tests.lua
+++ b/text_tests.lua
@@ -186,6 +186,28 @@ function test_click_on_wrapping_line_containing_non_ascii()
   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_select_text()
+  io.write('\ntest_select_text')
+  -- display a line of text
+  App.screen.init{width=80, height=80}
+  Lines = load_array{'abc def'}
+  Line_width = 75
+  Cursor1 = {line=1, pos=1}
+  Screen_top1 = {line=1, pos=1}
+  Screen_bottom1 = {}
+  App.draw()
+  -- select a letter
+  App.fake_key_press('lshift')
+  App.run_after_keychord('S-right')
+  App.fake_key_release('lshift')
+  App.keyreleased('lshift')
+  -- selection persists even after shift is released
+  check_eq(Selection1.line, 1, 'F - test_select_text/selection:line')
+  check_eq(Selection1.pos, 1, 'F - test_select_text/selection:pos')
+  check_eq(Cursor1.line, 1, 'F - test_select_text/cursor:line')
+  check_eq(Cursor1.pos, 2, 'F - test_select_text/cursor:pos')
+end
+
 function test_edit_after_click_resets_selection()
   io.write('\ntest_edit_after_click_resets_selection')
   -- display a line of text