<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
Andy, while implementing the conversion from TextPos to offset, I
encountered the following issue. <br>
<br>
Paragraph lines do not include line separators (\n or \r\n) at the
end. However, in order to correctly <br>
calculate the offset, I need to account for the size of the line
separator, which can be either 1 or 2 <br>
characters long. <br>
<br>
In RichTextFX, as far as I know, only \n is used (i.e., \r\n is
replaced with \n). But what about the JavaFX CodeArea? <br>
How can I determine the size of the line separator there? Or is it
always 1 byte as well?<br>
<br>
Best regards, Pavel<br>
<br>
<div class="moz-cite-prefix">On 5/7/25 20:04, Andy Goryachev wrote:<br>
</div>
<blockquote type="cite"
cite="mid:BYAPR10MB3013772CB633B370812C4E9DE588A@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;}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"">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').<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"">The
same is true for the reverse operation, TextPos ->
offset.<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 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>Wednesday, May 7, 2025 at 09:29<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>CodeArea: how to convert offset to
TextPos?<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">Could
anyone say how to convert offset to TextPos in
CodeArea?<br>
<br>
For example, in RTFX CodeArea we have:<br>
<br>
var pos = codeArea.offsetToPosition(offset,
Bias.Backward);<br>
var paragraph = pos.getMajor();<br>
<br>
Best regards, Pavel<o:p></o:p></span></p>
</div>
</div>
</div>
</div>
</div>
</blockquote>
<br>
</body>
</html>