about summary refs log tree commit diff stats
path: root/text.lua
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 /text.lua
parent978c1433976a72193a33dc9f2f52e514fce9db41 (diff)
downloadtext.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.
Diffstat (limited to 'text.lua')
-rw-r--r--text.lua15
1 files changed, 11 insertions, 4 deletions
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()