Eclipse-plugin how to get the current position of a text editor

I am trying to show a popup dialog at the position of the text cursor of an editor. How can I get the position of the text cursor in pixels of the active editor (dot) and the popup dialog at that moment?

+4
source share
2 answers

I'm not quite sure what you mean by "show popup dialog at this point", but do something like this:

IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); if (editor instanceof ITextEditor) { ISelectionProvider selectionProvider = ((ITextEditor)editor).getSelectionProvider(); ISelection selection = selectionProvider.getSelection(); if (selection instanceof ITextSelection) { ITextSelection textSelection = (ITextSelection)selection; int offset = textSelection.getOffset(); // etc. } } 

Of course, in production code, zero checks, etc.

+2
source

You can use getCursorPosition() method AbstractTextEditor

0
source

Source: https://habr.com/ru/post/924503/


All Articles