(If it’s not OK to ask this here @marijn please let me know and I’ll delete this thread)
Whenever the contenteditable element grows past the height of the window, browsers strive to keep the caret very close to the bottom of the window. This is annoying from a UX perspective in longer documents because users end up always spending their time at the very bottom of the window.
To solve this, I’m trying to find a way so that the caret never reaches the very bottom of the window.
This is how Google Docs does it:
And this is Medium:
Has anyone found an elegant way to solve this?
I’ve tried with CSS margins and paddings but it doesn’t work. I imagine I can hack my way by manipulating the scroll position but I’d rather avoid that if possible.
The setTimeout is necessary because if the browser is already scrolling then scrollTo won’t work. This happens when pasting text which moves the caret below the limit of the window.
Obviously a better implementation will use throttling/debouncing and also wait until the browser has stopped scrolling.