From 9d7da683a1b91bbfefb0d0934f735e11618dd5f6 Mon Sep 17 00:00:00 2001 From: Nate Date: Mon, 16 Sep 2024 13:40:55 -0700 Subject: [PATCH] more fixes to tooltip display --- .../ContinuePluginSelectionListener.kt | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/listeners/ContinuePluginSelectionListener.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/listeners/ContinuePluginSelectionListener.kt index bf262a415..81609a1cc 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/listeners/ContinuePluginSelectionListener.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/listeners/ContinuePluginSelectionListener.kt @@ -29,7 +29,7 @@ class ContinuePluginSelectionListener( private var toolTipComponents: ArrayList = ArrayList() - private fun removeExistingTooltips(editor: Editor) { + private fun removeExistingTooltips(editor: Editor, onComplete : () -> Unit = {}) { ApplicationManager.getApplication().invokeLater { toolTipComponents.forEach { editor.contentComponent.remove(it) @@ -37,6 +37,7 @@ class ContinuePluginSelectionListener( editor.contentComponent.revalidate() editor.contentComponent.repaint() toolTipComponents.clear() + onComplete() } } @@ -72,31 +73,33 @@ class ContinuePluginSelectionListener( FileDocumentManager.getInstance().getFile(document) val filepath = virtualFile?.path ?: "Unknown path" - ApplicationManager.getApplication().invokeLater { - removeExistingTooltips(editor) - editor.contentComponent.layout = null - val line = startLine - 2 - if (line > 0 && startLine < endLine) { - // Get the text on line number "line" + removeExistingTooltips(editor) { + ApplicationManager.getApplication().invokeLater { + editor.contentComponent.layout = null + + val line = startLine - 2 + if (line > 0 && startLine < endLine) { + // Get the text on line number "line" // val text = document.getText(document.getLineStartOffset(line), document.getLineEndOffset(line)) - val pos = LogicalPosition(line, selectedText.split("\n")[0].length + 1) - val y: Int = editor.logicalPositionToXY(pos).y + editor.lineHeight - var x: Int = editor.logicalPositionToXY(pos).x + val pos = LogicalPosition(line, selectedText.split("\n")[0].length + 1) + val y: Int = editor.logicalPositionToXY(pos).y + editor.lineHeight + var x: Int = editor.logicalPositionToXY(pos).x - // Check if x is out of bounds - val maxEditorWidth = editor.contentComponent.width - val maxToolTipWidth = 600 - x = max(0, min(x, maxEditorWidth - maxToolTipWidth)) + // Check if x is out of bounds + val maxEditorWidth = editor.contentComponent.width + val maxToolTipWidth = 600 + x = max(0, min(x, maxEditorWidth - maxToolTipWidth)) - val toolTipComponent = ToolTipComponent(editor, x, y) - toolTipComponents.add(toolTipComponent) - editor.contentComponent.add(toolTipComponent) + val toolTipComponent = ToolTipComponent(editor, x, y) + toolTipComponents.add(toolTipComponent) + editor.contentComponent.add(toolTipComponent) + } + + editor.contentComponent.revalidate() + editor.contentComponent.repaint() } - - editor.contentComponent.revalidate() - editor.contentComponent.repaint() } } }