Skip to content
Open
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
14 changes: 14 additions & 0 deletions packages/tui/src/routes/session/sidebar.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,10 +5,21 @@ import { useTheme } from "../../context/theme"
import { useTuiConfig } from "../../config"
import { InstallationChannel, InstallationVersion } from "@opencode-ai/core/installation/version"
import { usePluginRuntime } from "../../plugin/runtime"
import type { Renderable } from "@opentui/core"

import { getScrollAcceleration } from "../../util/scroll"
import { WorkspaceLabel } from "../../component/workspace-label"

export function disableSelectionSubtree(root: Renderable) {
root.selectable = false
const stack = [...root.getChildren()]
while (stack.length > 0) {
const node = stack.pop()!
node.selectable = false
stack.push(...node.getChildren())
}
}

export function Sidebar(props: { sessionID: string; overlay?: boolean }) {
const pluginRuntime = usePluginRuntime()
const project = useProject()
Expand All@@ -26,6 +37,9 @@ export function Sidebar(props: { sessionID: string; overlay?: boolean }) {
return (
<Show when={session()}>
<box
renderBefore={function () {
disableSelectionSubtree(this)
}}
backgroundColor={theme.backgroundPanel}
width={42}
height="100%"
Expand Down
37 changes: 37 additions & 0 deletions packages/tui/test/util/sidebar-selection.test.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
import { expect, test } from "bun:test"
import type { Renderable } from "@opentui/core"
import { disableSelectionSubtree } from "../../src/routes/session/sidebar"

type MockRenderable = {
selectable: boolean
children: MockRenderable[]
getChildren: () => MockRenderable[]
}

function mockRenderable(children: MockRenderable[] = []): MockRenderable {
return {
selectable: true,
children,
getChildren() {
return this.children
},
}
}

function asRenderable(node: MockRenderable) {
return node as unknown as Renderable
}

test("disableSelectionSubtree disables selection for all descendants", () => {
const leaf = mockRenderable()
const nested = mockRenderable([leaf])
const sibling = mockRenderable()
const root = mockRenderable([nested, sibling])

disableSelectionSubtree(asRenderable(root))

expect(root.selectable).toBe(false)
expect(nested.selectable).toBe(false)
expect(leaf.selectable).toBe(false)
expect(sibling.selectable).toBe(false)
})
Loading