Eclipse-plugin如何获取当前文本编辑器的corsor位置 [英] Eclipse-plugin how to get current text editor corsor position

查看:188
本文介绍了Eclipse-plugin如何获取当前文本编辑器的corsor位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在编辑器的文本光标位置显示弹出对话框。在这个点上,如何获取文本光标位置的像素点(Point)和显示弹出对话框?

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.

这篇关于Eclipse-plugin如何获取当前文本编辑器的corsor位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆