Skip to content
This repository was archived by the owner on Nov 4, 2024. It is now read-only.

Commit 7d8b5ec

Browse files
committed
feat(settings): add prompt text area and enable word wrapping
Added a prompt text area to the settings UI and enabled word wrapping for better readability.
1 parent f8c20fe commit 7d8b5ec

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

src/main/kotlin/com/github/blarc/ai/commits/intellij/plugin/settings/AppSettingsConfigurable.kt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import com.aallam.openai.api.exception.OpenAIAPIException
44
import com.github.blarc.ai.commits.intellij.plugin.AICommitsBundle.message
55
import com.github.blarc.ai.commits.intellij.plugin.OpenAIService
66
import com.intellij.icons.AllIcons
7-
import com.intellij.ide.starters.shared.withValidation
87
import com.intellij.openapi.options.BoundConfigurable
98
import com.intellij.openapi.progress.runBackgroundableTask
109
import com.intellij.ui.components.JBLabel
@@ -46,15 +45,29 @@ class AppSettingsConfigurable : BoundConfigurable(message("settings.general.grou
4645

4746
// Prompt to use with OpenAI
4847
row {
49-
textField()
48+
val promptTextArea = textArea()
5049
.label(message("settings.prompt"))
5150
.bindText(
5251
{ AppSettings.instance.getPrompt() },
5352
{ AppSettings.instance.savePrompt(it) }
5453
)
5554
.align(Align.FILL)
5655
.resizableColumn()
56+
57+
promptTextArea.component.wrapStyleWord = true
58+
promptTextArea.component.lineWrap = true
59+
60+
promptTextArea.component.addCaretListener {
61+
val fontMetrics = promptTextArea.component.getFontMetrics(promptTextArea.component.font)
62+
val lineHeight = fontMetrics.height
63+
val contentWidth = promptTextArea.component.size.width - promptTextArea.component.insets.left - promptTextArea.component.insets.right
64+
val maxLineWidth = promptTextArea.component.ui.getPreferredSize(promptTextArea.component).width
65+
val contentHeight = promptTextArea.component.preferredSize.height
66+
val rows = ((contentHeight / lineHeight).coerceAtLeast(1) * maxLineWidth / contentWidth).coerceAtLeast(1)
67+
promptTextArea.rows(rows)
68+
}
5769
}
70+
5871
}
5972

6073
@OptIn(DelicateCoroutinesApi::class)

0 commit comments

Comments
 (0)