StyledText setCaretOffset not working? [message #467516] |
Wed, 01 February 2006 12:54 |
Eclipse User |
|
|
|
Originally posted by: eclipse.insomnia-consulting.org
I'm writing code that replaces text in a StyledText widget during the
TextChanged event.
The code that's giving me problems is...
StyledText sv = getSourceViewer().getTextWidget() ;
int offset = sv.getCaretOffset() ;
sv.setSelection(0, offset) ;
ignore = true ; //to ensure the textChanged doesn't get executed a second
time
sv.insert("//test\nnop|nop |nop|nop|nop\nnop|clracc|") ;
ignore = false ;
sv.setCaretOffset(0);
I'd expect, at the end of this the caret would be at the beginning of the
text. However, it is always at the original caretOffset position.
Any thoughts? (Eclipse 3.1.1 on Mac OSX 10.4)
|
|
|
|
Re: StyledText setCaretOffset not working? [message #467522 is a reply to message #467518] |
Wed, 01 February 2006 14:35 |
Eclipse User |
|
|
|
Originally posted by: eclipse.insomnia-consulting.org
Stefan Langer wrote:
> I had a similar problem and solved it by executing the setCaretOffset in
> asyncExec. Thus it gets executed after my eventhandling code is done.
> This seems to work although I can't guarantee that this is crossplatform
> compatible since I only execute the code on windows.
> Regards
> Stefan
Thanks Stefan... I'm not familiar with asyncExec? Can you give me an
example?
|
|
|
Re: StyledText setCaretOffset not working? [message #467526 is a reply to message #467516] |
Wed, 01 February 2006 15:18 |
Eclipse User |
|
|
|
Originally posted by: sunil_kamath.nohotspammail.com
greg akins <eclipse@insomnia-consulting.org> wrote:
> I'm writing code that replaces text in a StyledText widget during the
> TextChanged event.
>
> The code that's giving me problems is...
>
> StyledText sv = getSourceViewer().getTextWidget() ;
> int offset = sv.getCaretOffset() ;
>
>
> sv.setSelection(0, offset) ;
> ignore = true ; //to ensure the textChanged doesn't get executed a
> second time
>
> sv.insert("//test\nnop|nop |nop|nop|nop\nnop|clracc|") ;
> ignore = false ;
>
> sv.setCaretOffset(0);
>
> I'd expect, at the end of this the caret would be at the beginning of
> the text. However, it is always at the original caretOffset position.
>
try:
sv.setSelection(0,0)
--
Sunil
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03230 seconds