avoid scrolling current line to top of view when start editing #794
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes a painful behavior that I noticed in Markdown Writer FX:
When I start typing into the current line, RichTextFX immediately
scrolls the current line to the top of the view.
Turns out that this happens only if embedded images feature is enabled
and if there are of course some embedded images before the current line.
The cause for the behaviour is in
GenericStyledArea.followCaret()
.For some unknown reason, the cell of the current line that is returned by
virtualFlow.getCell(parIdx)
is not visible (cell.getNode().isVisible() == false
)although it is visible on screen.
Later on in
Navigator.visit(MinDistanceTo targetPosition)
, the VirtualFlow stillthinks that is is not visible and invokes
Navigator.placeStartAtMayCrop()
toscroll the current line to the top of the view.
The fix is easy:
virtualFlow.layout()
Then we have a visible cell in
followCaret()
and also later inNavigator.visit(MinDistanceTo targetPosition)
, which then invokesplaceToViewport()
and scrolls only when really necessary.This PR probably fixes also issue #724, which describes the same strange behavior: