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

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

问题描述

我尝试在编辑器的文本光标位置显示弹出对话框。

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?

推荐答案

如何在活动编辑器(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插件如何获取当前文本编辑器的光标位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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