diff --git a/packages/tui/src/component/prompt/autocomplete.tsx b/packages/tui/src/component/prompt/autocomplete.tsx index 561555165c1..444297a6e2e 100644 --- a/packages/tui/src/component/prompt/autocomplete.tsx +++ b/packages/tui/src/component/prompt/autocomplete.tsx @@ -1,16 +1,32 @@ -import { measureEditText, type BoxRenderable, type TextareaRenderable, type ScrollBoxRenderable } from "@opentui/core" +import { + measureEditText, + type RGBA, + type BoxRenderable, + type TextareaRenderable, + type ScrollBoxRenderable, +} from "@opentui/core" import { pathToFileURL } from "node:url" import fuzzysort from "fuzzysort" import path from "path" import { firstBy } from "remeda" -import { createMemo, createResource, createEffect, onMount, onCleanup, Index, Show, createSignal } from "solid-js" +import { + createMemo, + createResource, + createEffect, + onMount, + onCleanup, + Index, + Show, + createSignal, + type JSX, +} from "solid-js" import { createStore } from "solid-js/store" import { useEditorContext } from "../../context/editor" import { useClient } from "../../context/client" import { useData } from "../../context/data" import { getScrollAcceleration } from "../../util/scroll" import { useTuiPaths } from "../../context/runtime" -import { useConfig } from "../../config" +import { useConfig, useNewDesigns } from "../../config" import { useLocation } from "../../context/location" import { useTheme } from "../../context/theme" import { SplitBorder } from "../../ui/border" @@ -82,6 +98,7 @@ export function Autocomplete(props: { const dimensions = useTerminalDimensions() const frecency = useFrecency() const config = useConfig().data + const newDesigns = useNewDesigns() const paths = useTuiPaths() const location = useLocation() const [store, setStore] = createStore({ @@ -849,6 +866,8 @@ export function Autocomplete(props: { return "No matching files, agents, or references" }) const emptyError = createMemo(() => store.visible === "reference" && !files.loading && visibleFiles().failed) + // The scrollbox paints this under the classic design; new designs paint it per row. + const rowBackground = () => (newDesigns() ? theme.background.raised.high : undefined) const labels = { skill: "skill", agent: "agent", @@ -864,6 +883,8 @@ export function Autocomplete(props: { width={position().width} zIndex={100} {...SplitBorder} + // Under new designs each row draws its own left rail so the selected row can show the selection bar. + border={newDesigns() ? ["right"] : SplitBorder.border} borderColor={theme.border.base} > - {emptyMessage()} - + + + {/* Under new designs the 1-row popup keeps the message on one line, so it never scrolls past the rail. */} + + {newDesigns() ? Locale.truncate(emptyMessage(), Math.max(1, position().width - 4)) : emptyMessage()} + + + } > {(option, index) => { @@ -900,57 +935,69 @@ export function Autocomplete(props: { return action !== undefined && action.id === confirming() } return ( - moveTo(index)} - onMouseDown={() => moveTo(index)} - onMouseUp={() => select()} > - moveTo(index)} + onMouseDown={() => moveTo(index)} + onMouseUp={() => select()} > - {Locale.truncateMiddle( - confirmingAction() ? (destructive()?.confirm ?? "") : option().display, - contentWidth(), - )} - - - - {" " + option().description?.replace(/\s+/g, " ").trim()} - - - - - {label()} + {Locale.truncateMiddle( + confirmingAction() ? (destructive()?.confirm ?? "") : option().display, + contentWidth(), + )} - - + + + {" " + option().description?.replace(/\s+/g, " ").trim()} + + + + + + {label()} + + + + ) }} @@ -958,3 +1005,19 @@ export function Autocomplete(props: { ) } + +// Under new designs the popup's left border is drawn per row, so the selected row's segment +// becomes the selection bar, matching dialog rows. `color` overrides the border color. +function AutocompleteRail(props: { enabled: boolean; color?: RGBA; children: JSX.Element }) { + const theme = useTheme() + return ( + + + + ┃ + + {props.children} + + + ) +}