From 3f89896e8a7675657a7552d0c21489ec26301eca Mon Sep 17 00:00:00 2001 From: Dax Raad Date: Sat, 20 Sep 2025 19:06:19 -0400 Subject: [PATCH] refactor: centralize resize logic for message parts in OpenTUI session --- .../opencode/src/cli/cmd/opentui/session.tsx | 49 ++++++++++--------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/packages/opencode/src/cli/cmd/opentui/session.tsx b/packages/opencode/src/cli/cmd/opentui/session.tsx index 9678e6871..4fc76abd2 100644 --- a/packages/opencode/src/cli/cmd/opentui/session.tsx +++ b/packages/opencode/src/cli/cmd/opentui/session.tsx @@ -26,7 +26,6 @@ import type { PatchTool } from "../../../tool/patch" import type { WebFetchTool } from "../../../tool/webfetch" import type { TaskTool } from "../../../tool/task" import { useKeyboard, type BoxProps, type JSX } from "@opentui/solid" -import { createStore } from "solid-js/store" export function Session() { const route = useRouteData("session") @@ -132,28 +131,9 @@ function AssistantMessage(props: { message: AssistantMessage; parts: Part[] }) { {(part) => { const component = createMemo(() => PART_MAPPING[part.type as keyof typeof PART_MAPPING]) - function resize(el: BoxRenderable) { - const parent = el.parent - if (!parent) return - const children = parent.getChildren() - const index = children.indexOf(el) - const previous = children[index - 1] - if (!previous) return - console.log(previous.height, el.height) - if (el.height > 1 || previous.height > 1) { - el.marginTop = 1 - } - } return ( - resize(el!)} - > - - + ) }} @@ -165,6 +145,17 @@ const PART_MAPPING = { text: TextPart, tool: ToolPart, } +function resize(el: BoxRenderable) { + const parent = el.parent + if (!parent) return + const children = parent.getChildren() + const index = children.indexOf(el) + const previous = children[index - 1] + if (!previous) return + if (el.height > 1 || previous.height > 1) { + el.marginTop = 1 + } +} function TextPart(props: { part: TextPart; message: AssistantMessage }) { const sync = useSync() @@ -172,7 +163,13 @@ function TextPart(props: { part: TextPart; message: AssistantMessage }) { const local = useLocal() return ( - + resize(el!)} + > {props.part.text.trim()} {Locale.titlecase(agent().name)}{" "} @@ -209,7 +206,13 @@ function ToolPart(props: { part: ToolPart; message: AssistantMessage }) { } return ( - + resize(el!)} + >