[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.tools] Re: How can I insert a string into an editor with an external menuitem?

Actually, my first name is Nick, which you can use.

The selection is owned by the editor, not the document, since each editor
open on the same document may have a different selection.  You can get the
selection from the text editor's selection provider.
Here's a snippet from AddMarkerAction:

    ITextSelection selection= (ITextSelection)
getTextEditor().getSelectionProvider().getSelection();
    if (!selection.isEmpty()) {
        int start= selection.getOffset();
        int length= selection.getLength();
        if (length < 0) {
            length= -length;
            start -= length;
        }
        ...
    }

If the selection is empty, that mean's it's just a regular insertion point,
so you can just insert the text at getOffset().
If it's not empty, you probably want to replace the selection with your text
to insert.
As the snippet shows, the length may be negative.

Nick