Skip to content

Commit 30786a5

Browse files
committed
Unsets vertical indent upon preview termination
1 parent c20132d commit 30786a5

File tree

4 files changed

+37
-27
lines changed

4 files changed

+37
-27
lines changed

plugin/src/software/aws/toolkits/eclipse/amazonq/handlers/QAcceptSuggestionsHandler.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ private void insertSuggestion(final String suggestion) {
3636
var insertOffset = widget.getCaretOffset();
3737
doc.replace(insertOffset, 0, suggestion);
3838
widget.setCaretOffset(insertOffset + suggestion.length());
39-
4039
QInvocationSession.getInstance().transitionToDecisionMade();
41-
QInvocationSession.getInstance().getViewer().getTextWidget().redraw();
4240
QInvocationSession.getInstance().end();
4341
} catch (BadLocationException e) {
4442
PluginLogger.error(e.toString());

plugin/src/software/aws/toolkits/eclipse/amazonq/util/QEclipseEditorUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ public static ITextViewer getActiveTextViewer(final ITextEditor editor) {
6363
return asTextViewer(editor);
6464
}
6565

66-
public static boolean shouldIndentNextLineVertically(final StyledText textWidget, final int line) {
67-
return line + 1 < textWidget.getLineCount() - 1;
66+
public static boolean shouldIndentVertically(final StyledText textWidget, final int zeroIndexedLine) {
67+
return zeroIndexedLine + 1 < textWidget.getLineCount();
6868
}
6969

7070

plugin/src/software/aws/toolkits/eclipse/amazonq/util/QInlineRendererListener.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import org.eclipse.swt.graphics.Point;
99

1010
import static software.aws.toolkits.eclipse.amazonq.util.QConstants.Q_INLINE_HINT_TEXT_COLOR;
11-
import static software.aws.toolkits.eclipse.amazonq.util.QEclipseEditorUtils.shouldIndentNextLineVertically;
11+
import static software.aws.toolkits.eclipse.amazonq.util.QEclipseEditorUtils.shouldIndentVertically;
1212

1313
import java.util.Arrays;
1414

@@ -60,22 +60,25 @@ public final void paintControl(final PaintEvent e) {
6060
gc.drawText(renderHeadIndex >= 0 ? firstLine.substring(renderHeadIndex) : firstLine, xLoc, location.y, true);
6161
}
6262

63-
// Draw other lines inline
64-
if (!remainder.isEmpty()) {
65-
// For last line case doesn't need to indent next line vertically
66-
var caretLine = widget.getLineAtOffset(widget.getCaretOffset());
67-
if (shouldIndentNextLineVertically(widget, caretLine)) {
68-
// when showing the suggestion need to add next line indent
69-
Point textExtent = gc.stringExtent(" ");
70-
int height = textExtent.y * remainder.split("\\R").length;
71-
qInvocationSessionInstance.setVerticalIndent(caretLine + 1, height, textExtent.y);
72-
}
63+
// Draw other lines inline
64+
if (!remainder.isEmpty()) {
65+
// For last line case doesn't need to indent next line vertically
66+
var caretLine = widget.getLineAtOffset(widget.getCaretOffset());
67+
if (shouldIndentVertically(widget, caretLine)
68+
&& qInvocationSessionInstance.isPreviewingSuggestions()) {
69+
// when showing the suggestion need to add next line indent
70+
Point textExtent = gc.stringExtent(" ");
71+
int height = textExtent.y * remainder.split("\\R").length;
72+
qInvocationSessionInstance.setVerticalIndent(caretLine + 1, height);
73+
}
7374

74-
int lineHt = widget.getLineHeight();
75+
int lineHt = widget.getLineHeight();
7576
int fontHt = gc.getFontMetrics().getHeight();
7677
int x = widget.getLeftMargin();
7778
int y = location.y + lineHt * 2 - fontHt;
7879
gc.drawText(remainder, x, y, true);
80+
} else {
81+
qInvocationSessionInstance.unsetVerticalIndent();
7982
}
8083
}
8184

plugin/src/software/aws/toolkits/eclipse/amazonq/util/QInvocationSession.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -219,15 +219,17 @@ public void transitionToDecisionMade() {
219219
return;
220220
}
221221
state = QInvocationSessionState.DECISION_MADE;
222+
223+
unsetVerticalIndent();
222224

223225
// Clear previous next line indent in certain cases (always for now?)
224226
// From Felix: Not really sure when or where this is needed, disabling for now.
225227
// This is throwing under certain circumstances with IllegalArgument
226-
// var widget = viewer.getTextWidget();
227-
// var caretLine = widget.getLineAtOffset(widget.getCaretOffset());
228-
// if (!isLastLine(widget, caretLine + 1)) {
229-
// widget.setLineVerticalIndent(caretLine + 1, 0);
230-
// }
228+
// var widget = viewer.getTextWidget();
229+
// var caretLine = widget.getLineAtOffset(widget.getCaretOffset());
230+
// if (!isLastLine(widget, caretLine + 1)) {
231+
// widget.setLineVerticalIndent(caretLine + 1, 0);
232+
// }
231233
}
232234

233235
public void setCaretMovementReason(final CaretMovementReason reason) {
@@ -333,10 +335,21 @@ public boolean hasBeenTypedahead() {
333335
return hasBeenTypedahead;
334336
}
335337

336-
public void setVerticalIndent(int line, int height, int originalHeight) {
338+
public void setVerticalIndent(int line, int height) {
339+
System.out.println("set vertical indent called for line " + line);
337340
var widget = viewer.getTextWidget();
338341
widget.setLineVerticalIndent(line, height);
339-
unsetVerticalIndent = () -> { widget.setLineVerticalIndent(line, originalHeight); };
342+
unsetVerticalIndent = () -> {
343+
var caretLine = widget.getLineAtOffset(widget.getCaretOffset());
344+
widget.setLineVerticalIndent(caretLine + 1, 0);
345+
};
346+
}
347+
348+
public void unsetVerticalIndent() {
349+
if (unsetVerticalIndent != null) {
350+
unsetVerticalIndent.run();
351+
unsetVerticalIndent = null;
352+
}
340353
}
341354

342355
// Additional methods for the session can be added here
@@ -356,10 +369,6 @@ public void dispose() {
356369
widget.removePaintListener(paintListener);
357370
widget.removeCaretListener(caretListener);
358371
widget.removeVerifyKeyListener(verifyKeyListener);
359-
if (unsetVerticalIndent != null) {
360-
unsetVerticalIndent.run();
361-
unsetVerticalIndent = null;
362-
}
363372
paintListener = null;
364373
caretListener = null;
365374
verifyKeyListener = null;

0 commit comments

Comments
 (0)