|
3 | 3 |
|
4 | 4 | package software.aws.toolkits.eclipse.amazonq.util;
|
5 | 5 |
|
6 |
| -//import org.eclipse.swt.custom.StyledText; |
7 | 6 | import org.eclipse.swt.events.PaintEvent;
|
8 | 7 | import org.eclipse.swt.events.PaintListener;
|
9 |
| -//import org.eclipse.swt.graphics.Point; |
| 8 | +import org.eclipse.swt.graphics.Point; |
10 | 9 |
|
11 | 10 | import static software.aws.toolkits.eclipse.amazonq.util.QConstants.Q_INLINE_HINT_TEXT_COLOR;
|
12 |
| -//import static software.aws.toolkits.eclipse.amazonq.util.QEclipseEditorUtils.isLastLine; |
| 11 | +import static software.aws.toolkits.eclipse.amazonq.util.QEclipseEditorUtils.shouldIndentVertically; |
13 | 12 |
|
14 | 13 | import java.util.Arrays;
|
15 | 14 |
|
@@ -50,38 +49,38 @@ public final void paintControl(final PaintEvent e) {
|
50 | 49 | }
|
51 | 50 |
|
52 | 51 | int renderHeadIndex = currentOffset - offsetAtCurrentLine;
|
53 |
| - String[] remainderArray = Arrays.copyOfRange(suggestionParts, currentLineInSuggestion + 1, suggestionParts.length); |
| 52 | + String[] remainderArray = Arrays.copyOfRange(suggestionParts, currentLineInSuggestion + 1, |
| 53 | + suggestionParts.length); |
54 | 54 | String remainder = String.join("\n", remainderArray);
|
55 | 55 |
|
56 | 56 | // Draw first line inline
|
57 |
| - String firstLine = renderHeadIndex >= 0 |
58 |
| - ? suggestionParts[currentLineInSuggestion].trim() : suggestionParts[currentLineInSuggestion]; |
| 57 | + String firstLine = renderHeadIndex >= 0 ? suggestionParts[currentLineInSuggestion].trim() |
| 58 | + : suggestionParts[currentLineInSuggestion]; |
59 | 59 | int xLoc = renderHeadIndex >= 0 ? location.x : widget.getLeftMargin();
|
60 | 60 | if (renderHeadIndex < firstLine.length()) {
|
61 |
| - gc.drawText(renderHeadIndex >= 0 ? firstLine.substring(renderHeadIndex) : firstLine, xLoc, location.y, true); |
| 61 | + gc.drawText(renderHeadIndex >= 0 ? firstLine.substring(renderHeadIndex) : firstLine, xLoc, location.y, |
| 62 | + true); |
62 | 63 | }
|
63 | 64 |
|
64 | 65 | // Draw other lines inline
|
65 | 66 | if (!remainder.isEmpty()) {
|
66 | 67 | // For last line case doesn't need to indent next line vertically
|
67 | 68 | var caretLine = widget.getLineAtOffset(widget.getCaretOffset());
|
68 |
| - // Felix: Not really sure what this does and it is throwing under certain |
69 |
| - // circumstance |
70 |
| - // Will confirm with Andrew before adding this back in / modifying it. |
71 |
| -// if (!isLastLine(widget, caretLine + 1)) { |
72 |
| -// // when showing the suggestion need to add next line indent |
73 |
| -// Point textExtent = gc.stringExtent(" "); |
74 |
| -// int height = textExtent.y * suggestionParts[1].split("\\R").length; |
75 |
| -// widget.setLineVerticalIndent(caretLine + 1, height); |
76 |
| -// } |
| 69 | + if (shouldIndentVertically(widget, caretLine) && qInvocationSessionInstance.isPreviewingSuggestions()) { |
| 70 | + // when showing the suggestion need to add next line indent |
| 71 | + Point textExtent = gc.stringExtent(" "); |
| 72 | + int height = textExtent.y * remainder.split("\\R").length; |
| 73 | + qInvocationSessionInstance.setVerticalIndent(caretLine + 1, height); |
| 74 | + } |
77 | 75 |
|
78 | 76 | int lineHt = widget.getLineHeight();
|
79 | 77 | int fontHt = gc.getFontMetrics().getHeight();
|
80 | 78 | int x = widget.getLeftMargin();
|
81 | 79 | int y = location.y + lineHt * 2 - fontHt;
|
82 | 80 | gc.drawText(remainder, x, y, true);
|
| 81 | + } else { |
| 82 | + qInvocationSessionInstance.unsetVerticalIndent(); |
83 | 83 | }
|
84 | 84 | }
|
85 | 85 |
|
86 | 86 | }
|
87 |
| - |
0 commit comments