@@ -35,6 +35,8 @@ type AssistantMessageItem struct {
35 thinkingBoxHeight int // Tracks the rendered thinking box height for click detection.
35 thinkingBoxHeight int // Tracks the rendered thinking box height for click detection.
38+var _ Expandable = (*AssistantMessageItem)(nil)
38// NewAssistantMessageItem creates a new AssistantMessageItem.
40// NewAssistantMessageItem creates a new AssistantMessageItem.
39func NewAssistantMessageItem(sty *styles.Styles, message *message.Message) MessageItem {
41func NewAssistantMessageItem(sty *styles.Styles, message *message.Message) MessageItem {
40 a := &AssistantMessageItem{
42 a := &AssistantMessageItem{
@@ -249,23 +251,26 @@ func (a *AssistantMessageItem) SetMessage(message *message.Message) tea.Cmd {
249 return nil
251 return nil
252−// ToggleExpanded toggles the expanded state of the thinking box.
254+// ToggleExpanded toggles the expanded state of the thinking box and returns
255+// whether the item is now expanded.
253−func (a *AssistantMessageItem) ToggleExpanded() {
256+func (a *AssistantMessageItem) ToggleExpanded() bool {
254 a.thinkingExpanded = !a.thinkingExpanded
257 a.thinkingExpanded = !a.thinkingExpanded
255 a.clearCache()
258 a.clearCache()
259+ return a.thinkingExpanded
258−// HandleMouseClick implements MouseClickable.
262+// HandleMouseClick implements MouseClickable. It signals (via a true return)
263+// that the click lies on the thinking box so the caller can invoke
264+// [AssistantMessageItem.ToggleExpanded] through the generic [Expandable]
265+// path. Toggling here directly would double-toggle because the caller always
266+// runs the generic path after a handled click.
259func (a *AssistantMessageItem) HandleMouseClick(btn ansi.MouseButton, x, y int) bool {
267func (a *AssistantMessageItem) HandleMouseClick(btn ansi.MouseButton, x, y int) bool {
260 if btn != ansi.MouseLeft {
268 if btn != ansi.MouseLeft {
261 return false
269 return false
263− // check if the click is within the thinking box
271+ // Only the thinking box is clickable; other regions of the assistant
272+ // message should not trigger expansion.
264− if a.thinkingBoxHeight > 0 && y < a.thinkingBoxHeight {
273+ return a.thinkingBoxHeight > 0 && y < a.thinkingBoxHeight
271// HandleKeyEvent implements KeyEventHandler.
276// HandleKeyEvent implements KeyEventHandler.