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

Tejesh R duke at openjdk.java.net
Mon Apr 11 10:35:47 UTC 2022


On Fri, 8 Apr 2022 12:17:37 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:
> 
>   Updated based on Review Comments

> > > 
> > 
> > 
> > If I add '\n' after the string then it would be "\n\r\n" which would be mapped to "\r\n\r\n" resulting in extra space......
> 
> Resulting in extra space?
> 
> As far as I can see, both samples have two line breaks and they're preserved. _With the updated code_, right?
Yeah, in old code also the result for this sample would be same I guess, the old code bug was only w.r.t "\r\n" (one line break) resulting in "\r\r\n" (two line breaks).

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

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



More information about the client-libs-dev mailing list