about summary refs log tree commit diff stats
path: root/text.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-05-20 22:18:39 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-05-20 22:18:39 -0700
commite420245ee316f540ed968877c929e2630d2a849c (patch)
treed3e8298c9d4f038309bd15b169c091acce619ddc /text.lua
parente3dc4c330b3d78aa2f1a360ce931974ef7b277d1 (diff)
downloadtext.love-e420245ee316f540ed968877c929e2630d2a849c.tar.gz
keep cursor on screen when pressing 'down'
Diffstat (limited to 'text.lua')
-rw-r--r--text.lua6
1 files changed, 4 insertions, 2 deletions
diff --git a/text.lua b/text.lua
index 4f1baf9..48e9398 100644
--- a/text.lua
+++ b/text.lua
@@ -3,7 +3,7 @@ Text = {}
 
 local utf8 = require 'utf8'
 
-local Debug_new_render = true
+local Debug_new_render = false
 
 function Text.draw(line, line_width, line_index)
   love.graphics.setColor(0,0,0)
@@ -123,7 +123,7 @@ end
 
 -- Don't handle any keys here that would trigger love.textinput above.
 function Text.keychord_pressed(chord)
-  Debug_new_render = true
+--?   Debug_new_render = true
   if chord == 'return' then
     local byte_offset = utf8.offset(Lines[Cursor_line].data, Cursor_pos)
     table.insert(Lines, Cursor_line+1, {mode='text', data=string.sub(Lines[Cursor_line].data, byte_offset)})
@@ -286,6 +286,7 @@ function Text.keychord_pressed(chord)
           break
         end
       end
+      print(Cursor_line, Cursor_pos, Screen_bottom_line)
       if Cursor_line > Screen_bottom_line then
         print('screen top before:', Screen_top_line, Top_screen_line_starting_pos)
         Screen_top_line = Cursor_line
@@ -302,6 +303,7 @@ function Text.keychord_pressed(chord)
       local s = string.sub(Lines[Cursor_line].data, new_screen_line_starting_pos)
       Cursor_pos = new_screen_line_starting_pos + Text.nearest_cursor_pos(s, Cursor_x) - 1
       print('cursor pos is now '..tostring(Cursor_pos))
+      Screen_top_line = Cursor_line
       Text.scroll_up_while_cursor_on_screen()
     end
   end