开发者

Eclipse-plugin how to get current text editor cursor position

开发者 https://www.devze.com 2022-12-09 14:55 出处:网络
I try to show popup dialog at text cursor position of an editor. How can I get text cursor position in pixels of the active editor (Point) 开发者_高级运维and a show popup dialog at this point?I\'m not

I try to show popup dialog at text cursor position of an editor. How can I get text cursor position in pixels of the active editor (Point) 开发者_高级运维and a show popup dialog at this point?


I'm not exactly sure what do you mean under "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 do null checks etc.


You can use the getCursorPosition() method of AbstractTextEditor

0

精彩评论

暂无评论...
验证码 换一张
取 消