Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/jetbrains-faster-tab-switching.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kilocode/kilo-jetbrains": patch
---

Speed up switching between JetBrains session and worktree editor tabs, and reduce Agent Manager list repaint cost while sessions are running.
3 changes: 3 additions & 0 deletions packages/kilo-jetbrains/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ Swing is retained-mode UI. For dynamic Swing surfaces such as session cards, tra
- Expandable session cards extend `AbstractSessionPartView`, which binds click-to-toggle and hover across the whole header subtree automatically (including children added later). Do not re-bind header parts per view. A header control that must not toggle the card (file link, copy button, toolbar action) simply owns its own mouse listener and is skipped automatically.
- Hover should update only the affected component (usually the header background) and repaint only that component when the effective color changed.
- Lazy-create expensive bodies such as `JBTextArea`, `JBScrollPane`, markdown panes, and HTML panes on first expansion or first direct access.
- Keep what every transcript card carries for the whole session small. Every editor tab switch walks the entire transcript tree, so attach rarely shown header parts (the expand arrow, a file link, a copy placeholder) only while they show instead of keeping them attached and hidden.
- Parent containers should refresh for add/remove/reorder operations, not automatically after every delegated child update or streaming delta.
- Child views should call `revalidate()`/`repaint()` only when they changed preferred size, visibility, containment, or paint output.
- Empty deltas, identical text, unchanged styles, repeated hover values, and no-op toggles should not repaint the whole card.
Expand Down Expand Up @@ -430,6 +431,7 @@ Generic utilities:
|---|---|
| Rich HTML with modern CSS, icons, shortcuts | `JBHtmlPane` (`com.intellij.ui.components.JBHtmlPane`) |
| Simple multi-line label with HTML | `JBLabel` + `XmlStringUtil.wrapInHtml()` |
| Single-line transcript text (tool headers, file links, to-do rows) | `PlainLabel` (`ai.kilocode.client.ui.PlainLabel`) with `underline`/`strike`; never `<html>` text, because Swing re-parses every HTML label each time an editor tab is detached or re-attached |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This AGENTS.md file is getting too long. At this size you will greatly degrade model output quality with that. Would it make sense to extract certain parts to skills instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I's been working better and better for me in time but I think it makes sense to re-iterate on that. I planned to make a clean up day this week that would include checking for bad smells, code duplication, memory leaks and running the profiler. I think I will add this to the plan too, that makes sense.

| Scrollable / wrapping HTML panel | `SwingHelper.createHtmlViewer()` |
| High-performance colored text fragments in trees/lists/tables | `SimpleColoredComponent` |
| Plain-text newline splitting | `MultiLineLabel` — legacy, do not use in new code |
Expand Down Expand Up @@ -549,6 +551,7 @@ Stack.horizontal()
- Use `fill(size)`, `Stack.verticalFiller(size)`, or `Stack.horizontalFiller(size)` for persistent leading, trailing, or interstitial whitespace. Do not use `Box` or `gap(size)` for persistent spacing.
- Use `Stack` for simple retained Swing rows/columns where children should track the cross-axis size. Use `Align` for positioning one child inside available space.
- Do not use `Stack` for padding, borders, colors, wrapping rows, flexible glue, or transcript components that need width-aware HTML reflow. Use `JBUI.Borders.empty(...)`, `UiStyle.Gap`, purpose-built layouts, or `SessionLayout` for those concerns.
- `Stack` and `Align` ask each child for its minimum, preferred and maximum size, so measuring a deep invalid tree grows with every nesting level. A tree that is invalidated and measured over and over, such as a list renderer stamp, should run each layout or size read inside `LayoutPass.measure { ... }`, which answers each size once per container for that pass. Do not change the measured content inside the pass.

### Align — Single-Component Alignment Wrapper

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package ai.kilocode.client.session.ui.attachment

import ai.kilocode.client.plugin.KiloBundle
import ai.kilocode.client.session.ui.fileLinkHtml
import ai.kilocode.client.session.ui.style.SessionUiStyle
import ai.kilocode.client.ui.PlainLabel
import ai.kilocode.client.ui.UiStyle
import ai.kilocode.client.ui.iconButton
import ai.kilocode.client.ui.oneLine
import ai.kilocode.client.ui.layout.HAlign
import ai.kilocode.client.ui.layout.VAlign
import ai.kilocode.client.ui.layout.align
Expand Down Expand Up @@ -69,7 +70,8 @@ class AttachmentChip(
cursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)
toolTipText = tip
accessibleContext?.accessibleName = KiloBundle.message("prompt.attachment.open", item.name)
val label = JBLabel(fileLinkHtml(label())).apply {
val label = PlainLabel(oneLine(label())).apply {
underline = true
icon = attachmentIcon(item.mime, item.name)
iconTextGap = JBUI.scale(SessionUiStyle.View.Attachment.CHIP_ICON_GAP)
toolTipText = tip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ open class TextView(
md.addLinkListener { onLink(it) }
applyStyle(SessionEditorStyle.current())
add(md.component, BorderLayout.CENTER)
add(placeholder, BorderLayout.SOUTH)
if (text.content.isNotEmpty()) md.set(text.content.toString())
syncContent()
syncToolbar()
Expand Down Expand Up @@ -139,12 +138,16 @@ open class TextView(
md.component.isVisible = md.markdown().isNotBlank()
}

/**
* At most one text part per assistant message carries a copy toolbar, so the placeholder that reserves its
* slot joins the tree only while the toolbar is on rather than sitting hidden under every text part.
*/
@RequiresEdt
private fun syncToolbar() {
val on = copyText()?.isNotEmpty() == true
toolbar.sync(on)
if (placeholder.isVisible == on) return
placeholder.isVisible = on
if ((placeholder.parent === this) == on) return
if (on) add(placeholder, BorderLayout.SOUTH) else remove(placeholder)
refresh()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,24 @@ abstract class AbstractSessionPartView(
fun syncExpandable(expandable: Boolean): Boolean {
val active = this.expandable && expandable
val changed = setVisible(arrow, active)
syncArrowSlot(active)
val detached = if (active) false else collapse()
val cursor = if (active) Cursor.getPredefinedCursor(Cursor.HAND_CURSOR) else Cursor.getDefaultCursor()
val moved = syncCursor(cursor)
val icon = syncArrow()
return changed || detached || moved || icon
}

/**
* Keeps the arrow in the header row only while the card can toggle. A hidden component is still walked by
* every tree traversal (graphics-configuration updates on tab switch, component searches during painting),
* and most transcript cards never become expandable, so the arrow stays out of the tree until needed.
*/
private fun syncArrowSlot(active: Boolean) {
if (active == (arrow.parent === row)) return
if (active) row.add(arrow, BorderLayout.EAST) else row.remove(arrow)
}

protected fun refresh() {
revalidate()
repaint()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import ai.kilocode.client.plugin.KiloBundle
import ai.kilocode.client.session.ui.SessionSurface
import ai.kilocode.client.session.ui.style.SessionEditorStyle
import ai.kilocode.client.session.ui.style.SessionUiStyle
import ai.kilocode.client.ui.PlainLabel
import ai.kilocode.client.ui.UiStyle
import ai.kilocode.client.ui.layout.Stack
import ai.kilocode.client.ui.layout.StackAxis
import ai.kilocode.client.ui.oneLine
import ai.kilocode.rpc.dto.TodoDto
import com.intellij.ui.components.JBLabel
import com.intellij.util.ui.JBUI
import com.intellij.xml.util.XmlStringUtil
import java.awt.BasicStroke
import java.awt.Color
import java.awt.Component
Expand Down Expand Up @@ -83,7 +84,7 @@ class TodoListPanel(

internal fun rowCheckBorder(index: Int) = rows[index].icon.border

internal fun rowCheckAccessibleName(index: Int) = rows[index].check.accessibleContext.accessibleName
internal fun rowCheckAccessibleName(index: Int) = rows[index].text.accessibleContext.accessibleName

internal fun rowFont(index: Int) = rows[index].text.font

Expand All @@ -98,7 +99,7 @@ class TodoListPanel(
items.forEach { todo ->
val row = Row(todo, style)
rows.add(row)
next(row.panel)
next(row.text)
}
next(later)
syncHidden()
Expand All @@ -122,18 +123,18 @@ class TodoListPanel(
return KiloBundle.message(key, count)
}

/**
* One label per row: the check box is the label's icon rather than a sibling component, so a to-do list
* adds a single component per item to the transcript tree.
*/
private class Row(todo: TodoDto, style: SessionEditorStyle) {
var icon = TodoCheckIcon(false)
private set
val check = JBLabel().apply {
val text = PlainLabel().apply {
isFocusable = false
icon = this@Row.icon
}
val text = JBLabel()
val panel = Stack.horizontal(UiStyle.Gap.sm()).apply {
iconTextGap = UiStyle.Gap.sm()
border = JBUI.Borders.empty(UiStyle.Gap.xs(), 0)
next(check)
next(text)
}

init {
Expand All @@ -143,9 +144,10 @@ class TodoListPanel(
fun update(todo: TodoDto, style: SessionEditorStyle) {
val done = todo.status == "completed"
syncIcon(done)
check.accessibleContext.accessibleName = KiloBundle.message(accessible(done), todo.content)
check.accessibleContext.accessibleDescription = check.accessibleContext.accessibleName
text.text = label(todo.content, done)
text.accessibleContext.accessibleName = KiloBundle.message(accessible(done), todo.content)
text.accessibleContext.accessibleDescription = text.accessibleContext.accessibleName
text.text = oneLine(todo.content)
text.strike = done
text.font = style.regularFont
text.foreground = when {
!done -> style.editorForeground
Expand All @@ -159,13 +161,7 @@ class TodoListPanel(
val border = SessionUiStyle.View.Todo.checkBorder()
if (icon.done == done && icon.bg == bg && icon.fg == fg && icon.border == border) return
icon = TodoCheckIcon(done, bg, fg, border)
check.icon = icon
}

private fun label(value: String, done: Boolean): String {
val text = XmlStringUtil.escapeString(value)
if (!done) return "<html>$text</html>"
return "<html><s>$text</s></html>"
text.icon = icon
}

private fun accessible(done: Boolean) = if (done) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ abstract class BaseSearchToolView(
parts.targets.forEachIndexed { index, label ->
val text = values.getOrNull(index) ?: ""
changed = setVisible(label, text.isNotBlank()) || changed
changed = setTargetText(label, text) || changed
changed = setText(label, text) || changed
changed = setForeground(label, SessionUiStyle.Colors.foreground()) || changed
}
return changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import ai.kilocode.client.session.views.base.PartHeader
import ai.kilocode.client.session.views.base.AbstractSessionPartView
import ai.kilocode.client.session.views.base.HeaderOpenAction
import ai.kilocode.client.ui.DiffStatBadge
import ai.kilocode.client.ui.PlainLabel
import ai.kilocode.client.ui.UiStyle
import ai.kilocode.client.ui.md.MdCodeBlockBorder
import ai.kilocode.client.ui.md.MdCodeBlockOptions
Expand All @@ -26,7 +27,6 @@ import com.intellij.openapi.actionSystem.DataSink
import com.intellij.openapi.actionSystem.UiDataProvider
import com.intellij.openapi.util.Disposer
import com.intellij.ui.EditorTextField
import com.intellij.ui.components.JBLabel
import com.intellij.util.concurrency.annotations.RequiresEdt
import com.intellij.util.ui.JBFont
import java.awt.Dimension
Expand Down Expand Up @@ -57,7 +57,7 @@ class EditToolView(
private var canDiff = false
private val badge = DiffStatBadge(0, 0)
private val open = HeaderOpenAction(SessionViewIcons.openDiff, KiloBundle.message("session.part.tool.openDiff"), ::openDiffViewer)
private val filesTag = JBLabel().apply {
private val filesTag = PlainLabel().apply {
foreground = SessionUiStyle.Text.Secondary.foreground()
font = JBFont.small()
isVisible = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ReadToolView(
tool: Tool,
openFile: SessionFileOpener = { _, _ -> },
private val selection: SessionSelection? = null,
private val parts: ToolParts = toolParts(tool, openFile),
private val parts: ToolParts = toolParts(tool, openFile, link = true),
) : AbstractSessionPartView(parts.header, { parts.scroll(tool) }, expandable = false) {

companion object {
Expand Down Expand Up @@ -81,7 +81,7 @@ class ReadToolView(
@RequiresEdt
internal fun linkText() = parts.label
@RequiresEdt
internal fun linkMarkup() = parts.link.text ?: ""
internal fun linkUnderline() = parts.link.underline
@RequiresEdt
internal fun linkForeground() = parts.link.foreground
@RequiresEdt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class ShellToolView(
internal fun subtitleForeground() = parts.sub.foreground

@RequiresEdt
internal fun subtitleMarkup() = parts.sub.text ?: ""
internal fun subtitleValue() = parts.sub.text ?: ""

@RequiresEdt
internal fun stateFont() = parts.state.font
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import ai.kilocode.client.session.views.SessionViewIcons
import ai.kilocode.client.session.views.base.AbstractSessionPartView
import ai.kilocode.client.session.views.base.HeaderOpenAction
import ai.kilocode.client.ui.HoverIcon
import ai.kilocode.client.ui.PlainLabel
import ai.kilocode.client.ui.UiStyle
import ai.kilocode.client.ui.layout.Stack
import ai.kilocode.client.ui.layout.StackAxis
Expand Down Expand Up @@ -380,8 +381,8 @@ class TaskToolView(
private class Row(tool: Tool) {
private var item = tool
val icon = JBLabel()
val title = JBLabel()
val sub = JBLabel().apply { foreground = SessionUiStyle.Text.Secondary.foreground() }
val title = PlainLabel()
val sub = PlainLabel().apply { foreground = SessionUiStyle.Text.Secondary.foreground() }
val panel = JPanel(BorderLayout(UiStyle.Gap.md(), 0)).apply {
isOpaque = false
add(icon, BorderLayout.WEST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ai.kilocode.client.session.model.Tool
import ai.kilocode.client.session.ui.style.SessionEditorStyle
import ai.kilocode.client.session.ui.style.SessionUiStyle
import ai.kilocode.client.session.views.SessionViewIcons
import ai.kilocode.client.ui.PlainLabel
import ai.kilocode.client.ui.UiStyle
import ai.kilocode.client.ui.layout.Stack
import ai.kilocode.client.ui.layout.StackAxis
Expand All @@ -18,7 +19,7 @@ interface ApprovalReasonTarget {

class ToolApprovalFooter : Stack(StackAxis.HORIZONTAL, UiStyle.Gap.sm()) {
private val glyph = JBLabel(SessionViewIcons.shield)
private val label = JBLabel()
private val label = PlainLabel()

init {
next(glyph)
Expand Down
Loading
Loading