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

Alexey Ivanov aivanov at openjdk.java.net
Fri Apr 8 12:33:44 UTC 2022


On Fri, 8 Apr 2022 12:13:03 GMT, Tejesh R <duke at openjdk.java.net> wrote:

>> When you do out.write(array, last, counter - last); in write(Writer out, Document doc, int pos, int len) method, what is being written? Is it /r/r/n or /n/r/n presently?
>
> Finally its /n/r/n....... I mentioned /r/r/n because that was the output string from `getText()` method to `setText()` method......

Let me summarise:

Initially, `getText()` wrote out `\r\r\n` for the sequence of `\r\n` in the document.

Then `setText()` converted `\r\r\n` to `\n\r\n` or rather `\n\n` which resulted in the additional blank line in the editor.

The updated code makes sure the additional `\r` isn't added when the text already contains `\r` as part of new line sequence.

Is it correct?

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

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



More information about the client-libs-dev mailing list