From 75e2d2f39df30424b3831615ee3720a2844a60a5 Mon Sep 17 00:00:00 2001 From: Test Date: Tue, 1 Oct 2024 10:48:45 -0700 Subject: [PATCH 1/5] feat: improve dropshadow on jb inline edit --- .gitignore | 2 + .../editor/InlineEditAction.kt | 147 ++++++++---------- .../src/main/resources/config_schema.json | 36 ++++- extensions/vscode/continue_rc_schema.json | 41 ++++- extensions/vscode/package-lock.json | 4 +- 5 files changed, 142 insertions(+), 88 deletions(-) diff --git a/.gitignore b/.gitignore index ba5199b56..113c07c43 100644 --- a/.gitignore +++ b/.gitignore @@ -170,3 +170,5 @@ Icon? .aider* notes.md + +manual-testing-sandbox/Continue/.idea/vcs.xml \ No newline at end of file diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/InlineEditAction.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/InlineEditAction.kt index f94214c34..c2dab4527 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/InlineEditAction.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/InlineEditAction.kt @@ -24,38 +24,38 @@ import com.intellij.util.ui.UIUtil import net.miginfocom.swing.MigLayout import org.jdesktop.swingx.JXPanel import org.jdesktop.swingx.JXTextArea -import org.jdesktop.swingx.border.DropShadowBorder import java.awt.* import java.awt.event.* -import java.awt.geom.RoundRectangle2D +import java.awt.geom.Path2D import javax.swing.* import javax.swing.border.EmptyBorder import javax.swing.event.DocumentEvent import javax.swing.event.DocumentListener import javax.swing.plaf.basic.BasicComboBoxUI import kotlin.math.max +import java.awt.geom.RoundRectangle2D +import java.awt.geom.AffineTransform - -const val SHADOW_SIZE = 7 const val MAIN_FONT_SIZE = 13 fun makeTextArea(): JTextArea { - val textArea = CustomTextArea( 2, 40).apply { + val textArea = CustomTextArea(1, 40).apply { lineWrap = true wrapStyleWord = true isOpaque = false background = GetTheme().getSecondaryDark() maximumSize = Dimension(400, Short.MAX_VALUE.toInt()) - margin = JBUI.insets(8) + margin = JBUI.insets(6, 4, 4, 4) // Reduced from 8 to 4 font = UIUtil.getFontWithFallback("Arial", Font.PLAIN, MAIN_FONT_SIZE) + // Set a preferred size with a taller height + preferredSize = Dimension(400, 75) // Added this line } textArea.putClientProperty(UIUtil.HIDE_EDITOR_FROM_DATA_CONTEXT_PROPERTY, true) - return textArea } fun makePanel(project: Project, customPanelRef: Ref, textArea: JTextArea, inlayRef: Ref, comboBoxRef: Ref>, leftInset: Int, modelTitles: List, onEnter: () -> Unit, onCancel: () -> Unit, onAccept: () -> Unit, onReject: () -> Unit): JPanel { - val topPanel = ShadowPanel(MigLayout("wrap 1, insets 4 $leftInset 2 2, gap 0!")).apply { + val topPanel = ShadowPanel(MigLayout("wrap 1, insets 2 ${leftInset + 4} 8 2, gap 0!")).apply { val globalScheme = EditorColorsManager.getInstance().globalScheme val defaultBackground = globalScheme.defaultBackground // background = defaultBackground @@ -63,7 +63,7 @@ fun makePanel(project: Project, customPanelRef: Ref, textArea: JTex isOpaque = false } - val panel = CustomPanel(MigLayout("wrap 1, insets 0, gap 0!, fillx"), project, modelTitles, comboBoxRef, onEnter, onCancel, onAccept, onReject).apply { + val panel = CustomPanel(MigLayout("wrap 1, insets 4 10 0 2, gap 0!, fillx"), project, modelTitles, comboBoxRef, onEnter, onCancel, onAccept, onReject).apply { val globalScheme = EditorColorsManager.getInstance().globalScheme val defaultBackground = globalScheme.defaultBackground background = defaultBackground @@ -71,16 +71,9 @@ fun makePanel(project: Project, customPanelRef: Ref, textArea: JTex putClientProperty(UIUtil.HIDE_EDITOR_FROM_DATA_CONTEXT_PROPERTY, true) preferredSize = textArea.preferredSize - isOpaque = false setup() - - val shadow = DropShadowBorder() - shadow.shadowColor = JBColor(0xb0b0b0, 0x505050) - shadow.isShowRightShadow = true - shadow.isShowBottomShadow = true - shadow.shadowSize = SHADOW_SIZE - border = shadow } + customPanelRef.set(panel) textArea.addComponentListener(object : ComponentAdapter() { @@ -252,6 +245,19 @@ class InlineEditAction : AnAction(), DumbAware { } class CustomPanel(layout: MigLayout, project: Project, modelTitles: List, comboBoxRef: Ref>, onEnter: () -> Unit, onCancel: () -> Unit, onAccept: () -> Unit, onReject: () -> Unit): JPanel(layout) { + private val shadowSize = 5 + private val cornerRadius = 8 + private val shadowColor = Color(0, 0, 0, 40) // Lighter shadow + private val borderColor = Color(128, 128, 128, 128) + private val borderThickness = 1 + private val triangleSize = 6 + private val rightMargin = 3.0 + + init { + isOpaque = false + } + + private val subPanelA: JPanel = JPanel(MigLayout("insets 0, fillx")).apply { val globalScheme = EditorColorsManager.getInstance().globalScheme val defaultBackground = globalScheme.defaultBackground @@ -289,9 +295,8 @@ class CustomPanel(layout: MigLayout, project: Project, modelTitles: List comboBoxRef.set(dropdown) - val rightButton = CustomButton("Submit") { onEnter() }.apply { -// background = GetTheme().getHighlight() - background = JBColor(0xe04573e8.toInt(), 0xe04573e8.toInt()) + val rightButton = CustomButton("↵ Enter") { onEnter() }.apply { + background = JBColor(0x999998.toInt(), 0x999998.toInt()) foreground = JBColor(0xffffffff.toInt(), 0xffffffff.toInt()) } @@ -302,7 +307,7 @@ class CustomPanel(layout: MigLayout, project: Project, modelTitles: List add(rightButton, "align right") } - border = EmptyBorder(4, 8, 4, 8) + border = EmptyBorder(0, 0, 18, 12) // Increased bottom padding from 4 to 8 add(leftButton, "align left") add(rightPanel, "align right") @@ -311,52 +316,17 @@ class CustomPanel(layout: MigLayout, project: Project, modelTitles: List cursor = Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR) } - private val subPanelB: JPanel = JPanel(MigLayout("insets 0, fillx")).apply { - // Get the global color scheme and default background color - val globalScheme = EditorColorsManager.getInstance().globalScheme - val defaultBackground = globalScheme.defaultBackground - - val leftButton = CustomButton("Esc to cancel") { onCancel() }.apply { - foreground = Color(128, 128, 128, 200) - background = defaultBackground - } - - val dropdown = JComboBox(modelTitles.toTypedArray()).apply { - isEditable = true - background = defaultBackground - foreground = Color(128, 128, 128, 200) - font = UIUtil.getFontWithFallback("Arial", Font.PLAIN, 11) - border = EmptyBorder(2, 4, 2, 4) - isOpaque = false - isEditable = false - cursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR) - renderer = DefaultListCellRenderer().apply { - horizontalAlignment = SwingConstants.RIGHT - } - - isVisible = false - -// setUI(TransparentArrowButtonUI()) - } - - val progressBar = JProgressBar() - progressBar.isIndeterminate = true - - val rightPanel = JPanel(MigLayout("insets 0, fillx")).apply { - isOpaque = false - border = EmptyBorder(0, 0, 0, 0) - add(dropdown, "align right") - add(progressBar, "align right") - } - - - - border = EmptyBorder(4, 8, 4, 8) - add(leftButton, "align left") - add(rightPanel, "align right") + private val subPanelB: JPanel = JPanel(BorderLayout()).apply { isOpaque = false - cursor = Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR) + val progressBar = JProgressBar().apply { + isIndeterminate = true + } + + add(progressBar, BorderLayout.CENTER) + + // Add right and bottom insets + border = BorderFactory.createEmptyBorder(0, 0, 20, 16) } private val subPanelC: JPanel = JPanel(MigLayout("insets 0, fillx")).apply { @@ -387,6 +357,7 @@ class CustomPanel(layout: MigLayout, project: Project, modelTitles: List } fun setup() { +// add(subPanelB, "grow, gap 0!") remove(subPanelB) remove(subPanelC) add(subPanelA, "grow, gap 0!") @@ -408,30 +379,41 @@ class CustomPanel(layout: MigLayout, project: Project, modelTitles: List } override fun paintComponent(g: Graphics) { + super.paintComponent(g) + val g2 = g as Graphics2D g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON) - // Draw the rounded border - val borderColor = Color(128, 128, 128, 128) - val borderThickness = 1 - val borderRadius = 8 + val w = width - shadowSize + val h = height - shadowSize + // Create the shape for the tooltip/triangle + val shape = Path2D.Double() + shape.moveTo(borderThickness / 2.0, cornerRadius.toDouble()) + shape.quadTo(borderThickness / 2.0, borderThickness / 2.0, cornerRadius.toDouble(), borderThickness / 2.0) + shape.lineTo(w - cornerRadius.toDouble() - rightMargin, borderThickness / 2.0) + shape.quadTo(w - borderThickness / 2.0 - rightMargin, borderThickness / 2.0, w - borderThickness / 2.0 - rightMargin, cornerRadius.toDouble()) + shape.lineTo(w - borderThickness / 2.0 - rightMargin, h - cornerRadius - triangleSize.toDouble()) + shape.quadTo(w - borderThickness / 2.0 - rightMargin, h - triangleSize.toDouble(), w - cornerRadius.toDouble() - rightMargin, h - triangleSize.toDouble()) + shape.lineTo(triangleSize.toDouble(), h - triangleSize.toDouble()) + shape.lineTo(borderThickness / 2.0, h.toDouble()) + shape.lineTo(borderThickness / 2.0, cornerRadius.toDouble()) + + // Draw shadow + g2.color = shadowColor + g2.fill(shape.createTransformedShape(AffineTransform.getTranslateInstance(shadowSize.toDouble(), shadowSize.toDouble()))) + + // Draw main shape + g2.color = background + g2.fill(shape) + + // Draw border g2.color = borderColor g2.stroke = BasicStroke(borderThickness.toFloat()) - g2.drawRoundRect( - borderThickness / 2, - borderThickness / 2, - width - borderThickness - SHADOW_SIZE + 1, - height - borderThickness - SHADOW_SIZE + 1, - borderRadius, - borderRadius - ) - - super.paintComponent(g) + g2.draw(shape) } } - class CustomButton(text: String, onClick: () -> Unit) : JLabel(text, CENTER) { private var isHovered = false @@ -488,7 +470,7 @@ class CustomTextArea(rows: Int, columns: Int) : JXTextArea("") { if (text.isEmpty()) { g.color = Color(128, 128, 128, 255) g.font = UIUtil.getFontWithFallback("Arial", Font.PLAIN, MAIN_FONT_SIZE) - g.drawString("Enter instructions to edit highlighted code", 8, 20) + g.drawString("Enter instructions...", 3, 20) } super.paintComponent(g) @@ -543,4 +525,5 @@ class TransparentArrowButtonUI : BasicComboBoxUI() { val defaultBackground = globalScheme.defaultBackground comboBox.background = defaultBackground } -} \ No newline at end of file +} + diff --git a/extensions/intellij/src/main/resources/config_schema.json b/extensions/intellij/src/main/resources/config_schema.json index 1f8e85f73..3f340f6ce 100644 --- a/extensions/intellij/src/main/resources/config_schema.json +++ b/extensions/intellij/src/main/resources/config_schema.json @@ -1552,7 +1552,8 @@ "url", "database", "os", - "repo-map" + "repo-map", + "greptile" ], "markdownEnumDescriptions": [ "Reference the contents of the current changes as given by `git diff`", @@ -1576,7 +1577,8 @@ "Reference the contents of a page at a URL", "Reference table schemas", "Operating system and CPU Information", - "Map of files in the repository with important code highlights" + "Map of files in the repository with important code highlights", + "Query your greptile index of the current repo" ], "type": "string" }, @@ -1954,6 +1956,36 @@ }, "required": ["host", "port", "user", "password", "database"] } + }, + { + "if": { + "properties": { + "name": { + "enum": ["greptile"] + } + } + }, + "then": { + "properties": { + "params": { + "properties": { + "GithubToken": { + "title": "GithubToken", + "description": "Your github access token", + "default": "", + "type": "string" + }, + "GreptileToken": { + "title": "GreptileToken", + "description": "Your greptile access token", + "default": "", + "type": "string" + } + } + } + }, + "required": ["GreptileToken", "GithubToken"] + } } ], "required": ["name"] diff --git a/extensions/vscode/continue_rc_schema.json b/extensions/vscode/continue_rc_schema.json index a5ce1dbc4..26877d8a3 100644 --- a/extensions/vscode/continue_rc_schema.json +++ b/extensions/vscode/continue_rc_schema.json @@ -1723,7 +1723,8 @@ "url", "database", "os", - "repo-map" + "repo-map", + "greptile" ], "markdownEnumDescriptions": [ "Reference the contents of the current changes as given by `git diff`", @@ -1747,7 +1748,8 @@ "Reference the contents of a page at a URL", "Reference table schemas", "Operating system and CPU Information", - "Map of files in the repository with important code highlights" + "Map of files in the repository with important code highlights", + "Query your greptile index of the current repo" ], "type": "string" }, @@ -2190,6 +2192,41 @@ "database" ] } + }, + { + "if": { + "properties": { + "name": { + "enum": [ + "greptile" + ] + } + } + }, + "then": { + "properties": { + "params": { + "properties": { + "GithubToken": { + "title": "GithubToken", + "description": "Your github access token", + "default": "", + "type": "string" + }, + "GreptileToken": { + "title": "GreptileToken", + "description": "Your greptile access token", + "default": "", + "type": "string" + } + } + } + }, + "required": [ + "GreptileToken", + "GithubToken" + ] + } } ], "required": [ diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 05833b84e..5bfd16377 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "0.9.213", + "version": "0.9.214", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "0.9.213", + "version": "0.9.214", "license": "Apache-2.0", "dependencies": { "@electron/rebuild": "^3.2.10", From 0570e93741bdd760c9b121db2e583fce675bbf02 Mon Sep 17 00:00:00 2001 From: Test Date: Tue, 1 Oct 2024 14:35:05 -0700 Subject: [PATCH 2/5] update shadow --- docs/static/schemas/config.json | 36 ++++++++- .../editor/InlineEditAction.kt | 78 +++++++++++-------- 2 files changed, 80 insertions(+), 34 deletions(-) diff --git a/docs/static/schemas/config.json b/docs/static/schemas/config.json index 1f8e85f73..3f340f6ce 100644 --- a/docs/static/schemas/config.json +++ b/docs/static/schemas/config.json @@ -1552,7 +1552,8 @@ "url", "database", "os", - "repo-map" + "repo-map", + "greptile" ], "markdownEnumDescriptions": [ "Reference the contents of the current changes as given by `git diff`", @@ -1576,7 +1577,8 @@ "Reference the contents of a page at a URL", "Reference table schemas", "Operating system and CPU Information", - "Map of files in the repository with important code highlights" + "Map of files in the repository with important code highlights", + "Query your greptile index of the current repo" ], "type": "string" }, @@ -1954,6 +1956,36 @@ }, "required": ["host", "port", "user", "password", "database"] } + }, + { + "if": { + "properties": { + "name": { + "enum": ["greptile"] + } + } + }, + "then": { + "properties": { + "params": { + "properties": { + "GithubToken": { + "title": "GithubToken", + "description": "Your github access token", + "default": "", + "type": "string" + }, + "GreptileToken": { + "title": "GreptileToken", + "description": "Your greptile access token", + "default": "", + "type": "string" + } + } + } + }, + "required": ["GreptileToken", "GithubToken"] + } } ], "required": ["name"] diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/InlineEditAction.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/InlineEditAction.kt index c2dab4527..7de540cdc 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/InlineEditAction.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/InlineEditAction.kt @@ -244,7 +244,16 @@ class InlineEditAction : AnAction(), DumbAware { } } -class CustomPanel(layout: MigLayout, project: Project, modelTitles: List, comboBoxRef: Ref>, onEnter: () -> Unit, onCancel: () -> Unit, onAccept: () -> Unit, onReject: () -> Unit): JPanel(layout) { +class CustomPanel( + layout: MigLayout, + project: Project, + modelTitles: List, + comboBoxRef: Ref>, + private val onEnter: () -> Unit, + private val onCancel: () -> Unit, + private val onAccept: () -> Unit, + private val onReject: () -> Unit +) : JPanel(layout) { private val shadowSize = 5 private val cornerRadius = 8 private val shadowColor = Color(0, 0, 0, 40) // Lighter shadow @@ -252,24 +261,28 @@ class CustomPanel(layout: MigLayout, project: Project, modelTitles: List private val borderThickness = 1 private val triangleSize = 6 private val rightMargin = 3.0 + private val closeButton: JComponent = createCloseButton() init { isOpaque = false + add(closeButton, "pos 100% 0 -3 3, w 20!, h 20!") } + private fun createCloseButton(): JComponent { + return CustomButton("X") { onCancel() }.apply { + foreground = Color(128, 128, 128, 200) + background = Color(0, 0, 0, 0) + font = UIUtil.getFontWithFallback("Arial", Font.BOLD, 12) + border = EmptyBorder(2, 6, 2, 6) + } + } private val subPanelA: JPanel = JPanel(MigLayout("insets 0, fillx")).apply { val globalScheme = EditorColorsManager.getInstance().globalScheme val defaultBackground = globalScheme.defaultBackground - - val leftButton = CustomButton("Esc to cancel") { onCancel() }.apply { - foreground = Color(128, 128, 128, 200) - background = defaultBackground - } - val continueSettingsService = service() - val dropdown = JComboBox(modelTitles.toTypedArray()).apply { + setUI(TransparentArrowButtonUI()) isEditable = true background = defaultBackground foreground = Color(128, 128, 128, 200) @@ -279,7 +292,7 @@ class CustomPanel(layout: MigLayout, project: Project, modelTitles: List isEditable = false cursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR) renderer = DefaultListCellRenderer().apply { - horizontalAlignment = SwingConstants.RIGHT + horizontalAlignment = SwingConstants.LEFT } selectedIndex = continueSettingsService.continueState.lastSelectedInlineEditModel?.let { val index = modelTitles.indexOf(it) @@ -289,8 +302,6 @@ class CustomPanel(layout: MigLayout, project: Project, modelTitles: List addActionListener { continueSettingsService.continueState.lastSelectedInlineEditModel = selectedItem as String } - -// setUI(TransparentArrowButtonUI()) } comboBoxRef.set(dropdown) @@ -309,8 +320,8 @@ class CustomPanel(layout: MigLayout, project: Project, modelTitles: List border = EmptyBorder(0, 0, 18, 12) // Increased bottom padding from 4 to 8 - add(leftButton, "align left") - add(rightPanel, "align right") + add(dropdown, "align left") + add(rightPanel, "align right, split 2") isOpaque = false cursor = Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR) @@ -496,34 +507,37 @@ class TransparentArrowButtonUI : BasicComboBoxUI() { override fun paintComponent(g: Graphics) { val g2 = g as Graphics2D g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON) - val size = 6 + g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE) + + val size = 4 // Smaller size val x = (width - size) / 2 - val y = (height - size / 2) / 2 - val triangle = Polygon( - intArrayOf(x, x + size, x + size / 2), - intArrayOf(y, y, (y + size / 1.16).toInt()), - 3 - ) - g2.color = Color.GRAY - g2.fill(triangle) + val y = (height - size) / 2 + + val path = Path2D.Double() + path.moveTo(x.toDouble(), y.toDouble()) + path.lineTo((x + size).toDouble(), y.toDouble()) + path.lineTo((x + size / 2.0), (y + size).toDouble()) + path.closePath() + + g2.color = Color(128, 128, 128, 200) // Light gray, semi-transparent + g2.fill(path) + } + + override fun getPreferredSize(): Dimension { + return Dimension(12, 12) // Smaller button size } }.apply { - border = EmptyBorder(0, 0, 0, 0) -// background = Color(0, 0, 0, 0) isOpaque = false - } - - override fun getInsets(): Insets { - return JBUI.insets(0, 0, 0, 0) + isFocusable = false + isBorderPainted = false + isContentAreaFilled = false } override fun installUI(c: JComponent?) { super.installUI(c) - comboBox.border = EmptyBorder(0, 0, 0, 0) + comboBox.border = EmptyBorder(2, 0, 2, 0) comboBox.isOpaque = false - val globalScheme = EditorColorsManager.getInstance().globalScheme - val defaultBackground = globalScheme.defaultBackground - comboBox.background = defaultBackground + comboBox.background = Color(0, 0, 0, 0) // Fully transparent background } } From dfd37912df051d291e7883ad7aef8fa4b8850a74 Mon Sep 17 00:00:00 2001 From: Test Date: Tue, 1 Oct 2024 17:04:53 -0700 Subject: [PATCH 3/5] Update InlineEditAction.kt --- .../editor/InlineEditAction.kt | 130 ++++++++++++------ 1 file changed, 91 insertions(+), 39 deletions(-) diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/InlineEditAction.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/InlineEditAction.kt index 7de540cdc..0020d260f 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/InlineEditAction.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/InlineEditAction.kt @@ -45,7 +45,7 @@ fun makeTextArea(): JTextArea { isOpaque = false background = GetTheme().getSecondaryDark() maximumSize = Dimension(400, Short.MAX_VALUE.toInt()) - margin = JBUI.insets(6, 4, 4, 4) // Reduced from 8 to 4 + margin = JBUI.insets(6, 4, 0, 4) font = UIUtil.getFontWithFallback("Arial", Font.PLAIN, MAIN_FONT_SIZE) // Set a preferred size with a taller height preferredSize = Dimension(400, 75) // Added this line @@ -55,7 +55,7 @@ fun makeTextArea(): JTextArea { } fun makePanel(project: Project, customPanelRef: Ref, textArea: JTextArea, inlayRef: Ref, comboBoxRef: Ref>, leftInset: Int, modelTitles: List, onEnter: () -> Unit, onCancel: () -> Unit, onAccept: () -> Unit, onReject: () -> Unit): JPanel { - val topPanel = ShadowPanel(MigLayout("wrap 1, insets 2 ${leftInset + 4} 8 2, gap 0!")).apply { + val topPanel = ShadowPanel(MigLayout("wrap 1, insets 2 ${leftInset} 2 2, gap 0!")).apply { val globalScheme = EditorColorsManager.getInstance().globalScheme val defaultBackground = globalScheme.defaultBackground // background = defaultBackground @@ -63,7 +63,7 @@ fun makePanel(project: Project, customPanelRef: Ref, textArea: JTex isOpaque = false } - val panel = CustomPanel(MigLayout("wrap 1, insets 4 10 0 2, gap 0!, fillx"), project, modelTitles, comboBoxRef, onEnter, onCancel, onAccept, onReject).apply { + val panel = CustomPanel(MigLayout("wrap 1, insets 4 10 0 2, gap 0!, fillx"), project, modelTitles, comboBoxRef, onEnter, onCancel, onAccept, onReject, textArea).apply { val globalScheme = EditorColorsManager.getInstance().globalScheme val defaultBackground = globalScheme.defaultBackground background = defaultBackground @@ -197,6 +197,15 @@ fun openInlineEdit(project: Project?, editor: Editor) { } }) + // Listen for key typed events after diff streaming is finished + textArea.addKeyListener(object : KeyAdapter() { + override fun keyTyped(e: KeyEvent) { + if (customPanelRef.get().isFinished) { + customPanelRef.get().setup() + } + } + }) + // Listen for changes to textarea line count textArea.document.addDocumentListener(object : DocumentListener { private var lastNumLines: Int = 0 @@ -252,7 +261,8 @@ class CustomPanel( private val onEnter: () -> Unit, private val onCancel: () -> Unit, private val onAccept: () -> Unit, - private val onReject: () -> Unit + private val onReject: () -> Unit, + private val textArea: JTextArea ) : JPanel(layout) { private val shadowSize = 5 private val cornerRadius = 8 @@ -262,18 +272,31 @@ class CustomPanel( private val triangleSize = 6 private val rightMargin = 3.0 private val closeButton: JComponent = createCloseButton() + private val originalTextColor: Color = textArea.foreground + private val greyTextColor: Color = Color(128, 128, 128, 200) + public var isFinished = false init { isOpaque = false - add(closeButton, "pos 100% 0 -3 3, w 20!, h 20!") + add(closeButton, "pos 100%-25 0 -3 3, w 20!, h 20!") } private fun createCloseButton(): JComponent { return CustomButton("X") { onCancel() }.apply { - foreground = Color(128, 128, 128, 200) + foreground = Color(128, 128, 128, 128) background = Color(0, 0, 0, 0) - font = UIUtil.getFontWithFallback("Arial", Font.BOLD, 12) + font = UIUtil.getFontWithFallback("Arial", Font.BOLD, 10) border = EmptyBorder(2, 6, 2, 6) + toolTipText = "`esc` to cancel" + + addMouseListener(object : MouseAdapter() { + override fun mouseEntered(e: MouseEvent) { + foreground = Color(128, 128, 128, 255) + } + override fun mouseExited(e: MouseEvent) { + foreground = Color(128, 128, 128, 128) + } + }) } } @@ -307,8 +330,9 @@ class CustomPanel( comboBoxRef.set(dropdown) val rightButton = CustomButton("↵ Enter") { onEnter() }.apply { - background = JBColor(0x999998.toInt(), 0x999998.toInt()) - foreground = JBColor(0xffffffff.toInt(), 0xffffffff.toInt()) + background = JBColor(0x33999998.toInt(), 0x33999998.toInt()) + foreground = Color.WHITE + border = EmptyBorder(2, 6, 2, 6) } val rightPanel = JPanel(MigLayout("insets 0, fillx")).apply { @@ -318,7 +342,7 @@ class CustomPanel( add(rightButton, "align right") } - border = EmptyBorder(0, 0, 18, 12) // Increased bottom padding from 4 to 8 + border = EmptyBorder(0, 0, 20, 16) add(dropdown, "align left") add(rightPanel, "align right, split 2") @@ -341,17 +365,20 @@ class CustomPanel( } private val subPanelC: JPanel = JPanel(MigLayout("insets 0, fillx")).apply { - val leftLabel = JLabel("Enter follow-up instructions").apply { + val leftLabel = JLabel("Type to re-prompt").apply { foreground = Color(128, 128, 128, 200) font = UIUtil.getFontWithFallback("Arial", Font.PLAIN, 11) + border = EmptyBorder(0, 4, 0, 0) } - val leftButton = CustomButton("${getAltKeyLabel()}⇧N") { onReject() }.apply { - background = Color(255, 0, 0, 64) + val leftButton = CustomButton("Reject (${getAltKeyLabel()}⇧N)") { onReject() }.apply { + background = Color(239, 68, 68) // text-red-500 + foreground = Color.WHITE } - val rightButton = CustomButton("${getAltKeyLabel()}⇧Y") { onAccept() }.apply { - background = Color(0, 255, 0, 64) + val rightButton = CustomButton("Accept (${getAltKeyLabel()}⇧Y)") { onAccept() }.apply { + background = Color(34, 197, 94) // text-green-500 + foreground = Color.WHITE } val rightPanel = JPanel(MigLayout("insets 0, fillx")).apply { @@ -363,15 +390,19 @@ class CustomPanel( add(leftLabel, "align left") add(rightPanel, "align right") - border = EmptyBorder(4, 8, 4, 8) + // Add right and bottom insets + border = BorderFactory.createEmptyBorder(0, 0, 20, 16) isOpaque = false } fun setup() { -// add(subPanelB, "grow, gap 0!") remove(subPanelB) remove(subPanelC) add(subPanelA, "grow, gap 0!") + isFinished = false + revalidate() + repaint() + textArea.foreground = originalTextColor } fun enter() { @@ -387,6 +418,8 @@ class CustomPanel( add(subPanelC, "grow, gap 0!") revalidate() repaint() + isFinished = true + textArea.foreground = greyTextColor } override fun paintComponent(g: Graphics) { @@ -507,37 +540,56 @@ class TransparentArrowButtonUI : BasicComboBoxUI() { override fun paintComponent(g: Graphics) { val g2 = g as Graphics2D g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON) - g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE) - - val size = 4 // Smaller size + val size = 6 val x = (width - size) / 2 - val y = (height - size) / 2 - - val path = Path2D.Double() - path.moveTo(x.toDouble(), y.toDouble()) - path.lineTo((x + size).toDouble(), y.toDouble()) - path.lineTo((x + size / 2.0), (y + size).toDouble()) - path.closePath() - - g2.color = Color(128, 128, 128, 200) // Light gray, semi-transparent - g2.fill(path) - } - - override fun getPreferredSize(): Dimension { - return Dimension(12, 12) // Smaller button size + val y = (height - size / 2) / 2 + val triangle = Polygon( + intArrayOf(x, x + size, x + size / 2), + intArrayOf(y, y, (y + size / 1.16).toInt()), + 3 + ) + g2.color = Color.GRAY + g2.fill(triangle) } }.apply { + border = EmptyBorder(0, 0, 0, 0) isOpaque = false - isFocusable = false - isBorderPainted = false - isContentAreaFilled = false + } + + override fun getInsets(): Insets { + return JBUI.insets(0, 6, 0, 0) } override fun installUI(c: JComponent?) { super.installUI(c) - comboBox.border = EmptyBorder(2, 0, 2, 0) comboBox.isOpaque = false - comboBox.background = Color(0, 0, 0, 0) // Fully transparent background + val globalScheme = EditorColorsManager.getInstance().globalScheme + val defaultBackground = globalScheme.defaultBackground + comboBox.background = defaultBackground } + + override fun paintCurrentValueBackground(g: Graphics, bounds: Rectangle, hasFocus: Boolean) { + + // Do nothing to prevent painting the background +} + +override fun paintCurrentValue(g: Graphics, bounds: Rectangle, hasFocus: Boolean) { + val renderer = comboBox.renderer + val item = comboBox.selectedItem + + if (item != null) { + val c = renderer.getListCellRendererComponent(listBox, item, -1, false, false) + c.font = comboBox.font + c.foreground = comboBox.foreground + c.background = comboBox.background + + if (c is JComponent) { + c.isOpaque = false + } + + val currentValuePane = currentValuePane + currentValuePane.paintComponent(g, c, comboBox, bounds.x, bounds.y, bounds.width, bounds.height, true) + } +} } From 25b8b84a80c4838902c271ff31da823b156d674b Mon Sep 17 00:00:00 2001 From: Test Date: Tue, 1 Oct 2024 17:16:32 -0700 Subject: [PATCH 4/5] Update InlineEditAction.kt --- .../editor/InlineEditAction.kt | 146 ++++++++++++------ 1 file changed, 96 insertions(+), 50 deletions(-) diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/InlineEditAction.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/InlineEditAction.kt index 0020d260f..55ad62630 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/InlineEditAction.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/InlineEditAction.kt @@ -45,25 +45,43 @@ fun makeTextArea(): JTextArea { isOpaque = false background = GetTheme().getSecondaryDark() maximumSize = Dimension(400, Short.MAX_VALUE.toInt()) - margin = JBUI.insets(6, 4, 0, 4) + margin = JBUI.insets(6, 4, 6, 4) font = UIUtil.getFontWithFallback("Arial", Font.PLAIN, MAIN_FONT_SIZE) - // Set a preferred size with a taller height - preferredSize = Dimension(400, 75) // Added this line + preferredSize = Dimension(400, 75) } textArea.putClientProperty(UIUtil.HIDE_EDITOR_FROM_DATA_CONTEXT_PROPERTY, true) return textArea } -fun makePanel(project: Project, customPanelRef: Ref, textArea: JTextArea, inlayRef: Ref, comboBoxRef: Ref>, leftInset: Int, modelTitles: List, onEnter: () -> Unit, onCancel: () -> Unit, onAccept: () -> Unit, onReject: () -> Unit): JPanel { +fun makePanel( + project: Project, + customPanelRef: Ref, + textArea: JTextArea, + inlayRef: Ref, + comboBoxRef: Ref>, + leftInset: Int, + modelTitles: List, + onEnter: () -> Unit, + onCancel: () -> Unit, + onAccept: () -> Unit, + onReject: () -> Unit +): JPanel { val topPanel = ShadowPanel(MigLayout("wrap 1, insets 2 ${leftInset} 2 2, gap 0!")).apply { - val globalScheme = EditorColorsManager.getInstance().globalScheme - val defaultBackground = globalScheme.defaultBackground -// background = defaultBackground - background = JBColor(0x20888888.toInt(), 0x20888888.toInt()) + background = JBColor(0x20888888.toInt(), 0x20888888.toInt()) isOpaque = false } - val panel = CustomPanel(MigLayout("wrap 1, insets 4 10 0 2, gap 0!, fillx"), project, modelTitles, comboBoxRef, onEnter, onCancel, onAccept, onReject, textArea).apply { + val panel = CustomPanel( + MigLayout("wrap 1, insets 4 10 0 2, gap 0!, fillx"), + project, + modelTitles, + comboBoxRef, + onEnter, + onCancel, + onAccept, + onReject, + textArea + ).apply { val globalScheme = EditorColorsManager.getInstance().globalScheme val defaultBackground = globalScheme.defaultBackground background = defaultBackground @@ -92,9 +110,9 @@ fun openInlineEdit(project: Project?, editor: Editor) { if (project == null) return // Don't open in terminal - if (EditorUtils().isTerminal(editor)) { - return - } + if (EditorUtils().isTerminal(editor)) { + return + } val manager = EditorComponentInlaysManager.from(editor) @@ -135,7 +153,8 @@ fun openInlineEdit(project: Project?, editor: Editor) { val lineEnd = editor.document.getLineEndOffset(indentationLineNum) val text = editor.document.getText(TextRange(lineStart, lineEnd)) val indentation = text.takeWhile { it == ' ' }.length - val charWidth = editor.contentComponent.getFontMetrics(editor.colorsScheme.getFont(EditorFontType.PLAIN)).charWidth(' ') + val charWidth = + editor.contentComponent.getFontMetrics(editor.colorsScheme.getFont(EditorFontType.PLAIN)).charWidth(' ') val leftInset = indentation * charWidth * 2 / 3 val inlayRef = Ref() @@ -162,16 +181,17 @@ fun openInlineEdit(project: Project?, editor: Editor) { diffStreamHandler.run(textArea.text, prefix, highlighted, suffix, comboBoxRef.get().selectedItem as String) } - val panel = makePanel(project, customPanelRef, textArea, inlayRef, comboBoxRef, leftInset, modelTitles, {onEnter()}, { - diffStreamService.reject(editor) - selectionModel.setSelection(start, end) - }, { - diffStreamService.accept(editor) - inlayRef.get().dispose() - }, { - diffStreamService.reject(editor) - inlayRef.get().dispose() - }) + val panel = + makePanel(project, customPanelRef, textArea, inlayRef, comboBoxRef, leftInset, modelTitles, { onEnter() }, { + diffStreamService.reject(editor) + selectionModel.setSelection(start, end) + }, { + diffStreamService.accept(editor) + inlayRef.get().dispose() + }, { + diffStreamService.reject(editor) + inlayRef.get().dispose() + }) val inlay = manager.insertAfter(lineNumber, panel) panel.revalidate() inlayRef.set(inlay) @@ -216,6 +236,7 @@ fun openInlineEdit(project: Project?, editor: Editor) { viewport?.dispatchEvent(ComponentEvent(viewport, ComponentEvent.COMPONENT_RESIZED)) } } + override fun insertUpdate(e: DocumentEvent?) { updateSize() } @@ -293,6 +314,7 @@ class CustomPanel( override fun mouseEntered(e: MouseEvent) { foreground = Color(128, 128, 128, 255) } + override fun mouseExited(e: MouseEvent) { foreground = Color(128, 128, 128, 128) } @@ -329,7 +351,7 @@ class CustomPanel( comboBoxRef.set(dropdown) - val rightButton = CustomButton("↵ Enter") { onEnter() }.apply { + val rightButton = CustomButton("⏎ Enter") { onEnter() }.apply { background = JBColor(0x33999998.toInt(), 0x33999998.toInt()) foreground = Color.WHITE border = EmptyBorder(2, 6, 2, 6) @@ -359,14 +381,12 @@ class CustomPanel( } add(progressBar, BorderLayout.CENTER) - - // Add right and bottom insets border = BorderFactory.createEmptyBorder(0, 0, 20, 16) } private val subPanelC: JPanel = JPanel(MigLayout("insets 0, fillx")).apply { val leftLabel = JLabel("Type to re-prompt").apply { - foreground = Color(128, 128, 128, 200) + foreground = Color(156, 163, 175) // text-gray-400 font = UIUtil.getFontWithFallback("Arial", Font.PLAIN, 11) border = EmptyBorder(0, 4, 0, 0) } @@ -390,7 +410,6 @@ class CustomPanel( add(leftLabel, "align left") add(rightPanel, "align right") - // Add right and bottom insets border = BorderFactory.createEmptyBorder(0, 0, 20, 16) isOpaque = false } @@ -436,16 +455,33 @@ class CustomPanel( shape.moveTo(borderThickness / 2.0, cornerRadius.toDouble()) shape.quadTo(borderThickness / 2.0, borderThickness / 2.0, cornerRadius.toDouble(), borderThickness / 2.0) shape.lineTo(w - cornerRadius.toDouble() - rightMargin, borderThickness / 2.0) - shape.quadTo(w - borderThickness / 2.0 - rightMargin, borderThickness / 2.0, w - borderThickness / 2.0 - rightMargin, cornerRadius.toDouble()) + shape.quadTo( + w - borderThickness / 2.0 - rightMargin, + borderThickness / 2.0, + w - borderThickness / 2.0 - rightMargin, + cornerRadius.toDouble() + ) shape.lineTo(w - borderThickness / 2.0 - rightMargin, h - cornerRadius - triangleSize.toDouble()) - shape.quadTo(w - borderThickness / 2.0 - rightMargin, h - triangleSize.toDouble(), w - cornerRadius.toDouble() - rightMargin, h - triangleSize.toDouble()) + shape.quadTo( + w - borderThickness / 2.0 - rightMargin, + h - triangleSize.toDouble(), + w - cornerRadius.toDouble() - rightMargin, + h - triangleSize.toDouble() + ) shape.lineTo(triangleSize.toDouble(), h - triangleSize.toDouble()) shape.lineTo(borderThickness / 2.0, h.toDouble()) shape.lineTo(borderThickness / 2.0, cornerRadius.toDouble()) // Draw shadow g2.color = shadowColor - g2.fill(shape.createTransformedShape(AffineTransform.getTranslateInstance(shadowSize.toDouble(), shadowSize.toDouble()))) + g2.fill( + shape.createTransformedShape( + AffineTransform.getTranslateInstance( + shadowSize.toDouble(), + shadowSize.toDouble() + ) + ) + ) // Draw main shape g2.color = background @@ -484,13 +520,21 @@ class CustomButton(text: String, onClick: () -> Unit) : JLabel(text, CENTER) { font = UIUtil.getFontWithFallback("Arial", Font.PLAIN, 11) border = EmptyBorder(2, 4, 2, 4) } + override fun paintComponent(g: Graphics) { val g2 = g as Graphics2D g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON) val cornerRadius = 8 val rect = Rectangle(0, 0, width, height) - val roundRect = RoundRectangle2D.Float(rect.x.toFloat(), rect.y.toFloat(), rect.width.toFloat(), rect.height.toFloat(), cornerRadius.toFloat(), cornerRadius.toFloat()) + val roundRect = RoundRectangle2D.Float( + rect.x.toFloat(), + rect.y.toFloat(), + rect.width.toFloat(), + rect.height.toFloat(), + cornerRadius.toFloat(), + cornerRadius.toFloat() + ) if (isHovered) { g2.color = background.brighter() } else { @@ -498,8 +542,10 @@ class CustomButton(text: String, onClick: () -> Unit) : JLabel(text, CENTER) { } g2.fill(roundRect) g2.color = foreground - g2.drawString(text, (width / 2 - g.fontMetrics.stringWidth(text) / 2).toFloat(), - (height / 2 + g.fontMetrics.ascent / 2).toFloat()) + g2.drawString( + text, (width / 2 - g.fontMetrics.stringWidth(text) / 2).toFloat(), + (height / 2 + g.fontMetrics.ascent / 2).toFloat() + ) } } @@ -570,26 +616,26 @@ class TransparentArrowButtonUI : BasicComboBoxUI() { override fun paintCurrentValueBackground(g: Graphics, bounds: Rectangle, hasFocus: Boolean) { - // Do nothing to prevent painting the background -} + // Do nothing to prevent painting the background + } -override fun paintCurrentValue(g: Graphics, bounds: Rectangle, hasFocus: Boolean) { - val renderer = comboBox.renderer - val item = comboBox.selectedItem + override fun paintCurrentValue(g: Graphics, bounds: Rectangle, hasFocus: Boolean) { + val renderer = comboBox.renderer + val item = comboBox.selectedItem - if (item != null) { - val c = renderer.getListCellRendererComponent(listBox, item, -1, false, false) - c.font = comboBox.font - c.foreground = comboBox.foreground - c.background = comboBox.background + if (item != null) { + val c = renderer.getListCellRendererComponent(listBox, item, -1, false, false) + c.font = comboBox.font + c.foreground = Color(156, 163, 175) // text-gray-400 + c.background = comboBox.background - if (c is JComponent) { - c.isOpaque = false + if (c is JComponent) { + c.isOpaque = false + } + + val currentValuePane = currentValuePane + currentValuePane.paintComponent(g, c, comboBox, bounds.x, bounds.y, bounds.width, bounds.height, true) } - - val currentValuePane = currentValuePane - currentValuePane.paintComponent(g, c, comboBox, bounds.x, bounds.y, bounds.width, bounds.height, true) } } -} From c8482ce9a8b70d11da29dd1d46b7dcb481a1613f Mon Sep 17 00:00:00 2001 From: Test Date: Wed, 2 Oct 2024 12:19:28 -0700 Subject: [PATCH 5/5] Update InlineEditAction.kt --- .../editor/InlineEditAction.kt | 48 +++++++++++-------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/InlineEditAction.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/InlineEditAction.kt index 55ad62630..843fd69c0 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/InlineEditAction.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/editor/InlineEditAction.kt @@ -35,6 +35,7 @@ import javax.swing.plaf.basic.BasicComboBoxUI import kotlin.math.max import java.awt.geom.RoundRectangle2D import java.awt.geom.AffineTransform +import javax.swing.event.ListDataListener const val MAIN_FONT_SIZE = 13 @@ -582,24 +583,9 @@ class ShadowPanel(layout: LayoutManager) : JXPanel(layout) { } class TransparentArrowButtonUI : BasicComboBoxUI() { - override fun createArrowButton() = object : JButton() { - override fun paintComponent(g: Graphics) { - val g2 = g as Graphics2D - g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON) - val size = 6 - val x = (width - size) / 2 - val y = (height - size / 2) / 2 - val triangle = Polygon( - intArrayOf(x, x + size, x + size / 2), - intArrayOf(y, y, (y + size / 1.16).toInt()), - 3 - ) - g2.color = Color.GRAY - g2.fill(triangle) - } - }.apply { - border = EmptyBorder(0, 0, 0, 0) - isOpaque = false + override fun createArrowButton() = JButton().apply { + isVisible = false + preferredSize = Dimension(0, 0) } override fun getInsets(): Insets { @@ -612,13 +598,37 @@ class TransparentArrowButtonUI : BasicComboBoxUI() { val globalScheme = EditorColorsManager.getInstance().globalScheme val defaultBackground = globalScheme.defaultBackground comboBox.background = defaultBackground + + // Modify the ComboBoxModel to include the down symbol + val originalModel = comboBox.model + comboBox.model = object : ComboBoxModel { + override fun getSize(): Int = originalModel.size + override fun getElementAt(index: Int): Any? = originalModel.getElementAt(index) + override fun setSelectedItem(anItem: Any?) { + originalModel.selectedItem = anItem + } + + override fun getSelectedItem(): Any? { + val item = originalModel.selectedItem + return if (item is String) "$item ▾" else item + } + + override fun addListDataListener(l: ListDataListener?) { + originalModel.addListDataListener(l) + } + + override fun removeListDataListener(l: ListDataListener?) { + originalModel.removeListDataListener(l) + } + } } + override fun paintCurrentValueBackground(g: Graphics, bounds: Rectangle, hasFocus: Boolean) { - // Do nothing to prevent painting the background } + override fun paintCurrentValue(g: Graphics, bounds: Rectangle, hasFocus: Boolean) { val renderer = comboBox.renderer val item = comboBox.selectedItem