Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

avoid scrolling current line to top of view when start editing #794

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

JFormDesigner
Copy link
Contributor

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.

@Jugen
Copy link
Collaborator

Jugen commented Dec 21, 2018

@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.

@JFormDesigner
Copy link
Contributor Author

@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).

@Jugen
Copy link
Collaborator

Jugen commented Dec 21, 2018

@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.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants