about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-05-20 21:30:49 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-05-20 21:30:59 -0700
commita3f72abbdeac2d251c4221f1cb42896587afd60b (patch)
tree1e23f45e6ccc9282945785c7e536c8cef468f90b
parent6b91c0688ea9c63b865c2f8cf6578eef488aaad8 (diff)
downloadview.love-a3f72abbdeac2d251c4221f1cb42896587afd60b.tar.gz
reduce ambitions a bit: page up/down need not start screen from the middle of a line
But we still have work to do for cursor up/down.
-rw-r--r--main.lua27
-rw-r--r--text.lua10
2 files changed, 17 insertions, 20 deletions
diff --git a/main.lua b/main.lua
index 3960094..1bbd7f7 100644
--- a/main.lua
+++ b/main.lua
@@ -38,7 +38,7 @@ require 'icons'
 -- once, and read them passively thereafter.
 Lines = {{mode='text', data=''}}
 Cursor_line = 1
-Cursor_pos = 15  -- in Unicode codepoints, from 1 to utf8.len(line) + 1
+Cursor_pos = 1  -- in Unicode codepoints, from 1 to utf8.len(line) + 1
 
 Screen_width, Screen_height, Screen_flags = 0, 0, nil
 
@@ -47,8 +47,7 @@ Cursor_x, Cursor_y = 0, 0  -- in pixels
 -- scrolling support
 Screen_top_line = 1
 Screen_bottom_line = 1
-Top_screen_line_starting_pos = 6  -- when top of screen starts in between a wrapped line
-Bottom_screen_line_starting_pos = 1  -- when bottom of screen starts in between a wrapped line
+Top_screen_line_starting_pos = 1  -- when top of screen starts in between a wrapped line
 
 Current_drawing_mode = 'line'
 Previous_drawing_mode = nil
@@ -61,17 +60,18 @@ Filename = love.filesystem.getUserDirectory()..'/lines.txt'
 
 function love.load(arg)
   -- maximize window
---?   love.window.setMode(0, 0)  -- maximize
---?   Screen_width, Screen_height, Screen_flags = love.window.getMode()
---?   -- shrink slightly to account for window decoration
---?   Screen_width = Screen_width-100
---?   Screen_height = Screen_height-100
-  Screen_width = 120
-  Screen_height = 200
+  love.window.setMode(0, 0)  -- maximize
+  Screen_width, Screen_height, Screen_flags = love.window.getMode()
+  -- shrink slightly to account for window decoration
+  Screen_width = Screen_width-100
+  Screen_height = Screen_height-100
+  -- for testing line wrap
+--?   Screen_width = 120
+--?   Screen_height = 200
   love.window.setMode(Screen_width, Screen_height)
   love.window.setTitle('Text with Lines')
-  Line_width = 100
---?   Line_width = math.floor(Screen_width/2/40)*40
+--?   Line_width = 100
+  Line_width = math.floor(Screen_width/2/40)*40
   love.keyboard.setTextInput(true)  -- bring up keyboard on touch screen
   love.keyboard.setKeyRepeat(true)
   if #arg > 0 then
@@ -178,7 +178,8 @@ function keychord_pressed(chord)
   elseif chord == 'pagedown' then
     Screen_top_line = Screen_bottom_line
     Cursor_line = Screen_top_line
-    Cursor_pos = 1
+    Top_screen_line_starting_pos = 1
+    Cursor_pos = Top_screen_line_starting_pos
     Text.move_cursor_down_to_next_text_line_while_scrolling_again_if_necessary()
   elseif chord == 'pageup' then
     -- duplicate some logic from love.draw
diff --git a/text.lua b/text.lua
index 6aa2eba..c94d8ce 100644
--- a/text.lua
+++ b/text.lua
@@ -26,13 +26,6 @@ function Text.draw(line, line_width, line_index)
         y = y + math.floor(15*Zoom)
         if New_render then print('y', y) end
       end
-      if y > Screen_height then
-        if line.screen_line_starting_pos then
-          Bottom_screen_line_starting_pos = line.screen_line_starting_pos[#line.screen_line_starting_pos]
-        else
-          Bottom_screen_line_starting_pos = 1
-        end
-      end
       x = 25
       if line.screen_line_starting_pos == nil then
         line.screen_line_starting_pos = {1, pos}
@@ -294,8 +287,11 @@ function Text.keychord_pressed(chord)
         end
       end
       if Cursor_line > Screen_bottom_line then
+        print('screen top before:', Screen_top_line, Top_screen_line_starting_pos)
         Screen_top_line = Cursor_line
+        print('scroll up preserving cursor')
         Text.scroll_up_while_cursor_on_screen()
+        print('screen top after:', Screen_top_line, Top_screen_line_starting_pos)
       end
     else
       -- move down one screen line in current line