gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 15:04:49 26 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/2873879/

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