about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-05-21 20:52:44 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-05-21 20:52:44 -0700
commit1e63bf0e0a58860bbdf9fce02f551c2d00fa2c0f (patch)
tree63a88d01376106a0fc62e5f5647528a516f94ba5
parent6550a4c6d7d23d7769142b3d86eaa8f70f216970 (diff)
downloadlines.love-1e63bf0e0a58860bbdf9fce02f551c2d00fa2c0f.tar.gz
I feel confident now that page-down is working.
-rw-r--r--main.lua5
-rw-r--r--text.lua10
2 files changed, 12 insertions, 3 deletions
diff --git a/main.lua b/main.lua
index 3da6a57..f6f5cfe 100644
--- a/main.lua
+++ b/main.lua
@@ -141,11 +141,12 @@ function love.draw()
         y = y + Drawing.pixels(line.h) + 10 -- padding
       else
         line.y = y
-        y = Text.draw(line, Line_width, line_index)
+        y, Screen_bottom1.pos = Text.draw(line, Line_width, line_index)
         y = y + math.floor(15*Zoom)  -- text height
       end
     end
   end
+--?   print('screen bottom: '..tostring(Screen_bottom1.pos)..' in '..tostring(Lines[Screen_bottom1.line].data))
 --?   os.exit(1)
 end
 
@@ -216,7 +217,7 @@ function keychord_pressed(chord)
     save_to_disk(Lines, Filename)
   elseif chord == 'pagedown' then
     Screen_top1.line = Screen_bottom1.line
-    Screen_top1.pos = 1
+    Screen_top1.pos = Screen_bottom1.pos
     Cursor1.line = Screen_top1.line
     Cursor1.pos = Screen_top1.pos
     Text.move_cursor_down_to_next_text_line_while_scrolling_again_if_necessary()
diff --git a/text.lua b/text.lua
index 83e185b..e45d174 100644
--- a/text.lua
+++ b/text.lua
@@ -5,12 +5,16 @@ local utf8 = require 'utf8'
 
 local Debug_new_render = false
 
+-- return values:
+--  y coordinate drawn until in px
+--  position of start of final screen line drawn
 function Text.draw(line, line_width, line_index)
   love.graphics.setColor(0,0,0)
   -- wrap long lines
   local x = 25
   local y = line.y
   local pos = 1
+  local screen_line_starting_pos = 1
   if line.fragments == nil then
     Text.compute_fragments(line, line_width)
   end
@@ -24,6 +28,10 @@ function Text.draw(line, line_width, line_index)
       assert(x > 25)  -- no overfull lines
       if line_index > Screen_top1.line or pos > Screen_top1.pos then
         y = y + math.floor(15*Zoom)
+        if y + math.floor(15*Zoom) > Screen_height then
+          return y, screen_line_starting_pos
+        end
+        screen_line_starting_pos = pos
         if Debug_new_render then print('y', y) end
       end
       x = 25
@@ -52,7 +60,7 @@ function Text.draw(line, line_width, line_index)
     Text.draw_cursor(x, y)
   end
   Debug_new_render = false
-  return y
+  return y, screen_line_starting_pos
 end
 -- manual tests:
 --  draw with small line_width of 100