Eclipe PDE:跳转到 X 行并突出显示它

发布于 2024-09-02 03:10:38 字数 602 浏览 15 评论 0原文

关于Eclipse PDE开发的问题:我为Eclipse写了一个小插件,有以下内容 * org.eclipse.ui.texteditor.ITextEditor * 行号

如何自动跳转到该行并标记它?遗憾的是,API 似乎只支持文档内的偏移量(参见:ITextEditor.selectAndReveal()),但不支持行号。

最好的办法是 - 尽管这不起作用:

ITextEditor editor = (ITextEditor)IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file, true );
editor.goto(line);
editor.markLine(line);

这可能以某种方式实现吗?我没有找到解决方案

A qustion about Eclipse PDE development: I write a small plugin for Eclipse and have the following
* an org.eclipse.ui.texteditor.ITextEditor
* a line number

How can I automatically jump to that line and mark it? It's a pity that the API seems only to support offsets (see: ITextEditor.selectAndReveal()) within the document but no line numbers.

The best would be - although this doesn't work:

ITextEditor editor = (ITextEditor)IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file, true );
editor.goto(line);
editor.markLine(line);

It this possible in some way? I did not find a solution

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

万劫不复 2024-09-09 03:10:39

在类DetailsView 我找到了以下方法。

private static void goToLine(IEditorPart editorPart, int lineNumber) {
  if (!(editorPart instanceof ITextEditor) || lineNumber <= 0) {
    return;
  }
  ITextEditor editor = (ITextEditor) editorPart;
  IDocument document = editor.getDocumentProvider().getDocument(
    editor.getEditorInput());
  if (document != null) {
    IRegion lineInfo = null;
    try {
      // line count internaly starts with 0, and not with 1 like in
      // GUI
      lineInfo = document.getLineInformation(lineNumber - 1);
    } catch (BadLocationException e) {
      // ignored because line number may not really exist in document,
      // we guess this...
    }
    if (lineInfo != null) {
      editor.selectAndReveal(lineInfo.getOffset(), lineInfo.getLength());
    }
  }
}

on the class DetailsView I found the following method.

private static void goToLine(IEditorPart editorPart, int lineNumber) {
  if (!(editorPart instanceof ITextEditor) || lineNumber <= 0) {
    return;
  }
  ITextEditor editor = (ITextEditor) editorPart;
  IDocument document = editor.getDocumentProvider().getDocument(
    editor.getEditorInput());
  if (document != null) {
    IRegion lineInfo = null;
    try {
      // line count internaly starts with 0, and not with 1 like in
      // GUI
      lineInfo = document.getLineInformation(lineNumber - 1);
    } catch (BadLocationException e) {
      // ignored because line number may not really exist in document,
      // we guess this...
    }
    if (lineInfo != null) {
      editor.selectAndReveal(lineInfo.getOffset(), lineInfo.getLength());
    }
  }
}
扎心 2024-09-09 03:10:39

即使 org.eclipse.ui.texteditor.ITextEditor 处理偏移量,它应该能够使用 selectAndReveal() 方法获取行号。

请参阅此线程此线程

尝试以下方法:

((ITextEditor)org.eclipse.jdt.ui.JavaUI.openInEditor(compilationUnit)).selectAndReveal(int, int);

Even though org.eclipse.ui.texteditor.ITextEditor deals wiith offset, it should be able to take your line number with the selectAndReveal() method.

See this thread and this thread.

Try something along the line of:

((ITextEditor)org.eclipse.jdt.ui.JavaUI.openInEditor(compilationUnit)).selectAndReveal(int, int);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文