【发布时间】:2012-11-10 00:43:06
【问题描述】:
我有一个奇怪的问题让我很困惑。我使用以下代码在 Eclipse 的编辑器中打开一个文件:
final IWorkbench wb = PlatformUI.getWorkbench();
IWorkbenchWindow window = wb.getActiveWorkbenchWindow();
final IWorkbenchPage page = window.getActivePage();
wb.getProgressService().runInUI( window, new IRunnableWithProgress() {
@Override
public void run( IProgressMonitor monitor ) throws InvocationTargetException, InterruptedException {
if( null == monitor ) {
monitor = new NullProgressMonitor();
}
try {
monitor.beginTask( "Append to file", 2 );
ITextEditor editor = (ITextEditor) IDE.openEditor( page, file );
monitor.worked( 1 );
// TODO Bug: Editor is active, it has the focus but doesn't process keypress events :-(
} catch( Exception e ) {
throw new InvocationTargetException( e, "Error appending to file " + file );
} finally {
monitor.done();
}
}
}, null );
我从互联网上的几个来源收集了一些零碎的东西。
奇怪的问题是编辑器似乎有焦点(标签被突出显示,我看到它周围的蓝色边框)
但是在编辑器中看不到光标,当我输入内容时,什么也没有发生(工作台的其他地方也没有发生任何事情)。
我也尝试了ITextEditor editor = (ITextEditor) IDE.openEditor( page, file, true );,但结果相同。
当我点击选项卡时,光标出现,我可以使用编辑器。不过,按F12 无效。
还有什么想法?
【问题讨论】:
-
你用的是什么版本的eclipse?我问这个是因为我看到 IDE.openEditor() 并且不确定它来自哪里。
-
3.7.代码来自FAQ:wiki.eclipse.org/…
-
我已经解决了这个问题,请访问:stackoverflow.com/questions/41606181/…
-
@ChetanBhagat 你为什么删除你的答案?