| Preserve Line Breaks [message #1121060] |
Mon, 30 September 2013 04:20  |
Lars Martin Messages: 22 Registered: July 2009 |
Junior Member |
|
|
Following Jan's Blog post I can modify parts of my model. This works great (Xtext 2.4.3) except for Strings where line breaks need to be preserved.
IXtextDocument xtextDocument = xtextEditor.getDocument();
xtextDocument.modify(new IUnitOfWork.Void<XtextResource>() {
public void process(XtextResource resource) {
...
Variable.setValue("a\nb\\nc\\\nd\\\\ne");
...
}
}
No matter what type of escaping the NEWLINE char I use, the Xtext editor receive exactly that passed String.
result:
V="a\nb\\nc\\\nd\\\\ne"
expected:
V="a
b
c
d
e"
Any hints how to preserve line breaks?
Regards, Lars M.
[Updated on: Mon, 30 September 2013 04:21] Report message to a moderator
|
|
|
|
|
|
| Re: Preserve Line Breaks [message #1122059 is a reply to message #1121221] |
Tue, 01 October 2013 03:31  |
Lars Martin Messages: 22 Registered: July 2009 |
Junior Member |
|
|
Also the utility methods:
org.eclipse.xtext.util.Strings.convertFromJavaString
org.eclipse.xtext.util.Strings.convertToJavaString
didn't work.
My environment: My grammar contains a rule like following
Variable:
name=ID '=' value=STRING;
The preferred formatting of "value" uses line breaks even if every WS would be legal for the post-processing step.
An extract from a sample model:
In a Multipage Editor the user can edit the "value" of a given element in a JFace/SWT Formeditor, synchronization with the underlaying Xtext Document works well:
xtextDocument.readOnly(new IUnitOfWork...) // read the proper model element
..
xtextDocument.modify(new IUnitOfWork...) // write/update the proper model element
.. except for Strings with line breaks. Line breaks get escaped to "\n" when writing back to the XtextDocument.
Regards, Lars M.
|
|
|
Powered by
FUDForum. Page generated in 0.01551 seconds