Skip to content

Commit ad03841

Browse files
authored
fix(amazonq): better location for inline chat editor hint (#5057)
1 parent 0b83303 commit ad03841

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type" : "bugfix",
3+
"description" : "Improve the position that inline chat shortcut hint is shown in editor"
4+
}

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/inline/InlineChatEditorHint.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,26 @@ import javax.swing.JPanel
1919

2020
class InlineChatEditorHint {
2121
private val hint = createHint()
22+
private val hintXOffset = 20
2223

2324
private fun getHintLocation(editor: Editor): Point {
2425
val range = editor.calculateVisibleRange()
2526
val document = editor.document
2627
val selectionEnd = editor.selectionModel.selectionEnd
2728
val isOneLineSelection = isOneLineSelection(editor)
28-
val isBelow = editor.offsetToXY(selectionEnd) !in editor.scrollingModel.visibleArea
29+
val offset = document.getLineEndOffset(document.getLineNumber(selectionEnd))
30+
val offsetXy = editor.offsetToXY(offset)
31+
val potentialXy = Point(offsetXy.x + hintXOffset, offsetXy.y)
32+
val isBelow = potentialXy !in editor.scrollingModel.visibleArea
2933
val areEdgesOutsideOfVisibleArea = editor.selectionModel.selectionStart !in range && editor.selectionModel.selectionEnd !in range
3034
val offsetForHint = when {
31-
isOneLineSelection -> selectionEnd
3235
areEdgesOutsideOfVisibleArea -> document.getLineEndOffset(getLineByVisualStart(editor, editor.caretModel.offset, true))
3336
isBelow -> document.getLineEndOffset(getLineByVisualStart(editor, selectionEnd, true))
3437
else -> document.getLineEndOffset(getLineByVisualStart(editor, selectionEnd, false))
3538
}
3639
val visualPosition = editor.offsetToVisualPosition(offsetForHint)
37-
val hintPoint = HintManagerImpl.getHintPosition(hint, editor, visualPosition, HintManager.RIGHT)
38-
hintPoint.translate(0, if (isBelow) editor.lineHeight else 0)
40+
val hintPoint = HintManagerImpl.getHintPosition(hint, editor, visualPosition, HintManager.RIGHT_UNDER)
41+
hintPoint.translate(if (!isBelow) hintXOffset else 0, if (!isOneLineSelection || isBelow) editor.lineHeight else 0)
3942
return hintPoint
4043
}
4144

0 commit comments

Comments
 (0)