Skip to content

Commit 185f9c6

Browse files
committed
fix(ui): improve layout and scroll behavior in PlanSketch
#331 - Add vertical glue to push content up when there's extra space. - Ensure content panel takes maximum width but doesn't force height. - Use a wrapper panel to ensure proper scroll behavior. - Update toolbar creation to pass target component for proper focus handling. - Adjust alignment and maximum size for consistent UI rendering.
1 parent 0d1eae1 commit 185f9c6

File tree

4 files changed

+36
-11
lines changed

4 files changed

+36
-11
lines changed

core/src/main/kotlin/cc/unitmesh/devti/observer/plan/PlanReviewAction.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ class PlanReviewAction : AnAction() {
3232
val agentStateService = project.getService(AgentStateService::class.java)
3333

3434
val currentPlan = agentStateService.getPlan()
35-
val issue = agentStateService.buildOriginIntention() ?: ""
3635
val plan = MarkdownPlanParser.formatPlanToMarkdown(currentPlan)
3736

3837
val allMessages = agentStateService.getAllMessages()
@@ -44,7 +43,8 @@ class PlanReviewAction : AnAction() {
4443
val systemPrompt = templateRender.getTemplate("plan-reviewer.vm")
4544
val history = withoutCodeMsgs.joinToString {
4645
"# Role ${it.role}\nMessage:\n${it.content}"
47-
}
46+
} + "\nLastPlan: \n$plan\n"
47+
4848

4949
val stream = LlmFactory.create(project).stream(history, systemPrompt)
5050
AutoDevCoroutineScope.scope(project).launch {
@@ -64,7 +64,7 @@ class PlanReviewAction : AnAction() {
6464
}
6565

6666
if (plan !== null) {
67-
agentStateService.updatePlan(result)
67+
agentStateService.updatePlan(plan.text)
6868
}
6969
}
7070
}

core/src/main/kotlin/cc/unitmesh/devti/sketch/ui/plan/PlanSketch.kt

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// filepath: /Volumes/source/ai/autocrud/core/src/main/kotlin/cc/unitmesh/devti/sketch/ui/plan/PlanSketch.kt
12
package cc.unitmesh.devti.sketch.ui.plan
23

34
import cc.unitmesh.devti.observer.agent.AgentStateService
@@ -39,6 +40,9 @@ class PlanController(
3940
contentPanel.add(sectionPanel)
4041
}
4142

43+
// Add a vertical glue to push content up when there's extra space
44+
contentPanel.add(Box.createVerticalGlue())
45+
4246
contentPanel.revalidate()
4347
contentPanel.repaint()
4448
}
@@ -86,14 +90,17 @@ class PlanSketch(
8690
) : JBPanel<PlanSketch>(BorderLayout(JBUI.scale(8), 0)), ExtensionLangSketch {
8791
private val contentPanel = JPanel().apply {
8892
layout = BoxLayout(this, BoxLayout.Y_AXIS)
93+
// Ensure content panel takes maximum width but doesn't force height
94+
maximumSize = Dimension(Int.MAX_VALUE, Int.MAX_VALUE)
95+
alignmentX = LEFT_ALIGNMENT
8996
}
9097

9198
private val toolbarFactory = PlanToolbarFactory(project)
9299
private val planController = PlanController(project, contentPanel, agentTaskItems)
93100

94101
init {
95102
if (!isInToolwindow) {
96-
add(toolbarFactory.createToolbar(), BorderLayout.NORTH)
103+
add(toolbarFactory.createToolbar(this), BorderLayout.NORTH)
97104
border = JBUI.Borders.empty(8)
98105
}
99106

@@ -103,9 +110,18 @@ class PlanSketch(
103110
verticalScrollBarPolicy = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED
104111
horizontalScrollBarPolicy = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER
105112
border = null
113+
114+
// Make sure viewport tracks width but not height
115+
viewport.isOpaque = false
116+
viewport.view = contentPanel
106117
}
107118

108-
add(scrollPane, BorderLayout.CENTER)
119+
// Use a wrapper panel to ensure proper scroll behavior
120+
val wrapperPanel = JPanel(BorderLayout())
121+
wrapperPanel.add(scrollPane, BorderLayout.CENTER)
122+
wrapperPanel.background = JBUI.CurrentTheme.ToolWindow.background()
123+
124+
add(wrapperPanel, BorderLayout.CENTER)
109125

110126
minimumSize = Dimension(200, 0)
111127
background = JBUI.CurrentTheme.ToolWindow.background()
@@ -139,4 +155,3 @@ class PlanSketch(
139155

140156
override fun dispose() {}
141157
}
142-

core/src/main/kotlin/cc/unitmesh/devti/sketch/ui/plan/PlanToolbarFactory.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ import javax.swing.JPanel
2020
* Toolbar factory for creating the plan sketch toolbar
2121
*/
2222
class PlanToolbarFactory(private val project: Project) {
23-
fun createToolbar(): JComponent {
23+
fun createToolbar(component: JComponent): JComponent {
2424
val actionGroup = DefaultActionGroup(createToolbarActions())
2525
val toolbar = ActionManager.getInstance()
26-
.createActionToolbar("PlanSketch", actionGroup, true)
26+
.createActionToolbar("PlanSketch", actionGroup, true).apply {
27+
this.targetComponent = component
28+
}
2729

2830
val titleLabel = JLabel("Thought Plan").apply {
2931
border = JBUI.Borders.empty(0, 10)

core/src/main/kotlin/cc/unitmesh/devti/sketch/ui/plan/SectionPanel.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// filepath: /Volumes/source/ai/autocrud/core/src/main/kotlin/cc/unitmesh/devti/sketch/ui/plan/SectionPanel.kt
12
package cc.unitmesh.devti.sketch.ui.plan
23

34
import cc.unitmesh.devti.AutoDevBundle
@@ -31,14 +32,21 @@ class SectionPanel(
3132
init {
3233
layout = BoxLayout(this, BoxLayout.Y_AXIS)
3334
background = JBUI.CurrentTheme.ToolWindow.background()
35+
36+
alignmentX = LEFT_ALIGNMENT
37+
maximumSize = Dimension(Int.MAX_VALUE, Int.MAX_VALUE)
38+
3439
val titlePanel = createSectionTitlePanel()
3540
add(titlePanel)
3641

3742
planItem.steps.forEach { task ->
38-
add(TaskPanel(project, task) {
43+
val taskPanel = TaskPanel(project, task) {
3944
updateSectionStatus()
4045
onStatusChange()
41-
})
46+
}
47+
48+
taskPanel.alignmentX = LEFT_ALIGNMENT
49+
add(taskPanel)
4250
}
4351

4452
revalidate()
@@ -94,4 +102,4 @@ class SectionPanel(
94102
fun updateSectionStatus() {
95103
planItem.updateCompletionStatus()
96104
}
97-
}
105+
}

0 commit comments

Comments
 (0)