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

Alexey Ivanov aivanov at openjdk.java.net
Thu Apr 7 11:22:55 UTC 2022


On Thu, 7 Apr 2022 10:26:20 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:
> 
>   Added Test Case - ChangeStyleAndAppend.java

Why can't the test be automatic?

You're modifying the contents of a `JTextPane` via `Document`. You can easily get the text from it and verify it has no unexpected new lines.

Please follow Java Coding Style in the product code where the added lines don't fit well into the surrounding code style as well as in the test code.

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

Changes requested by aivanov (Reviewer).

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



More information about the client-libs-dev mailing list