Richtextfx: How best to scroll to a position in the text?

Created on 14 Oct 2017  路  2Comments  路  Source: FXMisc/RichTextFX

For multi-line paragraphs you often want to move the view to a specific line, for example when doing a search to show a match or moving to a line or for a specific text offset.

What is the best way to do this?

NavigationActions.moveTo moves the caret but not the view, and that isn't really desirable anyway in the general case.

The scroll[]ToPixel methods are possible but how would I translate a text offset into a view pixel offset? Also, in general how do I determine the view offset of a text offset that is currently not on screen?

question

Most helpful comment

You can use area.showParagraphAtTop(int paragraphIndex) or its bottom counterpart, or area.showParagraphInViewport(int paragraphIndex) to insure the paragraph is visible. There are two other methods not yet exposed from Flowless: VirtualFlow#show(int cellIndex, double yOffset) and VirtualFlow#show(int cellIndex, Bounds regionInCell)

As for ones that show a line specifically, you'd need to use a mixture of the above. Since the VirtualFlow only renders the paragraphs that are visible as a way to save memory and increase speed, you would need to show that paragraph first, calculate where on the screen the thing in the paragraph you want to show is, calculate an offset value using that, and then scroll by that offset value so that the line is visible or the part in the line is visible.

All 2 comments

You can use area.showParagraphAtTop(int paragraphIndex) or its bottom counterpart, or area.showParagraphInViewport(int paragraphIndex) to insure the paragraph is visible. There are two other methods not yet exposed from Flowless: VirtualFlow#show(int cellIndex, double yOffset) and VirtualFlow#show(int cellIndex, Bounds regionInCell)

As for ones that show a line specifically, you'd need to use a mixture of the above. Since the VirtualFlow only renders the paragraphs that are visible as a way to save memory and increase speed, you would need to show that paragraph first, calculate where on the screen the thing in the paragraph you want to show is, calculate an offset value using that, and then scroll by that offset value so that the line is visible or the part in the line is visible.

Closing since I think this has been answered.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Adrodoc picture Adrodoc  路  3Comments

hendriklenz picture hendriklenz  路  9Comments

prat-man picture prat-man  路  4Comments

JordanMartinez picture JordanMartinez  路  11Comments

kszilagyi picture kszilagyi  路  6Comments