diff --git a/.changes/next-release/bugfix-1b531ca4-5b80-48d9-89e7-ac88adc77ad5.json b/.changes/next-release/bugfix-1b531ca4-5b80-48d9-89e7-ac88adc77ad5.json new file mode 100644 index 00000000000..49848874a00 --- /dev/null +++ b/.changes/next-release/bugfix-1b531ca4-5b80-48d9-89e7-ac88adc77ad5.json @@ -0,0 +1,4 @@ +{ + "type" : "bugfix", + "description" : "Improve the position that inline chat shortcut hint is shown in editor" +} \ No newline at end of file diff --git a/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/inline/InlineChatEditorHint.kt b/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/inline/InlineChatEditorHint.kt index 21e33ab3df1..4ad0e108913 100644 --- a/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/inline/InlineChatEditorHint.kt +++ b/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/inline/InlineChatEditorHint.kt @@ -19,23 +19,26 @@ import javax.swing.JPanel class InlineChatEditorHint { private val hint = createHint() + private val hintXOffset = 20 private fun getHintLocation(editor: Editor): Point { val range = editor.calculateVisibleRange() val document = editor.document val selectionEnd = editor.selectionModel.selectionEnd val isOneLineSelection = isOneLineSelection(editor) - val isBelow = editor.offsetToXY(selectionEnd) !in editor.scrollingModel.visibleArea + val offset = document.getLineEndOffset(document.getLineNumber(selectionEnd)) + val offsetXy = editor.offsetToXY(offset) + val potentialXy = Point(offsetXy.x + hintXOffset, offsetXy.y) + val isBelow = potentialXy !in editor.scrollingModel.visibleArea val areEdgesOutsideOfVisibleArea = editor.selectionModel.selectionStart !in range && editor.selectionModel.selectionEnd !in range val offsetForHint = when { - isOneLineSelection -> selectionEnd areEdgesOutsideOfVisibleArea -> document.getLineEndOffset(getLineByVisualStart(editor, editor.caretModel.offset, true)) isBelow -> document.getLineEndOffset(getLineByVisualStart(editor, selectionEnd, true)) else -> document.getLineEndOffset(getLineByVisualStart(editor, selectionEnd, false)) } val visualPosition = editor.offsetToVisualPosition(offsetForHint) - val hintPoint = HintManagerImpl.getHintPosition(hint, editor, visualPosition, HintManager.RIGHT) - hintPoint.translate(0, if (isBelow) editor.lineHeight else 0) + val hintPoint = HintManagerImpl.getHintPosition(hint, editor, visualPosition, HintManager.RIGHT_UNDER) + hintPoint.translate(if (!isBelow) hintXOffset else 0, if (!isOneLineSelection || isBelow) editor.lineHeight else 0) return hintPoint }