Eclipse Plugin Development: How to highlight syntax in texteditor?

房东的猫 提交于 2019-12-24 21:42:20

问题


Given a java method name, i want to highlight it in the TextEditor. I have reference to the texteditor in ITextEditor.


回答1:


You can create an IMarker object on a file which the Java editor will show.

IFile file = ... file to mark

IMarker marker = file.createMarker(IMarker.TASK); 

marker.setAttribute(IMarker.CHAR_START, start);
marker.setAttribute(IMarker.CHAR_END, end);

I have used a task marker in this example, but you can use the org.eclipse.core.resources.markers extension point to define your own marker.

The org.eclipse.ui.editors.markerAnnotationSpecification extension point can be used to define the colors and style used to show the markers.

The org.eclipse.ui.editors.markerUpdaters extension point can be used to define how markers are updated in an editor as the file is edited.



来源:https://stackoverflow.com/questions/28690144/eclipse-plugin-development-how-to-highlight-syntax-in-texteditor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!