[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.platform] Re: Easiest way getting the text under the mouse

Grant Gayed wrote:

If your editor is a StyledText under the covers, and if you can get hold of
it, then you can use StyledText.getOffsetAtLocation() to get the cursor's
character offset, and then determine the content from there.

I don't know if there's a higher-level api for computing what you want, if
there is then hopefully someone can follow up here with it.

Grant

Hi Grant,

I don't know how to use that...

I'm developing an plug-in for Eclipse and need to extend the normal
editors, (java or CDT) with an extra menu choices when I click on the mouse's right button in the editor.


I have functionality for getting the text at the carret position.

IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IEditorPart part = page.getActiveEditor();
ITextEditor editor = (ITextEditor)part;
ISelectionProvider selprovider = editor.getEditorSite().getSelectionProvider();
TextSelection selectedText = (TextSelection)selprovider.getSelection();
int iCursorPosition = selectedText.getOffset(); But I need to translate a mouse point to an usable offset in the same way.


/Pelle