super_editor
super_editor copied to clipboard
[SuperTextField] - Don't let the caret sit beyond the viewport edge (single line)
In single-line SuperTextField
we have auto-scroll logic that scrolls to the right or left to ensure that the selection extent is visible. This includes the situation where the user uses the arrow key to move the caret right and left.
The auto-scroll behavior is roughly correct, but there's one small detail that we should fix. Even though we auto-scroll to ensure the extent offset is visible, the extent offset is probably where the caret starts. Therefore, the caret can sit just outside the viewport and essentially be invisible.
We could add a few pixels to the auto-scroll behavior to correct for that. However, there's still another problem. If the padding for the text field is zero, then when the caret sits at the very end of the text, we can't scroll a few pixels more, because there's no content left to scroll.
Perhaps we should force a couple pixels of padding on the left and the right for a single-line text field. Or, perhaps we should allow for the case that a zero-padding text field might have a caret that sits just beyond the viewport.
After solving this issue, update the caret visibility test in text/super_textfield/super_textfield_scrolling_test.dart