InlayModel.addBlockElement() offset parameter
Answered
Hi!
I am trying to use a new 2018.3 feature --- InlayModel.addInlineElement in my plugin for displaying text data above the some lines in Editor. So, the question is: what is meant by offset in given context? For example, I want to display my text above line 10 in editor. So :
editor.getInlayModel().addBlockElement(10,
false,
true,
1,
new EditorCustomElementRenderer() {
@Override
public int calcWidthInPixels(@NotNull Inlay inlay) {
return 30;
}
@Override
public int calcHeightInPixels(@NotNull Inlay inlay) {
return 15;
}
@Override
public void paint(@NotNull Inlay inlay, @NotNull Graphics g, @NotNull Rectangle targetRegion, @NotNull TextAttributes textAttributes) {
Editor editor = inlay.getEditor();
g.setColor(JBColor.GRAY);
g.setFont(getFont(editor));
g.drawString("WOW TXT ABOVE TXT", targetRegion.x, targetRegion.y);
}
});
But after this I see my text not above line with number 10 in editor, just above line 1 (picture attached).
So, can you please clarify, what is the meaning of "offset" parameter in InlayModel.addBlockElement() ?
Many thanks!
Please sign in to leave a comment.
It means character offset in document, inlay is 'attached' to. If the document isn't changing, and soft wraps are not used, any offset for a document line can be used (i.e. from document.getLineStartOffset(line) to document.getLineEndOffset(line)). If the document is changing though, inlay 'attachment' position will behave in the same way as RangeMarker - e.g. if a line break is inserted before the inlay's offset, inlay will now relate to the new line (the one after line break).
Thank you, Dmitry.
And where can I found some documentation about RangeMarker or some examples of it's usage?
Have you checked its javadoc?
Yes, just checked like a 30 minutes ago, just didn't updated the question, sorry.
Finally, I saw "It means character offset" in your first answer :D
Thanks a lot, it works great!