0

在我的 Eclipse 插件中,我有一个StyledText对象和IEditorReference对象。我还有一个 yCoordinate,我想用它来检查哪个行号低于这个坐标:

        int lineIndex = styledText.getLineIndex(yCoordinate);

如果没有应用线折叠,这可以正常工作。因此,我正在寻找一种将折线考虑在内的方法,或者将所有折线归还给我,以便我可以手动调整lineIndex. 我有哪些选择?

4

1 回答 1

2

IEditorReference你可以得到IEditorPart

IEditorPart part = ref.getEditor(false);

如果零件是一个,ITextEditor您可以执行以下操作:

ITextEditor editor = (ITextEditor)part;

IDocumentProvider provider = editor.getDocumentProvider();

IEditorInput input = editor.getEditorInput();

IDocument document = provider.getDocument(input);

int line = document.getLineOfOffset(offset in text);

“文本中的偏移量”是从文档开头开始的字符数。StyledText有许多方法可以获取此值,例如getOffsetAtLocation(Point).

于 2014-10-14T17:45:26.787 回答