Eclipe PDE:跳到X行并突出显示
-
03-10-2019 - |
题
关于Eclipse PDE开发的Qustion:我为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);
这可能会以某种方式吗?我找不到解决方案
解决方案
在课堂上 详细信息view 我找到了以下方法。
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());
}
}
}
其他提示
虽然 org.eclipse.ui.texteditor.itexteditor 交易偏移,它应该能够使用您的行号 selectAndReveal()
方法。
尝试沿线的某些内容:
((ITextEditor)org.eclipse.jdt.ui.JavaUI.openInEditor(compilationUnit)).selectAndReveal(int, int);
不隶属于 StackOverflow