eclipse插件:如何以编程方式选择文本? [英] eclipse plugin: How to programmatically select text in editor?

查看:195
本文介绍了eclipse插件:如何以编程方式选择文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以编程方式跳转到文本编辑器中的位置并突出显示代码。

I want to programmatically jump to a position in the text editor and highlight code.

推荐答案

我无法获取安德鲁的答案在Eclipse 3.7中工作。编译器发出这个错误:

I wasn't able to get Andrew's answer to work in Eclipse 3.7. The compiler gave this error:

The method getSourceViewer() from the type AbstractTextEditor is not visible.

但是,我能够使用 selectAndReveal()方法:

However, I was able to get it to work with the selectAndReveal() method:

IFile myfile = ...
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
ITextEditor editor = (ITextEditor) IDE.openEditor(page, myfile);
editor.selectAndReveal(offset, length);

这篇关于eclipse插件:如何以编程方式选择文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆