diff --git a/plugin/src/software/aws/toolkits/eclipse/amazonq/util/QInlineCaretListener.java b/plugin/src/software/aws/toolkits/eclipse/amazonq/util/QInlineCaretListener.java index e9eb6c61a..dc9dda9ae 100644 --- a/plugin/src/software/aws/toolkits/eclipse/amazonq/util/QInlineCaretListener.java +++ b/plugin/src/software/aws/toolkits/eclipse/amazonq/util/QInlineCaretListener.java @@ -8,9 +8,11 @@ public final class QInlineCaretListener implements CaretListener { private StyledText widget = null; + private int previousLine = -1; public QInlineCaretListener(final StyledText widget) { this.widget = widget; + this.previousLine = widget.getLineAtOffset(widget.getCaretOffset()); } @Override @@ -21,13 +23,16 @@ public void caretMoved(final CaretEvent event) { // We want to ignore caret movements induced by text editing if (caretMovementReason == CaretMovementReason.TEXT_INPUT) { qInvocationSessionInstance.setCaretMovementReason(CaretMovementReason.UNEXAMINED); + previousLine = widget.getLineAtOffset(widget.getCaretOffset()); return; } if (qInvocationSessionInstance.isPreviewingSuggestions()) { - qInvocationSessionInstance.transitionToDecisionMade(); + qInvocationSessionInstance.transitionToDecisionMade(previousLine + 1); qInvocationSessionInstance.end(); + return; } + + previousLine = widget.getCaretOffset(); } } - diff --git a/plugin/src/software/aws/toolkits/eclipse/amazonq/util/QInlineInputListener.java b/plugin/src/software/aws/toolkits/eclipse/amazonq/util/QInlineInputListener.java index 9e6bb8d23..280fbb2ff 100644 --- a/plugin/src/software/aws/toolkits/eclipse/amazonq/util/QInlineInputListener.java +++ b/plugin/src/software/aws/toolkits/eclipse/amazonq/util/QInlineInputListener.java @@ -58,11 +58,10 @@ public void verifyKey(final VerifyEvent event) { case SWT.CR: if (lastKeyStrokeType == LastKeyStrokeType.OPEN_CURLY && isAutoClosingEnabled) { lastKeyStrokeType = LastKeyStrokeType.OPEN_CURLY_FOLLOWED_BY_NEW_LINE; - // we need to unset the vertical indent prior to new line otherwise the line - // inserted by - // eclipse with the closing curly braces would inherit the extra vertical - // indent. - qInvocationSessionInstance.unsetVerticalIndent(); + // we need to unset the vertical indent prior to new line otherwise the line inserted by + // eclipse with the closing curly braces would inherit the extra vertical indent. + int line = widget.getLineAtOffset(widget.getCaretOffset()); + qInvocationSessionInstance.unsetVerticalIndent(line + 1); } else { lastKeyStrokeType = LastKeyStrokeType.NORMAL_INPUT; } @@ -196,9 +195,6 @@ public void verifyText(final VerifyEvent event) { .setHasBeenTypedahead(currentOffset - qInvocationSessionInstance.getInvocationOffset() > 0); boolean isOutOfBounds = distanceTraversed >= currentSuggestion.length() || distanceTraversed < 0; - if (!isOutOfBounds) { - System.out.println("current char in suggestion: " + currentSuggestion.charAt(distanceTraversed)); - } if (isOutOfBounds || !isInputAMatch(currentSuggestion, distanceTraversed, input)) { qInvocationSessionInstance.transitionToDecisionMade(); qInvocationSessionInstance.end(); diff --git a/plugin/src/software/aws/toolkits/eclipse/amazonq/util/QInlineRendererListener.java b/plugin/src/software/aws/toolkits/eclipse/amazonq/util/QInlineRendererListener.java index 62304a51f..bc84035eb 100644 --- a/plugin/src/software/aws/toolkits/eclipse/amazonq/util/QInlineRendererListener.java +++ b/plugin/src/software/aws/toolkits/eclipse/amazonq/util/QInlineRendererListener.java @@ -79,7 +79,8 @@ public final void paintControl(final PaintEvent e) { int y = location.y + lineHt * 2 - fontHt; gc.drawText(remainder, x, y, true); } else { - qInvocationSessionInstance.unsetVerticalIndent(); + int line = widget.getLineAtOffset(widget.getCaretOffset()); + qInvocationSessionInstance.unsetVerticalIndent(line + 1); } } diff --git a/plugin/src/software/aws/toolkits/eclipse/amazonq/util/QInvocationSession.java b/plugin/src/software/aws/toolkits/eclipse/amazonq/util/QInvocationSession.java index 28f707413..42955376e 100644 --- a/plugin/src/software/aws/toolkits/eclipse/amazonq/util/QInvocationSession.java +++ b/plugin/src/software/aws/toolkits/eclipse/amazonq/util/QInvocationSession.java @@ -19,6 +19,7 @@ import java.util.Stack; import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; +import java.util.function.Consumer; import static software.aws.toolkits.eclipse.amazonq.util.QConstants.Q_INLINE_HINT_TEXT_STYLE; import static software.aws.toolkits.eclipse.amazonq.util.QEclipseEditorUtils.getActiveTextViewer; @@ -45,7 +46,7 @@ public final class QInvocationSession extends QResource { private int[] headOffsetAtLine = new int[500]; private boolean hasBeenTypedahead = false; private CodeReferenceAcceptanceCallback codeReferenceAcceptanceCallback = null; - private Runnable unsetVerticalIndent; + private Consumer unsetVerticalIndent; // Private constructor to prevent instantiation private QInvocationSession() { @@ -214,12 +215,17 @@ public void transitionToInactiveState() { } public void transitionToDecisionMade() { + var widget = viewer.getTextWidget(); + var caretLine = widget.getLineAtOffset(widget.getCaretOffset()); + transitionToDecisionMade(caretLine + 1); + } + + public void transitionToDecisionMade(final int line) { if (state != QInvocationSessionState.SUGGESTION_PREVIEWING) { return; } state = QInvocationSessionState.DECISION_MADE; - - unsetVerticalIndent(); + unsetVerticalIndent(line); } public void setCaretMovementReason(final CaretMovementReason reason) { @@ -325,15 +331,14 @@ public void executeCallbackForCodeReference() { public void setVerticalIndent(final int line, final int height) { var widget = viewer.getTextWidget(); widget.setLineVerticalIndent(line, height); - unsetVerticalIndent = () -> { - var caretLine = widget.getLineAtOffset(widget.getCaretOffset()); - widget.setLineVerticalIndent(caretLine + 1, 0); + unsetVerticalIndent = (caretLine) -> { + widget.setLineVerticalIndent(caretLine, 0); }; } - public void unsetVerticalIndent() { + public void unsetVerticalIndent(final int caretLine) { if (unsetVerticalIndent != null) { - unsetVerticalIndent.run(); + unsetVerticalIndent.accept(caretLine); unsetVerticalIndent = null; } }