Home » Modeling » TMF (Xtext) » appending text programmatically.
| | |
Re: appending text programmatically. [message #692393 is a reply to message #692392] |
Mon, 04 July 2011 11:01 |
Christophe Bouhier Messages: 937 Registered: July 2009 |
Senior Member |
|
|
Actuall this one is better, and doesn't replace the last char, and keeps
the cursor in place:
IXtextDocument doc = editor.getDocument();
int len = doc.getLength();
try {
if( len == 0){
doc.set(toInsert);
}else{
String lastChar = doc.get(len-1, 1);
doc.replace(len-1, toInsert.length(), lastChar + toInsert);
}
} catch (BadLocationException e) {
e.printStackTrace();
}
On 04-07-11 12:54, Christophe Bouhier wrote:
> On 04-07-11 12:39, Alexander Nittka wrote:
>> Hi,
>>
>> doesn't doc.set(doc.get()+ whateverToAppend) work?
>>
>> Alex
> thanks, I actually resolved by this:
>
> IXtextDocument doc = editor.getDocument();
> int len = doc.getLength();
> try {
> if( len == 0){
> doc.set(toInsert);
> }else{
> doc.replace(len-1, toInsert.length(), toInsert);
> }
> } catch (BadLocationException e) {
> e.printStackTrace();
> }
|
|
|
Re: appending text programmatically. [message #692520 is a reply to message #692393] |
Mon, 04 July 2011 16:23 |
|
In Xtext 1.0.x it was reccomended to do this using a unit of work; isn't
this necessary anymore?
On 07/04/2011 01:01 PM, Christophe Bouhier wrote:
> Actuall this one is better, and doesn't replace the last char, and keeps
> the cursor in place:
>
> IXtextDocument doc = editor.getDocument();
> int len = doc.getLength();
> try {
> if( len == 0){
> doc.set(toInsert);
> }else{
> String lastChar = doc.get(len-1, 1);
> doc.replace(len-1, toInsert.length(), lastChar + toInsert);
> }
> } catch (BadLocationException e) {
> e.printStackTrace();
> }
>
>
> On 04-07-11 12:54, Christophe Bouhier wrote:
>> On 04-07-11 12:39, Alexander Nittka wrote:
>>> Hi,
>>>
>>> doesn't doc.set(doc.get()+ whateverToAppend) work?
>>>
>>> Alex
>> thanks, I actually resolved by this:
>>
>> IXtextDocument doc = editor.getDocument();
>> int len = doc.getLength();
>> try {
>> if( len == 0){
>> doc.set(toInsert);
>> }else{
>> doc.replace(len-1, toInsert.length(), toInsert);
>> }
>> } catch (BadLocationException e) {
>> e.printStackTrace();
>> }
>
--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net
HOME: http://www.lorenzobettini.it
TDD Book: https://leanpub.com/tdd-buildautomation-ci
Xtext Book: https://www.packtpub.com/application-development/implementing-domain-specific-languages-xtext-and-xtend-second-edition
|
|
| | |
Goto Forum:
Current Time: Fri Sep 20 09:44:53 GMT 2024
Powered by FUDForum. Page generated in 0.03689 seconds
|