IDEA 5.0: Line separator problems with Document.replaceString(...)

Hello,

I am trying to substitute the content of my text editor with the Document.replaceString(int, int, CharSequence) method:

String myNewContent = "...";
document.replaceString(0, document.getTextLength(), myNewContent);

If 'myNewContent' contains a text with Unix line separators (\n) then everything works fine.
As soon as 'myNewContent' contains text with Windows (\r\n) or Mac (\r) line separators then IntelliJ IDEA throws an error in the "IDE Fatal Errors window":
Wrong line separators inserted into Document

How can I use Document.replaceString(...) with Windows or Mac Line Separators without getting this error ?

Thanks in advance for your help!

Best regards
Tobias

3 comments

TobiasAndree wrote:

How can I use Document.replaceString(...) with Windows or Mac Line Separators without getting this error ?


Replace them with Unix line separators in the new content string before
calling Document.replaceString().

Ciao,
Gordon

--
Gordon Tyler (Software Developer)
Quest Software <http://www.quest.com/>
260 King Street East, Toronto, Ontario M5A 4L5, Canada
Voice: (416) 933-5046 | Fax: (416) 933-5001

0

Hello Gordon,

but what can I do if I would really like to keep the Windows and Mac line separators to get the source code in the document formatted in Mac/Windows style?

Thanks!
Tobias




0

Hello TobiasAndree,

T> but what can I do if I would really like to keep the Windows and Mac
T> line separators to get the source code in the document formatted in
T> Mac/Windows style?

IDEA will convert the line separators to the proper format when the document
is saved.

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"


0

Please sign in to leave a comment.