Skip to content

Commit b94ccc0

Browse files
committed
fix: fix width issue
1 parent a626347 commit b94ccc0

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

src/main/kotlin/cc/unitmesh/devti/custom/CustomIntention.kt

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import cc.unitmesh.devti.gui.chat.ChatActionType
55
import cc.unitmesh.devti.gui.sendToChatPanel
66
import cc.unitmesh.devti.intentions.AbstractChatIntention
77
import cc.unitmesh.devti.provider.ContextPrompter
8-
import cc.unitmesh.devti.provider.builtin.DefaultContextPrompter
98
import com.intellij.openapi.editor.Editor
109
import com.intellij.openapi.project.Project
1110
import com.intellij.openapi.util.NlsSafe
@@ -29,24 +28,26 @@ class CustomIntention(private val intentionConfig: CustomIntentionConfig) : Abst
2928
val withRange = elementWithRange(editor, file, project) ?: return
3029
val selectedText = withRange.first
3130
val psiElement = withRange.second
32-
val prompt: CustomIntentionPrompt = buildCustomPrompt(psiElement!!, selectedText, intentionConfig)
31+
val prompt: CustomIntentionPrompt = buildCustomPrompt(psiElement!!, selectedText)
3332

34-
sendToChatPanel(project, getActionType(), object : ContextPrompter() {
35-
override fun displayPrompt(): String {
36-
return prompt.displayPrompt
37-
}
33+
if (intentionConfig.autoInvoke) {
34+
sendToChatPanel(project, getActionType(), object : ContextPrompter() {
35+
override fun displayPrompt(): String {
36+
return prompt.displayPrompt
37+
}
3838

39-
override fun requestPrompt(): String {
40-
return prompt.requestPrompt
39+
override fun requestPrompt(): String {
40+
return prompt.requestPrompt
41+
}
42+
})
43+
} else {
44+
sendToChatPanel(project) { panel, _ ->
45+
panel.setInput(prompt.displayPrompt)
4146
}
42-
})
47+
}
4348
}
4449

45-
private fun buildCustomPrompt(
46-
psiElement: PsiElement,
47-
selectedText: @NlsSafe String,
48-
config: CustomIntentionConfig,
49-
): CustomIntentionPrompt {
50+
private fun buildCustomPrompt(psiElement: PsiElement, selectedText: @NlsSafe String): CustomIntentionPrompt {
5051
val stringBuilderWriter = StringWriter()
5152
val velocityContext = VelocityContext()
5253

src/main/kotlin/cc/unitmesh/devti/settings/AppSettingsComponent.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import java.awt.Dimension
1414
import java.awt.FontMetrics
1515
import javax.swing.JComponent
1616
import javax.swing.JPanel
17+
import javax.swing.ScrollPaneConstants
1718

1819
class AppSettingsComponent {
1920
val panel: JPanel
@@ -26,7 +27,7 @@ class AppSettingsComponent {
2627
val customEngineServer = JBTextField()
2728
val customEngineToken = JBTextField()
2829
val language = ComboBox(HUMAN_LANGUAGES)
29-
val maxTokenLengthInput = JBTextField(MAX_TOKEN_LENGTH)
30+
val maxTokenLengthInput = JBTextField()
3031

3132
private var myEditor: EditorEx? = null
3233
private val customEnginePrompt by lazy {
@@ -36,7 +37,7 @@ class AppSettingsComponent {
3637
override fun createEditor(): EditorEx {
3738
myEditor = super.createEditor().apply {
3839
setShowPlaceholderWhenFocused(true)
39-
setHorizontalScrollbarVisible(true)
40+
setHorizontalScrollbarVisible(false)
4041
setVerticalScrollbarVisible(true)
4142
setPlaceholder("Enter custom prompt here")
4243

@@ -53,7 +54,7 @@ class AppSettingsComponent {
5354
val metrics: FontMetrics = customEnginePrompt.getFontMetrics(customEnginePrompt.font)
5455
val columnWidth = metrics.charWidth('m')
5556
customEnginePrompt.setOneLineMode(false)
56-
customEnginePrompt.preferredSize = Dimension(25 * columnWidth, 16 * metrics.height)
57+
customEnginePrompt.preferredSize = Dimension(25 * columnWidth, 25 * metrics.height)
5758

5859
panel = FormBuilder.createFormBuilder()
5960
.addLabeledComponent(JBLabel("Language: "), language, 1, false)
@@ -73,6 +74,7 @@ class AppSettingsComponent {
7374
.addLabeledComponent(JBLabel("Custom Engine Prompt (Json): "), customEnginePrompt, 1, true)
7475
.addComponentFillVertically(JPanel(), 0)
7576
.panel
77+
7678
}
7779

7880
val preferredFocusedComponent: JComponent

0 commit comments

Comments
 (0)