On Fri, 8 Apr 2022 12:17:37 GMT, Tejesh R <[email protected]> wrote:
>> getText function returned extra endOfLine when appended. The reason was in
>> `EditorEditorKit` class, `write(Writer out, Document doc, int pos, int len)`
>> method, where translation happens from buffer to Out(Writer Object) if
>> endOfLine is other than '\n' ( which is '\r\n' in windows). In order to
>> write each line till End of line, the string till '\n' is written including
>> '\r' and again endOfLine is written which results in extra Carriage Return.
>> To solve this issue, a Condition is added which checks if previous character
>> to '\n' is '\r', if true then whole string except Carriage Return ('\r') is
>> written, else whole string till before '\n' is written.
>
> Tejesh R has updated the pull request incrementally with one additional
> commit since the last revision:
>
> Updated based on Review Comments
> > > > What happens if you add `\r` to an arbitrary location in text?
> > > > What happens if you read in such a text?
> > >
> > >
> > > It doesn't matter, since the data is appended only if '\n' is present
> > > when EndofLine is '\r\n'......
> >
> >
> > I'm not as sure⦠Well, yes, the text will be written out like expected and
> > `\r` character will be preserved. Yet when such a text will be read in, the
> > stranded `\r` will be converted to `\n` which will create an unexpected
> > line break. Or am I wrong?
>
> I edited your test case at line 119:
>
> ```java
> pane0.appendLine("MyJTextPane using append()\r and then calling
> setText()");
> ```
>
> And it creates a new line break after `append()` in the first `JTextPane`.
Yeah, \r converted to newline character......
-------------
PR: https://git.openjdk.java.net/jdk/pull/8122