about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-06-20 13:12:29 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-06-20 13:12:29 -0700
commit0d1e6aacd954146209b944f2bebc8033bcb13c23 (patch)
tree8c4ce88415e11bc84ad4391fc9cac8c341cff7d5
parent978c1433976a72193a33dc9f2f52e514fce9db41 (diff)
downloadlines.love-0d1e6aacd954146209b944f2bebc8033bcb13c23.tar.gz
revert selection logic to before commit 3ffc2ed8f
We still have a failing test, but now it's the one we introduced in
commit 3ffc2ed8f.
-rw-r--r--main.lua4
-rw-r--r--text.lua15
-rw-r--r--text_tests.lua1
3 files changed, 12 insertions, 8 deletions
diff --git a/main.lua b/main.lua
index b1b0bd8..712d44c 100644
--- a/main.lua
+++ b/main.lua
@@ -391,7 +391,6 @@ function App.mousereleased(x,y, button)
   end
 end
 
--- don't depend on state of Selection1; use keychord_pressed for that
 function App.textinput(t)
   for _,line in ipairs(Lines) do line.y = nil end  -- just in case we scroll
   if Search_term then
@@ -551,9 +550,6 @@ 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() and chord ~= 'C-c' then
-    Selection1 = {}
-  end
 end
 
 function App.keyreleased(key, scancode)
diff --git a/text.lua b/text.lua
index a3dd4c1..8753a7b 100644
--- a/text.lua
+++ b/text.lua
@@ -137,12 +137,14 @@ function Text.compute_fragments(line, line_width)
   end
 end
 
--- don't depend on state of Selection1; use keychord_pressed for that
 function Text.textinput(t)
   if App.mouse_down(1) then return end
   assert(not App.ctrl_down())
   if App.alt_down() then return end
   assert(not App.cmd_down())
+  if Selection1.line then
+    Text.delete_selection()
+  end
   local before = snapshot(Cursor1.line)
 --?   print(Screen_top1.line, Screen_top1.pos, Cursor1.line, Cursor1.pos, Screen_bottom1.line, Screen_bottom1.pos)
   Text.insert_at_cursor(t)
@@ -267,8 +269,10 @@ function Text.keychord_pressed(chord)
   --== shortcuts that move the cursor
   elseif chord == 'left' then
     Text.left()
+    Selection1 = {}
   elseif chord == 'right' then
     Text.right()
+    Selection1 = {}
   elseif chord == 'S-left' then
     if Selection1.line == nil then
       Selection1 = {line=Cursor1.line, pos=Cursor1.pos}
@@ -282,8 +286,10 @@ function Text.keychord_pressed(chord)
   -- C- hotkeys reserved for drawings, so we'll use M-
   elseif chord == 'M-left' then
     Text.word_left()
+    Selection1 = {}
   elseif chord == 'M-right' then
     Text.word_right()
+    Selection1 = {}
   elseif chord == 'M-S-left' then
     if Selection1.line == nil then
       Selection1 = {line=Cursor1.line, pos=Cursor1.pos}
@@ -310,8 +316,10 @@ function Text.keychord_pressed(chord)
     Cursor1.pos = utf8.len(Lines[Cursor1.line].data) + 1
   elseif chord == 'up' then
     Text.up()
+    Selection1 = {}
   elseif chord == 'down' then
     Text.down()
+    Selection1 = {}
   elseif chord == 'S-up' then
     if Selection1.line == nil then
       Selection1 = {line=Cursor1.line, pos=Cursor1.pos}
@@ -324,8 +332,10 @@ function Text.keychord_pressed(chord)
     Text.down()
   elseif chord == 'pageup' then
     Text.pageup()
+    Selection1 = {}
   elseif chord == 'pagedown' then
     Text.pagedown()
+    Selection1 = {}
   elseif chord == 'S-pageup' then
     if Selection1.line == nil then
       Selection1 = {line=Cursor1.line, pos=Cursor1.pos}
@@ -337,9 +347,6 @@ function Text.keychord_pressed(chord)
     end
     Text.pagedown()
   end
-  if Selection1.line and not App.shift_down() then
-    Text.delete_selection()
-  end
 end
 
 function Text.insert_return()
diff --git a/text_tests.lua b/text_tests.lua
index 93881ea..4221aa6 100644
--- a/text_tests.lua
+++ b/text_tests.lua
@@ -1335,6 +1335,7 @@ function test_undo_restores_selection()
   check_nil(Selection1.line, 'F - test_undo_restores_selection/baseline:selection')
   -- undo
   App.run_after_keychord('C-z')
+  App.run_after_keychord('C-z')
   -- selection is restored
   check_eq(Selection1.line, 1, 'F - test_undo_restores_selection/line')
   check_eq(Selection1.pos, 2, 'F - test_undo_restores_selection/pos')