From b94ccc0ca443737d54fe31b5b1bcb389d1c1e02a Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Tue, 8 Aug 2023 17:25:08 +0800 Subject: [PATCH] fix: fix width issue --- .../unitmesh/devti/custom/CustomIntention.kt | 29 ++++++++++--------- .../devti/settings/AppSettingsComponent.kt | 8 +++-- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/main/kotlin/cc/unitmesh/devti/custom/CustomIntention.kt b/src/main/kotlin/cc/unitmesh/devti/custom/CustomIntention.kt index 862b6c43e..ea25823ff 100644 --- a/src/main/kotlin/cc/unitmesh/devti/custom/CustomIntention.kt +++ b/src/main/kotlin/cc/unitmesh/devti/custom/CustomIntention.kt @@ -5,7 +5,6 @@ import cc.unitmesh.devti.gui.chat.ChatActionType import cc.unitmesh.devti.gui.sendToChatPanel import cc.unitmesh.devti.intentions.AbstractChatIntention import cc.unitmesh.devti.provider.ContextPrompter -import cc.unitmesh.devti.provider.builtin.DefaultContextPrompter import com.intellij.openapi.editor.Editor import com.intellij.openapi.project.Project import com.intellij.openapi.util.NlsSafe @@ -29,24 +28,26 @@ class CustomIntention(private val intentionConfig: CustomIntentionConfig) : Abst val withRange = elementWithRange(editor, file, project) ?: return val selectedText = withRange.first val psiElement = withRange.second - val prompt: CustomIntentionPrompt = buildCustomPrompt(psiElement!!, selectedText, intentionConfig) + val prompt: CustomIntentionPrompt = buildCustomPrompt(psiElement!!, selectedText) - sendToChatPanel(project, getActionType(), object : ContextPrompter() { - override fun displayPrompt(): String { - return prompt.displayPrompt - } + if (intentionConfig.autoInvoke) { + sendToChatPanel(project, getActionType(), object : ContextPrompter() { + override fun displayPrompt(): String { + return prompt.displayPrompt + } - override fun requestPrompt(): String { - return prompt.requestPrompt + override fun requestPrompt(): String { + return prompt.requestPrompt + } + }) + } else { + sendToChatPanel(project) { panel, _ -> + panel.setInput(prompt.displayPrompt) } - }) + } } - private fun buildCustomPrompt( - psiElement: PsiElement, - selectedText: @NlsSafe String, - config: CustomIntentionConfig, - ): CustomIntentionPrompt { + private fun buildCustomPrompt(psiElement: PsiElement, selectedText: @NlsSafe String): CustomIntentionPrompt { val stringBuilderWriter = StringWriter() val velocityContext = VelocityContext() diff --git a/src/main/kotlin/cc/unitmesh/devti/settings/AppSettingsComponent.kt b/src/main/kotlin/cc/unitmesh/devti/settings/AppSettingsComponent.kt index 2b7c0e9b5..ca9eddd23 100644 --- a/src/main/kotlin/cc/unitmesh/devti/settings/AppSettingsComponent.kt +++ b/src/main/kotlin/cc/unitmesh/devti/settings/AppSettingsComponent.kt @@ -14,6 +14,7 @@ import java.awt.Dimension import java.awt.FontMetrics import javax.swing.JComponent import javax.swing.JPanel +import javax.swing.ScrollPaneConstants class AppSettingsComponent { val panel: JPanel @@ -26,7 +27,7 @@ class AppSettingsComponent { val customEngineServer = JBTextField() val customEngineToken = JBTextField() val language = ComboBox(HUMAN_LANGUAGES) - val maxTokenLengthInput = JBTextField(MAX_TOKEN_LENGTH) + val maxTokenLengthInput = JBTextField() private var myEditor: EditorEx? = null private val customEnginePrompt by lazy { @@ -36,7 +37,7 @@ class AppSettingsComponent { override fun createEditor(): EditorEx { myEditor = super.createEditor().apply { setShowPlaceholderWhenFocused(true) - setHorizontalScrollbarVisible(true) + setHorizontalScrollbarVisible(false) setVerticalScrollbarVisible(true) setPlaceholder("Enter custom prompt here") @@ -53,7 +54,7 @@ class AppSettingsComponent { val metrics: FontMetrics = customEnginePrompt.getFontMetrics(customEnginePrompt.font) val columnWidth = metrics.charWidth('m') customEnginePrompt.setOneLineMode(false) - customEnginePrompt.preferredSize = Dimension(25 * columnWidth, 16 * metrics.height) + customEnginePrompt.preferredSize = Dimension(25 * columnWidth, 25 * metrics.height) panel = FormBuilder.createFormBuilder() .addLabeledComponent(JBLabel("Language: "), language, 1, false) @@ -73,6 +74,7 @@ class AppSettingsComponent { .addLabeledComponent(JBLabel("Custom Engine Prompt (Json): "), customEnginePrompt, 1, true) .addComponentFillVertically(JPanel(), 0) .panel + } val preferredFocusedComponent: JComponent