RFR: 8180276: JTextPane getText return extra when mixed with methods of Document [v3]

Prasanta Sadhukhan psadhukhan at openjdk.java.net
Fri Apr 8 08:41:30 UTC 2022


On Fri, 8 Apr 2022 06:55:34 GMT, Tejesh R <duke at openjdk.java.net> 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:
> 
>   Java coding style fix

src/java.desktop/share/classes/javax/swing/text/DefaultEditorKit.java line 350:

> 348:                             }
> 349:                         }
> 350:                         out.write(endOfLine);

It seems in windows, we use EndOfLineStringProperty property as
[CRLF](https://github.com/openjdk/jdk/blob/f1b6e3ea16f06bc57e8e905fb115650e6c4ad98f/src/java.desktop/share/classes/javax/swing/text/DefaultEditorKit.java#L286)
and `endOfLine ` is using the above property `EndOfLineStringProperty` so 
when you write out.write(endOfLine) will it not write \r\n again?

-------------

PR: https://git.openjdk.java.net/jdk/pull/8122



More information about the client-libs-dev mailing list