869b0059b441f5c610ea834f49c185cce01d014d — Phil Hagelberg a month ago 927f491
Fix scrolling offset.
1 files changed, 14 insertions(+), 3 deletions(-)

M polywell/frontend/love.lua
M polywell/frontend/love.lua => polywell/frontend/love.lua +14 -3
@@ 3,7 3,7 @@
 
 local lume = require("polywell.lib.lume")
 local row_height, scroll_rows, em, w, h
-local padding, buffer_padding, scroll_point = 10, 0, 0.8
+local padding, buffer_padding, offset = 10, 0, 0
 local _, lfs = pcall(require, "lfs")
 local canvas
 local scale = 1


@@ 29,10 29,21 @@ local normalize_color = function(c)
    end
 end
 
+local scroll_offset = function(old_offset, point_line, display_rows)
+   local bottom = display_rows - 2
+   local relative = point_line - old_offset
+   local chunk = display_rows / 2
+
+   if 2 < relative and relative < bottom then return old_offset
+   elseif relative < 2 then return math.max(0, old_offset - chunk)
+   elseif bottom < relative then return math.min(point_line, old_offset + chunk)
+   else return old_offset
+   end
+end
+
 local render_buffer = function(b, colors, bh, focused)
    local display_rows = math.floor(bh / row_height)
-   local edge = math.ceil(display_rows * scroll_point)
-   local offset = (b.point_line < edge and 0) or (b.point_line - edge)
+   offset = scroll_offset(offset, b.point_line, display_rows)
    if(focused or not scroll_rows) then scroll_rows = display_rows end
    for i,line in ipairs(b.render_lines or b.lines) do
       if(i >= offset) then