gpt4 book ai didi

eclipse-pde - Eclipse PDE : Jump to line X and highlight it

转载 作者:太空宇宙 更新时间:2023-11-04 07:36:08 27 4
gpt4 key购买 nike

关于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);

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

最佳答案

在类里面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());
}
}
}

关于eclipse-pde - Eclipse PDE : Jump to line X and highlight it,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16854155/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com