about summary refs log tree commit diff stats
path: root/text.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-07-05 11:27:41 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-07-05 11:27:41 -0700
commit4575648c12beba741b858b2fcdf1a195717e9d2e (patch)
tree38986077cbd967facb8a675c0f858a2f40338fda /text.lua
parentf2e5c4ffee3352268750861bd995386e1a47ecd5 (diff)
downloadtext.love-4575648c12beba741b858b2fcdf1a195717e9d2e.tar.gz
optimization: moving cursor to next word
Diffstat (limited to 'text.lua')
-rw-r--r--text.lua16
1 files changed, 12 insertions, 4 deletions
diff --git a/text.lua b/text.lua
index 4072311..d2c9466 100644
--- a/text.lua
+++ b/text.lua
@@ -529,13 +529,16 @@ end
 
 function Text.word_right()
   while true do
-    Text.right()
+    Text.right_without_scroll()
     if Cursor1.pos > utf8.len(Lines[Cursor1.line].data) then break end
     local offset = Text.offset(Lines[Cursor1.line].data, Cursor1.pos)
     if Lines[Cursor1.line].data:sub(offset,offset) == ' ' then  -- TODO: other space characters
       break
     end
   end
+  if Text.cursor_past_screen_bottom() then
+    Text.snap_cursor_to_bottom_of_screen()
+  end
 end
 
 function Text.left()
@@ -561,6 +564,13 @@ function Text.left()
 end
 
 function Text.right()
+  Text.right_without_scroll()
+  if Text.cursor_past_screen_bottom() then
+    Text.snap_cursor_to_bottom_of_screen()
+  end
+end
+
+function Text.right_without_scroll()
   assert(Lines[Cursor1.line].mode == 'text')
   if Cursor1.pos <= utf8.len(Lines[Cursor1.line].data) then
     Cursor1.pos = Cursor1.pos+1
@@ -575,9 +585,6 @@ function Text.right()
       end
     end
   end
-  if Text.cursor_past_screen_bottom() then
-    Text.snap_cursor_to_bottom_of_screen()
-  end
 end
 
 function Text.pos_at_start_of_cursor_screen_line()
@@ -620,6 +627,7 @@ function Text.move_cursor_down_to_next_text_line_while_scrolling_again_if_necess
   end
 end
 
+-- should never modify Cursor1
 function Text.snap_cursor_to_bottom_of_screen()
   local top2 = Text.to2(Cursor1)
   top2.screen_pos = 1  -- start of screen line