Update InlineEditAction.kt

This commit is contained in:
Test 2024-10-01 17:04:53 -07:00
parent 0570e93741
commit dfd37912df

View file

@ -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<CustomPanel>, textArea: JTextArea, inlayRef: Ref<Disposable>, comboBoxRef: Ref<JComboBox<String>>, leftInset: Int, modelTitles: List<String>, 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<CustomPanel>, 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)
}
}
}