template-carousel-mobile/0035-compute_scrollbar
Kartik K. Agaram 3717d7868a start sketching out a scrollbar
Not quite ideal: the scrollbar computation only considers
screen_bottom1.line and not screen_bottom1.pos, and so it always assumes
the final line is at the bottom of the screen.

I'm making a deeper change here that I might come to regret. I want to
avoid creating new book-keeping for editor mutations, so I'm putting the
work of computing scrollbar data into clear_screen_line_cache. But that
implies the editor should never clear before updating data, and I caught
one place that wasn't true before. A better name helps avoid this in
future. Let's see how much toil this causes in resolving conflicts.
2023-11-18 04:25:31 -08:00

8 lines
461 B
Plaintext

-- returns:
-- * a float between 0 and 1 regarding the relative position of the top line on screen
-- * a float between 0 and 1 regarding the relative position of the bottom line on screen
compute_scrollbar = function(state)
local top = state.line_cache[state.screen_top1.line].start_screen_line_index
local bot = state.line_cache[state.screen_bottom1.line].start_screen_line_index
return (top-1)/state.screen_line_count, bot/state.screen_line_count
end