in plugin/src/software/aws/toolkits/eclipse/amazonq/util/QInlineSuggestionNormalSegment.java [37:94]
public void render(final GC gc, final int currentCaretOffset) {
if (currentCaretOffset > endCaretOffset) {
return;
}
var qInvocationSessionInstance = QInvocationSession.getInstance();
if (qInvocationSessionInstance == null) {
return;
}
var widget = qInvocationSessionInstance.getViewer().getTextWidget();
int x;
int y;
String textToRender;
int invocationLine = widget.getLineAtOffset(qInvocationSessionInstance.getInvocationOffset());
int lineHt = widget.getLineHeight();
int fontHt = gc.getFontMetrics().getHeight();
y = (invocationLine + lineInSuggestion + 1) * lineHt - fontHt;
int idxInLine = currentCaretOffset - startCaretOffset;
if (lineInSuggestion == 0) {
x = widget.getLocationAtOffset(widget.getCaretOffset()).x;
textToRender = text.substring(idxInLine);
int curLineInDoc = widget.getLineAtOffset(currentCaretOffset);
int lineIdx = currentCaretOffset - widget.getOffsetAtLine(invocationLine);
String contentInLine = widget.getLine(curLineInDoc);
String rightCtxInLine = contentInLine.substring(lineIdx);
if (!rightCtxInLine.isBlank() && !text.endsWith("\n")) {
styleRange.start = currentCaretOffset;
styleRange.length = 1;
styleRange.metrics = new GlyphMetrics(0, 0, gc.textExtent(textToRender).x + gc.textExtent(" ").x);
styleRange.foreground = widget.getBackground();
widget.setStyleRange(styleRange);
// also include the character right of the caret that is covered by the glyph
textToRender += contentInLine.charAt(lineIdx);
}
} else if (currentCaretOffset <= startCaretOffset) {
textToRender = text;
x = widget.getLeftMargin();
} else {
x = gc.textExtent(text.substring(0, idxInLine)).x;
textToRender = text.substring(idxInLine);
}
int scrollOffsetY = widget.getTopPixel();
y -= scrollOffsetY;
if (!isMacOS) {
layout.setText(textToRender);
layout.setFont(qInvocationSessionInstance.getInlineTextFont());
layout.setTabs(widget.getTabStops());
gc.setAlpha(127);
layout.draw(gc, x, y);
} else {
gc.setForeground(Q_INLINE_HINT_TEXT_COLOR);
gc.setFont(qInvocationSessionInstance.getInlineTextFont());
gc.drawText(textToRender, x, y, true);
}
}