CodeArea: how to convert offset to TextPos?

Andy Goryachev andy.goryachev at oracle.com
Wed May 7 17:04:18 UTC 2025


There is no dedicated method to do that.  The application can iterate over paragraphs to compute the text position, just keep in mind that the model can be quite large and it a) will take a lot of iterations and b) the result may exceed 2^31 (i.e. need to be 'long').

The same is true for the reverse operation, TextPos -> offset.

-andy

From: openjfx-dev <openjfx-dev-retn at openjdk.org> on behalf of PavelTurk <pavelturk2000 at gmail.com>
Date: Wednesday, May 7, 2025 at 09:29
To: openjfx-dev at openjdk.org <openjfx-dev at openjdk.org>
Subject: CodeArea: how to convert offset to TextPos?
Could anyone say how to convert offset to TextPos in CodeArea?

For example, in RTFX CodeArea we have:

var pos = codeArea.offsetToPosition(offset, Bias.Backward);
var paragraph = pos.getMajor();

Best regards, Pavel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/openjfx-dev/attachments/20250507/57c7bee1/attachment.htm>


More information about the openjfx-dev mailing list