Skip to content

Commit

Permalink
more fixes to tooltip display
Browse files Browse the repository at this point in the history
  • Loading branch information
sestinj committed Sep 16, 2024
1 parent 732609c commit 9d7da68
Showing 1 changed file with 23 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ class ContinuePluginSelectionListener(

private var toolTipComponents: ArrayList<ToolTipComponent> = ArrayList()

private fun removeExistingTooltips(editor: Editor) {
private fun removeExistingTooltips(editor: Editor, onComplete : () -> Unit = {}) {
ApplicationManager.getApplication().invokeLater {
toolTipComponents.forEach {
editor.contentComponent.remove(it)
}
editor.contentComponent.revalidate()
editor.contentComponent.repaint()
toolTipComponents.clear()
onComplete()
}
}

Expand Down Expand Up @@ -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()
}
}
}
}
Expand Down

0 comments on commit 9d7da68

Please sign in to comment.