about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--app.lua2
-rw-r--r--main.lua5
-rw-r--r--text.lua28
3 files changed, 23 insertions, 12 deletions
diff --git a/app.lua b/app.lua
index f14b0ec..bb463b7 100644
--- a/app.lua
+++ b/app.lua
@@ -93,7 +93,7 @@ end
 --     App.font{
 --       height=15
 --     }
---     App.run_after_keypress('pagedown')
+--     App.run_after_keychord('pagedown')
 --     App.check_screen_contents{
 --       y0='ghi'
 --       y15=''
diff --git a/main.lua b/main.lua
index e72a875..ca69be6 100644
--- a/main.lua
+++ b/main.lua
@@ -122,8 +122,10 @@ function App.draw()
   local y = 15
   if Debug_main then print('== draw') end
   for line_index,line in ipairs(Lines) do
+    print(y, line_index, line)
     if Debug_main then print('draw:', line_index, y) end
     if y + math.floor(15*Zoom) > App.screen.height then break end
+    print('a')
     if line_index >= Screen_top1.line then
       Screen_bottom1.line = line_index
       if line.mode == 'text' and line.data == '' then
@@ -226,12 +228,13 @@ function App.keychord_pressed(chord)
     end
     save_to_disk(Lines, Filename)
   elseif chord == 'pagedown' then
-    print('setting top to', Screen_bottom1.line)
     Screen_top1.line = Screen_bottom1.line
     Screen_top1.pos = Screen_bottom1.pos
+    print('setting top to', Screen_top1.line)
     Cursor1.line = Screen_top1.line
     Cursor1.pos = Screen_top1.pos
     Text.move_cursor_down_to_next_text_line_while_scrolling_again_if_necessary()
+    print('top now', Screen_top1.line)
   elseif chord == 'pageup' then
     -- duplicate some logic from love.draw
     local y = App.screen.height
diff --git a/text.lua b/text.lua
index 288d0f6..51d69db 100644
--- a/text.lua
+++ b/text.lua
@@ -9,6 +9,7 @@ local Debug_new_render = false
 --  y coordinate drawn until in px
 --  position of start of final screen line drawn
 function Text.draw(line, line_width, line_index)
+  print('text.draw')
   love.graphics.setColor(0,0,0)
   -- wrap long lines
   local x = 25
@@ -126,11 +127,11 @@ end
 function test_pagedown_skip_drawings()
   print('test_pagedown_skip_drawings')
   -- some lines of text with a drawing intermixed
-  App.screen.init{width=50, height=45}
-  Lines = load_array{'abc',
-                     '```lines', '```',
-                     'def',
-                     'ghi'}
+  App.screen.init{width=50, height=80}
+  Lines = load_array{'abc',               -- height 15
+                     '```lines', '```',   -- height 25
+                     'def',               -- height 15
+                     'ghi'}               -- height 15
   check_eq(Lines[2].mode, 'drawing', 'F - test_pagedown_skip_drawings/baseline/lines')
   Line_width = App.screen.width
   Cursor1 = {line=1, pos=1}
@@ -138,17 +139,19 @@ function test_pagedown_skip_drawings()
   Screen_bottom1 = {}
   Zoom = 1
   local screen_top_margin = 15  -- pixels
-  local drawing_height = App.screen.width / 2  -- default
-  -- initially the screen displays the first line and part of the drawing
+  local text height = 15
+  local drawing_height = 20 + App.screen.width / 2  -- default
+  -- initially the screen displays the first line and the drawing
+  -- 15px margin + 15px line1 + 10px margin + 25px drawing + 10px margin = 75px < screen height 80px
   App.draw()
   local y = screen_top_margin
   App.screen.check(y, 'abc', 'F - test_pagedown_skip_drawings/baseline/screen:1')
   -- after pagedown the screen draws the screen up top
+  -- 15px margin + 10px margin + 25px drawing + 10px margin + 15px line3 = 75px < screen height 80px
   App.run_after_keychord('pagedown')
+  print('test: top:', Screen_top1.line)
   y = screen_top_margin + drawing_height
   App.screen.check(y, 'def', 'F - test_pagedown_skip_drawings/screen:1')
-  y = y + line_height
-  App.screen.check(y, 'ghi', 'F - test_pagedown_skip_drawings/screen:2')
 end
 
 function Text.compute_fragments(line, line_width)
@@ -418,10 +421,13 @@ function Text.cursor_at_final_screen_line()
 end
 
 function Text.move_cursor_down_to_next_text_line_while_scrolling_again_if_necessary()
+  local y = 15  -- top margin
   while Cursor1.line <= #Lines do
     if Lines[Cursor1.line].mode == 'text' then
       break
     end
+    print('cursor skips', Cursor1.line)
+    y = y + 20 + Drawing.pixels(Lines[Cursor1.line].h)
     Cursor1.line = Cursor1.line + 1
   end
   -- hack: insert a text line at bottom of file if necessary
@@ -429,7 +435,9 @@ function Text.move_cursor_down_to_next_text_line_while_scrolling_again_if_necess
     assert(Cursor1.line == #Lines+1)
     table.insert(Lines, {mode='text', data=''})
   end
-  if Cursor1.line > Screen_bottom1.line then
+--?   print(y, App.screen.height, App.screen.height-math.floor(15*Zoom))
+  if y > App.screen.height - math.floor(15*Zoom) then
+--?   if Cursor1.line > Screen_bottom1.line then
     print('scroll up')
     Screen_top1.line = Cursor1.line
     Text.scroll_up_while_cursor_on_screen()