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

aut*_*her 6 eclipse-api eclipse-pde

关于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);
Run Code Online (Sandbox Code Playgroud)

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

eld*_*dur 5

在类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());
    }
  }
}
Run Code Online (Sandbox Code Playgroud)