From 128ce6c0f1950cebdb97534889438de3e9beac48 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Wed, 1 Jan 2025 20:52:10 +0800 Subject: [PATCH] refactor(ui): simplify and enhance border styling #157 Removed redundant border-related code and streamlined the border creation process. Updated background and border colors for consistency. Improved focus traversal and component layout. Simplified text submission logic by trimming text before clearing the input area. --- .../shire/inline/ShireInlineChatService.kt | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/com/phodal/shire/inline/ShireInlineChatService.kt b/src/main/kotlin/com/phodal/shire/inline/ShireInlineChatService.kt index 4744f495..7e4244cf 100644 --- a/src/main/kotlin/com/phodal/shire/inline/ShireInlineChatService.kt +++ b/src/main/kotlin/com/phodal/shire/inline/ShireInlineChatService.kt @@ -29,7 +29,6 @@ import java.awt.event.* import java.awt.geom.Rectangle2D import java.util.concurrent.ConcurrentHashMap import javax.swing.* -import javax.swing.border.Border import kotlin.collections.set @Service(Service.Level.APP) @@ -104,7 +103,7 @@ class ShireInlineChatPanel(val editor: Editor) : JPanel(GridBagLayout()), Editor val panelView = ShirePanelView(project, showInput = false) panelView.minimumSize = Dimension(800, 100) setContent(panelView) - this@ShireInlineChatPanel.redraw() + ShireCoroutineScope.scope(project).launch { val suggestion = StringBuilder() panelView.onStart() @@ -125,14 +124,23 @@ class ShireInlineChatPanel(val editor: Editor) : JPanel(GridBagLayout()), Editor private var container: Container? = null init { - val createEmptyBorder = BorderFactory.createEmptyBorder(12, 12, 12, 12) - val roundedLineBorder: Border = RoundedLineBorder(JBColor(Gray.xCD, Gray.x4D), 8, 1) - border = BorderFactory.createCompoundBorder(createEmptyBorder, roundedLineBorder) + val bgColor = JBColor(Color.LIGHT_GRAY, Color.LIGHT_GRAY) + val borderColor = JBColor(Color.LIGHT_GRAY, Color.LIGHT_GRAY) + + border = BorderFactory.createCompoundBorder( + BorderFactory.createCompoundBorder( + BorderFactory.createEmptyBorder(12, 12, 12, 12), + RoundedLineBorder(bgColor, 8, 1) + ), + BorderFactory.createCompoundBorder( + RoundedLineBorder(borderColor, 8, 1), + BorderFactory.createMatteBorder(10, 10, 10, 10, borderColor) + ) + ) isOpaque = false cursor = Cursor.getPredefinedCursor(0) - background = JBColor(Gray.x99, Gray.x78) - minimumSize = Dimension(800, 100) + background = borderColor val c = GridBagConstraints() c.gridx = 0 @@ -156,8 +164,6 @@ class ShireInlineChatPanel(val editor: Editor) : JPanel(GridBagLayout()), Editor c.fill = 1 add(this.centerPanel, c) - isFocusCycleRoot = true - focusTraversalPolicy = LayoutFocusTraversalPolicy() this.inAllChildren { child -> child.addComponentListener(object : ComponentAdapter() { @@ -166,6 +172,9 @@ class ShireInlineChatPanel(val editor: Editor) : JPanel(GridBagLayout()), Editor } }) } + + isFocusCycleRoot = true + focusTraversalPolicy = LayoutFocusTraversalPolicy() } override fun calcWidthInPixels(inlay: Inlay<*>): Int = size.width @@ -276,8 +285,9 @@ class ShireInlineChatInputPanel( } private fun submit() { + val trimText = textArea.text.trim() textArea.text = "" - onSubmit(textArea.text.trim()) + onSubmit(trimText) } fun getInputComponent(): Component = textArea