about summary refs log tree commit diff stats
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
parente3dc4c330b3d78aa2f1a360ce931974ef7b277d1 (diff)
downloadtext.love-e420245ee316f540ed968877c929e2630d2a849c.tar.gz
keep cursor on screen when pressing 'down'
-rw-r--r--main.lua2
-rw-r--r--text.lua6
2 files changed, 5 insertions, 3 deletions
diff --git a/main.lua b/main.lua
index 1bbd7f7..63f80e3 100644
--- a/main.lua
+++ b/main.lua
@@ -111,7 +111,7 @@ function love.draw()
   end
   local y = 15
   for line_index,line in ipairs(Lines) do
-    if y > Screen_height then break end
+    if y + math.floor(15*Zoom) > Screen_height then break end
     if line_index >= Screen_top_line then
       Screen_bottom_line = line_index
       if line.mode == 'text' and line.data == '' then
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