<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
Andy, thank you for your reply<br>
<br>
<div class="moz-cite-prefix">On 4/29/25 18:02, Andy Goryachev wrote:<br>
</div>
<blockquote type="cite"
cite="mid:BYAPR10MB3013DB00B4D0D317F25BE9F1E5802@BYAPR10MB3013.namprd10.prod.outlook.com">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="Generator"
content="Microsoft Word 15 (filtered medium)">
<style>@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}@font-face
{font-family:Aptos;
panose-1:2 11 0 4 2 2 2 2 2 4;}@font-face
{font-family:"Iosevka Fixed SS16";
panose-1:2 0 5 9 3 0 0 0 0 4;}@font-face
{font-family:"Times New Roman \(Body CS\)";
panose-1:2 11 6 4 2 2 2 2 2 4;}p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
font-size:10.0pt;
font-family:"Aptos",sans-serif;}a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}span.EmailStyle19
{mso-style-type:personal-reply;
font-family:"Iosevka Fixed SS16";
color:windowtext;}.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;
mso-ligatures:none;}div.WordSection1
{page:WordSection1;}</style>
<div class="WordSection1">
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Iosevka Fixed SS16"">Multiple
topics here.<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Iosevka Fixed SS16""><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Iosevka Fixed SS16"">1.
The view does size 100 paragraphs
(Params.SLIDING_WINDOW_EXTENT) to ensure smooth scrolling
when text wrap is on. Initially I thought we could allow
the application to control this parameter, but we decided
against it, as it exposes internal aspect of the
implementation.<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Iosevka Fixed SS16""><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Iosevka Fixed SS16"">2.
You probably should not cache the paragraphs in the model,
or try to optimize the styling in the way I understood you
did. When the view asks for the paragraph, the model needs
to render it in all its glory, or things would break.<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Iosevka Fixed SS16""><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Iosevka Fixed SS16"">It
looks you are trying to implement the syntax highlighting,
right? The first question you might want to ask is
determine whether the styles are known at the time when the
paragraph gets requested. If not - you probably want to
return a plain text paragraph, that is with no styling, and
once the styling is known, fire the model's style change
event, which will cause the view to request the (newly
updated) paragraphs it needs. In other words, the code you
supplied won't work - the model should always build a new
paragraph (or supply a cached one only if you can guarantee
that nothing in it changed, not event line index).</span></p>
</div>
</blockquote>
Hm. I've read this line -
<a class="moz-txt-link-freetext" href="https://github.com/openjdk/jfx/blob/3fdd21386d6db96294fcecd80afc25d09732c067/modules/jfx.incubator.richtext/src/main/java/jfx/incubator/scene/control/richtext/model/RichParagraph.java#L42">https://github.com/openjdk/jfx/blob/3fdd21386d6db96294fcecd80afc25d09732c067/modules/jfx.incubator.richtext/src/main/java/jfx/incubator/scene/control/richtext/model/RichParagraph.java#L42</a>
saying that paragraph is IMMUTABLE and decided - why should I
recreate it if it hasn't changed. It seems that I was wrong. At the
same time in RTFX you can control what to update<br>
and what not. I mean:<br>
<br>
public class ParagraphStyler implements
Consumer<ListModification<? extends
Paragraph<Collection<String>, String,
Collection<String>>>> {<br>
<br>
@Override<br>
public void accept(ListModification<? extends
Paragraph<Collection<String>, String,
Collection<String>>> lm) { <br>
//here it is possible to update styles only for paragraphs
which styles should be updated<br>
}<br>
}<br>
<br>
codeArea.getVisibleParagraphs().addModificationObserver(new
ParagraphStyler()); //only for visible paragraphs!<br>
<br>
In other words, JFX CodeArea forces paragraph styles to update
whether it’s necessary or not, whereas in RTFX we can optimize this
process—at least, that’s how I understand it.<br>
<br>
<blockquote type="cite"
cite="mid:BYAPR10MB3013DB00B4D0D317F25BE9F1E5802@BYAPR10MB3013.namprd10.prod.outlook.com">
<div class="WordSection1">
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Iosevka Fixed SS16""><o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Iosevka Fixed SS16""><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Iosevka Fixed SS16"">3.
Not sure about the scrolling, it seems to work on macOS as
expected. Does it work with a stock model that has none of
the "optimizations"?<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Iosevka Fixed SS16""><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Iosevka Fixed SS16"">-andy<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Iosevka Fixed SS16""><o:p> </o:p></span></p>
</div>
</blockquote>
<br>
Best regards, Pavel<br>
<br>
<blockquote type="cite"
cite="mid:BYAPR10MB3013DB00B4D0D317F25BE9F1E5802@BYAPR10MB3013.namprd10.prod.outlook.com">
<div class="WordSection1">
<p class="MsoNormal"></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Iosevka Fixed SS16""><o:p> </o:p></span></p>
<div id="mail-editor-reference-message-container">
<div>
<div>
<div
style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span
style="font-size:12.0pt;color:black">From:
</span></b><span
style="font-size:12.0pt;color:black">openjfx-dev
<a class="moz-txt-link-rfc2396E" href="mailto:openjfx-dev-retn@openjdk.org"><openjfx-dev-retn@openjdk.org></a> on behalf of
PavelTurk <a class="moz-txt-link-rfc2396E" href="mailto:pavelturk2000@gmail.com"><pavelturk2000@gmail.com></a><br>
<b>Date: </b>Monday, April 28, 2025 at 16:54<br>
<b>To: </b><a class="moz-txt-link-abbreviated" href="mailto:openjfx-dev@openjdk.org">openjfx-dev@openjdk.org</a>
<a class="moz-txt-link-rfc2396E" href="mailto:openjfx-dev@openjdk.org"><openjfx-dev@openjdk.org></a><br>
<b>Subject: </b>RichTextArea: How to return
existing paragraphs from SyntaxDecorator?<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">I
noticed that paragraphs in CodeArea are updated too
aggressively. For example, when I press a single key
like '1', about 100 paragraphs get refreshed.<br>
<br>
To improve performance, I decided to implement it
this way: I store information for each paragraph
indicating whether its styles are up-to-date or not.<br>
From SyntaxDecorator, I return the existing
paragraph from the model if the styles are valid. If
the styles are outdated, I build a new paragraph.<br>
<br>
Something like this:<br>
<br>
codeArea.setSyntaxDecorator(new
SyntaxDecorator() {<br>
@Override<br>
public RichParagraph
createRichParagraph(CodeTextModel model, int index)
{<br>
if (paragraphStylesAreValid) {<br>
return
codeArea.getModel().getParagraph(index);<br>
} else {<br>
RichParagraph.Builder b =
RichParagraph.builder();<br>
...<br>
return b.build();<br>
}<br>
}<br>
<br>
@Override<br>
public void handleChange(CodeTextModel
m, TextPos start, TextPos end, int charsTop,<br>
int linesAdded, int
charsBottom) {<br>
<br>
}<br>
});<br>
<br>
However, it didn't work because of this line - <a
href="https://github.com/openjdk/jfx/blob/3fdd21386d6db96294fcecd80afc25d09732c067/modules/jfx.incubator.richtext/src/main/java/jfx/incubator/scene/control/richtext/model/CodeTextModel.java#L83"
moz-do-not-send="true"
class="moz-txt-link-freetext">
https://github.com/openjdk/jfx/blob/3fdd21386d6db96294fcecd80afc25d09732c067/modules/jfx.incubator.richtext/src/main/java/jfx/incubator/scene/control/richtext/model/CodeTextModel.java#L83</a><br>
<br>
As I result I get StackOverflowError. Could anyone
say how to do it?<br>
<br>
Best regards, Pavel<o:p></o:p></span></p>
</div>
</div>
</div>
</div>
</div>
</blockquote>
<br>
</body>
</html>