about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-06-20 12:02:51 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-06-20 12:02:51 -0700
commit7508a70ed5cb57beec1a69b996caf5375a446077 (patch)
treecdc142ee1427861de90f486993a9ff66575118af
parentc1b6bac187cf8597da3cc0d3dc1caa269d3c13c5 (diff)
downloadtext.love-7508a70ed5cb57beec1a69b996caf5375a446077.tar.gz
selection bugfix
-rw-r--r--main.lua2
-rw-r--r--text_tests.lua18
2 files changed, 19 insertions, 1 deletions
diff --git a/main.lua b/main.lua
index 270e0b7..b1b0bd8 100644
--- a/main.lua
+++ b/main.lua
@@ -551,7 +551,7 @@ function App.keychord_pressed(chord)
     for _,line in ipairs(Lines) do line.y = nil end  -- just in case we scroll
     Text.keychord_pressed(chord)
   end
-  if not App.shift_down() then
+  if not App.shift_down() and chord ~= 'C-c' then
     Selection1 = {}
   end
 end
diff --git a/text_tests.lua b/text_tests.lua
index 7c0ce7d..0fbe98c 100644
--- a/text_tests.lua
+++ b/text_tests.lua
@@ -243,6 +243,24 @@ function test_edit_deletes_selection()
   check_eq(Lines[1].data, 'xbc', 'F - test_edit_deletes_selection')
 end
 
+function test_copy_does_not_reset_selection()
+  io.write('\ntest_copy_does_not_reset_selection')
+  -- display a line of text with a selection
+  App.screen.init{width=80, height=80}
+  Lines = load_array{'abc'}
+  Line_width = 75
+  Cursor1 = {line=1, pos=1}
+  Selection1 = {line=1, pos=2}
+  Screen_top1 = {line=1, pos=1}
+  Screen_bottom1 = {}
+  App.draw()
+  -- copy selection
+  App.run_after_keychord('C-c')
+  check_eq(App.clipboard, 'a', 'F - test_copy_does_not_reset_selection/clipboard')
+  -- selection is reset since shift key is not pressed
+  check(Selection1.line, 'F - test_copy_does_not_reset_selection')
+end
+
 function test_edit_wrapping_text()
   io.write('\ntest_edit_wrapping_text')
   App.screen.init{width=50, height=60}