I came back to this scrolling issue twice now, and
ultimately I’ve realised that the code which updated the
“Scrolling Margins” of the terminal buffer is flawed in that
it doesn’t just scroll the lines of the buffer that are
within the margins, but it also reduces the size of the
buffer to the size of the viewport, without preserving the
location of everything that was in the viewport before.
To solve this I think need to make sure that the entire
buffer is preserved, but the lines within the scroll margins
are scrolled.
The issue is that the scroll margins are relative to the
viewport, but the buffer isn’t necessarily the size of the
viewport. I think this could be the design flaw that makes
my implementation so complicated, but it has certain
advantages.
Scrolling the content is such a crucial part of a terminal
to get right it seems. A lot of interactions depend on it
going smoothly.
I think I want to take the TDD an reintroduce the scroll
margins as an individual component.
For now I’ve figured out how to fix the bug though, so I’ll
continue.
For once it looks like my tests have picked up on a
regression, which is good :)
For now I need to rest though!