RichTextFX icon indicating copy to clipboard operation
RichTextFX copied to clipboard

avoid scrolling current line to top of view when start editing

Open JFormDesigner opened this issue 6 years ago • 3 comments

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 still thinks that is is not visible and invokes Navigator.placeStartAtMayCrop() to scroll 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 in Navigator.visit(MinDistanceTo targetPosition), which then invokes placeToViewport() and scrolls only when really necessary.

This PR probably fixes also issue #724, which describes the same strange behavior:

... press a key which inserts a char, moves the Caret or anything else, moves the line/paragraph you just edited to the top of the area viewport.

JFormDesigner avatar Dec 21 '18 14:12 JFormDesigner

@JFormDesigner I'm not sure but I think that this is related to #777 (?), so I'm not going to merge this just yet. I'm having real heartache trying to resolve it properly though, as the solution I have causes chaos with undo at the moment.

Jugen avatar Dec 21 '18 15:12 Jugen

@Jugen why do you think that it is related to issue #777? #777 is about GenericStyleArea.visibleParToAllParIndex() which is actually never invoked from RichTextFX (except in tests).

JFormDesigner avatar Dec 21 '18 15:12 JFormDesigner

@JFormDesigner I believe it may be related because you reported that

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

So this sounds like there is a discrepancy between the contents of getVisibleParagraphs() and getParagraphs(), in that not all the paragraph objects in the former can be found in the latter - which is actually what is causing the problem in 777.

From your description I'm therefore guessing that this may also be the root cause of this issue, especially because calling layout() 'fixes' the problem.

Jugen avatar Dec 21 '18 16:12 Jugen