fix(jetbrains): resize prompt editor with content

This commit is contained in:
kirillk
2026-05-26 17:05:58 -04:00
parent ca55401d52
commit 11d5d2a67b
4 changed files with 61 additions and 6 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@kilocode/kilo-jetbrains": patch
---
Resize the JetBrains prompt editor as prompt lines are added or removed.
@@ -160,6 +160,7 @@ class PromptPanel(
editor.text = ""
editor.addDocumentListener(object : DocumentListener {
override fun documentChanged(e: DocumentEvent) {
syncEditorHeight()
onChange()
}
})
@@ -235,17 +236,13 @@ class PromptPanel(
editor.font = style.transcriptFont
editor.getEditor(false)?.let(style::applyToEditor)
editor.background = style.editorScheme.defaultBackground
val height = style.transcriptFont.size * SessionUiStyle.View.Prompt.EDITOR_LINES + JBUI.scale(
SessionUiStyle.View.Prompt.EDITOR_CHROME)
editor.preferredSize = JBDimension(0, height)
editor.minimumSize = JBDimension(0, height)
revalidate()
repaint()
syncEditorHeight()
}
@RequiresEdt
fun clear() {
editor.text = ""
syncEditorHeight()
}
@RequiresEdt
@@ -328,6 +325,20 @@ class PromptPanel(
return KiloBundle.message("prompt.placeholder")
}
@RequiresEdt
private fun syncEditorHeight() {
val lines = (editor.document.lineCount + SessionUiStyle.View.Prompt.EDITOR_SPARE_LINES).coerceIn(
SessionUiStyle.View.Prompt.EDITOR_LINES,
SessionUiStyle.View.Prompt.EDITOR_MAX_LINES,
)
val height = style.transcriptFont.size * lines + JBUI.scale(SessionUiStyle.View.Prompt.EDITOR_CHROME)
if (editor.preferredSize.height == height && editor.minimumSize.height == height) return
editor.preferredSize = JBDimension(0, height)
editor.minimumSize = JBDimension(0, height)
revalidate()
repaint()
}
private inner class SendButton : JButton(), UiDataProvider {
private var over = false
@@ -47,6 +47,8 @@ object SessionUiStyle {
/** Prompt input dimensions and chrome inside the session view. */
object Prompt {
const val EDITOR_LINES = 3
const val EDITOR_MAX_LINES = 8
const val EDITOR_SPARE_LINES = 1
const val EDITOR_CHROME = 16
const val SEND_BUTTON_SIZE = 24
const val CORNER_ARC = 6
@@ -8,6 +8,7 @@ import com.intellij.openapi.actionSystem.DataSink
import com.intellij.openapi.actionSystem.UiDataProvider
import com.intellij.openapi.keymap.KeymapUtil
import com.intellij.testFramework.fixtures.BasePlatformTestCase
import com.intellij.ui.EditorTextField
import com.intellij.util.ui.EmptyIcon
import javax.swing.SwingUtilities
@@ -41,6 +42,42 @@ class PromptPanelTest : BasePlatformTestCase() {
assertTrue(panel.preferredSize.height >= 26)
}
fun `test prompt editor grows when lines are added`() {
val panel = PromptPanel(project, {}, {})
val editor = panel.defaultFocusedComponent as EditorTextField
val min = editor.preferredSize.height
editor.text = "one\ntwo\nthree\nfour\nfive"
assertTrue(editor.preferredSize.height > min)
}
fun `test prompt editor shrinks when lines are removed`() {
val panel = PromptPanel(project, {}, {})
val editor = panel.defaultFocusedComponent as EditorTextField
val min = editor.preferredSize.height
editor.text = "one\ntwo\nthree\nfour\nfive"
assertTrue(editor.preferredSize.height > min)
editor.text = "one"
assertEquals(min, editor.preferredSize.height)
}
fun `test prompt editor shrinks after clear`() {
val panel = PromptPanel(project, {}, {})
val editor = panel.defaultFocusedComponent as EditorTextField
val min = editor.preferredSize.height
editor.text = "one\ntwo\nthree\nfour\nfive"
assertTrue(editor.preferredSize.height > min)
panel.clear()
assertEquals(min, editor.preferredSize.height)
}
fun `test reasoning picker hides when variants are empty`() {
val panel = PromptPanel(project, {}, {})