CodeArea: request to raise priority of JDK-8357405 (text length metrics for ContentChange)
PavelTurk
pavelturk2000 at gmail.com
Wed May 28 10:10:36 UTC 2025
Andy, thank you for your reply.
When making changes, I think we have THREE key parameters:
1. startByte – this is the offset in the file where the change begins. If the document is very large, this value might require a long, although that would be one case in a billion.
2. removedLength – the length of the removed chunk of text starting from startByte. I think this will always fit in an int, but it could be a long as well. At the same time String#length() -> int.
3. insertedLength – the length of the inserted text starting at startByte. Again, I believe int should suffice, but long is also an option.
Now, in JDK-8357405, only (2) and (3) are mentioned. So, the calculation of startByte is left for the future or for the user to handle. The reason for this is that the user can compute startByte themselves, but they cannot efficiently determine removedLength and insertedLength (at least I don’t know how).
At the same time, I believe that during the change processing, the library itself can quite easily calculate these values and include them in the ContentChange. For example, when a portion of text is selected and replaced with something else, the library knows:
a) the length of the selected text, and
b) the length of the inserted text.
If I’m wrong and the user can efficiently calculate removedLength and insertedLength using a custom model, could you explain how to do that? Because without this data, my work with JFX CodeArea is completely blocked.
At the same time, wouldn’t it be better to support these values out of the box? Many code analysis libraries rely on them, and CodeArea is intended to be integrated with exactly those kinds of libraries.
Best regards, Pavel
On 5/27/25 20:51, Andy Goryachev wrote:
>
> Dear Pavel:
>
> This is not a trivial request. Currently, there is not easy way to control (override) the behavior of the CodeModel with respect to line endings. Line endings are not stored in the model, but they are emitted when saving/copying.
>
> Perhaps we ought to add a dedicated property to the model (line endings: CR/LF/CRLF/PLATFORM?) which would allow the application to specify the behavior and allow the model to perform the offset calculations.
>
> The other issue is that the CodeArea supports large models (CodeTextModel with a custom BasicTextModel.Content). Computing offsets in a large model not only may take a long time, but also produce result that does not fit into 31 bits. Which means, for all intents and purposes, this functionality should be implemented by a custom model.
>
> What do you think?
>
> Cheers,
>
> -andy
>
> *From: *openjfx-dev <openjfx-dev-retn at openjdk.org> on behalf of PavelTurk <pavelturk2000 at gmail.com>
> *Date: *Thursday, May 22, 2025 at 05:29
> *To: *openjfx-dev at openjdk.org <openjfx-dev at openjdk.org>
> *Subject: *CodeArea: request to raise priority of JDK-8357405 (text length metrics for ContentChange)
>
> I'd like to kindly ask for consideration in raising the priority of JDK-8357405 about adding text length
> metrics to ContentChange for removed/inserted text for CodeArea.
>
> The reason for this request is that accurate and reliable information about text changes is essential
> when integrating CodeArea with code processing libraries. Currently, CodeArea does not provide
> such information.
>
> As a result, CodeArea can only be reliably used in read-only mode at the moment — which severely
> limits its applicability in real-world applications.
>
> Best regards, Pavel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/openjfx-dev/attachments/20250528/82d1b8f4/attachment.htm>
More information about the openjfx-dev
mailing list