Skip to content

Commit

Permalink
fix: fix width issue
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Aug 8, 2023
1 parent a626347 commit b94ccc0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
29 changes: 15 additions & 14 deletions src/main/kotlin/cc/unitmesh/devti/custom/CustomIntention.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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")

Expand All @@ -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)
Expand All @@ -73,6 +74,7 @@ class AppSettingsComponent {
.addLabeledComponent(JBLabel("Custom Engine Prompt (Json): "), customEnginePrompt, 1, true)
.addComponentFillVertically(JPanel(), 0)
.panel

}

val preferredFocusedComponent: JComponent
Expand Down

0 comments on commit b94ccc0

Please sign in to comment.