Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » DocumentCommand and caret offset
DocumentCommand and caret offset [message #268204] Mon, 23 August 2004 09:27 Go to next message
Eclipse UserFriend
Originally posted by: doug.satchwell.btinternet.com

Hi - I have added an IAutoEditStrategy to a SourceViewer which, under
certain conditions, replaces a typed character with a string of characters.

Now I would like the caret to be placed at a location within the added
string. However, there doesn't seem to be an obvious way to locate the caret
inside the inserted string after the command has executed - the caretOffset
variable of DocumentCommand will only place the caret at a location with
respect to the document before the command is executed.

Does anyone know how I could force the caret to be inside the inserted
string after command execution?

Thanks,

Doug.
Re: DocumentCommand and caret offset [message #268226 is a reply to message #268204] Mon, 23 August 2004 10:50 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mvsteenbergen.eljakim.scratch-this.nl

Without knowing how IAutoEditStrategies or DocumentCommands work, this
is the first that comes to mind:

myTextEditor.getSelectionProvider().setSelection(new
TextSelection(offset, length));

In your case, length will probably be 0, since you just want to move the
caret. You will probably have to wrap it in a Runnable and pass it to
Display.asyncExec() too.

Hope this helps,

Martijn.

Doug Satchwell wrote:

> Hi - I have added an IAutoEditStrategy to a SourceViewer which, under
> certain conditions, replaces a typed character with a string of characters.
>
> Now I would like the caret to be placed at a location within the added
> string. However, there doesn't seem to be an obvious way to locate the caret
> inside the inserted string after the command has executed - the caretOffset
> variable of DocumentCommand will only place the caret at a location with
> respect to the document before the command is executed.
>
> Does anyone know how I could force the caret to be inside the inserted
> string after command execution?
>
> Thanks,
>
> Doug.
>
>
Re: DocumentCommand and caret offset [message #268276 is a reply to message #268226] Mon, 23 August 2004 12:52 Go to previous message
Eclipse UserFriend
Originally posted by: doug.satchwell.btinternet.com

Thanks Martijn. This would be a great way to do it, and works fine in most
situations. The problem is I'm using an IAutoEditStrategy. An
IAutoEditStrategy only has one method:

void customizeDocumentCommand(IDocument document, DocumentCommand command);

Inside this method, you can change the DocumentCommand. The DocumentCommand
specifies the text to be inserted and the position in the document to insert
the text (and where to put the caret after the command has executed, but
ONLY with respect to the initial document before the command was inserted).

Since the IAutoEditStrategy has no idea of when, or even if, the command
executed, there is no hook that can be placed in the IAutoEditStrategy in
order to run the below code.

I guess I need to find such a hook from the code that actually executes the
DocumentCommands....unless anyone has a better idea?

Thanks,

Doug.





"Martijn van Steenbergen" <mvsteenbergen@eljakim.scratch-this.nl> wrote in
message news:cgcvvd$gu9$1@eclipse.org...
> Without knowing how IAutoEditStrategies or DocumentCommands work, this is
> the first that comes to mind:
>
> myTextEditor.getSelectionProvider().setSelection(new TextSelection(offset,
> length));
>
> In your case, length will probably be 0, since you just want to move the
> caret. You will probably have to wrap it in a Runnable and pass it to
> Display.asyncExec() too.
>
> Hope this helps,
>
> Martijn.
>
> Doug Satchwell wrote:
>
>> Hi - I have added an IAutoEditStrategy to a SourceViewer which, under
>> certain conditions, replaces a typed character with a string of
>> characters.
>>
>> Now I would like the caret to be placed at a location within the added
>> string. However, there doesn't seem to be an obvious way to locate the
>> caret inside the inserted string after the command has executed - the
>> caretOffset variable of DocumentCommand will only place the caret at a
>> location with respect to the document before the command is executed.
>>
>> Does anyone know how I could force the caret to be inside the inserted
>> string after command execution?
>>
>> Thanks,
>>
>> Doug.
Previous Topic:[RCP] Showing multiple views
Next Topic:Need information about library exporting
Goto Forum:
  


Current Time: Sun Jul 20 15:05:43 EDT 2025

Powered by FUDForum. Page generated in 0.05383 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top