about summary refs log tree commit diff stats
path: root/text.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-06-04 14:55:52 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-06-04 14:55:52 -0700
commitfa267e25e600a875696b6ab972b72515fa71e20a (patch)
treee08e70387ef93f6b7b10a8e3f911a96ff3e1c690 /text.lua
parent1326914d7bda65a5791c2121dae6d3987a907994 (diff)
downloadview.love-fa267e25e600a875696b6ab972b72515fa71e20a.tar.gz
experiment: slightly adaptive scrolling
When long wrapping lines go past the current page, I find myself
scrolling before I get to the bottom. So let's scroll less, usually from
the start of the bottom-most line, even if it wraps multiple screen
lines.

The challenge with this is to ensure that a long line that fills the
whole page by itself doesn't get you stuck. I take some care to make
sure <pagedown> always makes forward progress.
Diffstat (limited to 'text.lua')
-rw-r--r--text.lua16
1 files changed, 14 insertions, 2 deletions
diff --git a/text.lua b/text.lua
index d3cc29d..cbccc85 100644
--- a/text.lua
+++ b/text.lua
@@ -395,8 +395,20 @@ function Text.pageup()
 end
 
 function Text.pagedown()
-  Screen_top1.line = Screen_bottom1.line
-  Screen_top1.pos = Screen_bottom1.pos
+  -- If a line/paragraph gets to a page boundary, I often want to scroll
+  -- before I get to the bottom.
+  -- However, only do this if it makes forward progress.
+  local top2 = Text.to2(Screen_bottom1)
+  if top2.screen_line > 1 then
+    top2.screen_line = math.max(top2.screen_line-10, 1)
+  end
+  local new_top1 = Text.to1(top2)
+  if Text.lt1(Screen_top1, new_top1) then
+    Screen_top1 = new_top1
+  else
+    Screen_top1.line = Screen_bottom1.line
+    Screen_top1.pos = Screen_bottom1.pos
+  end
 --?   print('setting top to', Screen_top1.line, Screen_top1.pos)
   Cursor1.line = Screen_top1.line
   Cursor1.pos = Screen_top1.pos