如何在 TextEditor 的子类中使用 org.eclipse.jface.text.PaintManager?

How can I use org.eclipse.jface.text.PaintManager in subclass of TextEditor?

如何将 PaintManager 附加到我的 TextEditor? 例如用org.eclipse.jface.text.CursorLinePainter.

绘制光标线的背景

您的编辑器的 TextViewerSourceViewer 提供绘图管理器。您可以使用查看器的 ITextViewerExtension2 界面访问它。

例如这段代码来自SourceViewerDecorationSupport:

private void showCursorLine() {
    if (fCursorLinePainter == null) {
        if (fSourceViewer instanceof ITextViewerExtension2) {
            fCursorLinePainter = new CursorLinePainter(fSourceViewer);
            fCursorLinePainter.setHighlightColor(getColor(fCursorLinePainterColorKey));

            ITextViewerExtension2 extension = (ITextViewerExtension2) fSourceViewer;
            extension.addPainter(fCursorLinePainter);
        }
    }
}