Просмотр исходного кода

tui: truncate sidebar file paths (#30531)

Simon Klee 3 месяцев назад
Родитель
Сommit
06eecc5a6d

+ 8 - 1
packages/opencode/src/cli/cmd/tui/feature-plugins/sidebar/files.tsx

@@ -1,9 +1,16 @@
 import type { TuiPlugin, TuiPluginApi } from "@opencode-ai/plugin/tui"
 import type { InternalTuiPlugin } from "../../plugin/internal"
 import { createMemo, For, Show, createSignal } from "solid-js"
+import { Locale } from "@/util/locale"
 
 const id = "internal:sidebar-files"
 
+function changeCountWidth(item: { additions: number; deletions: number }) {
+  return [item.additions ? `+${item.additions}` : "", item.deletions ? `-${item.deletions}` : ""]
+    .filter(Boolean)
+    .join(" ").length
+}
+
 function View(props: { api: TuiPluginApi; session_id: string }) {
   const [open, setOpen] = createSignal(true)
   const theme = () => props.api.theme.current
@@ -25,7 +32,7 @@ function View(props: { api: TuiPluginApi; session_id: string }) {
             {(item) => (
               <box flexDirection="row" gap={1} justifyContent="space-between">
                 <text fg={theme().textMuted} wrapMode="none">
-                  {item.file}
+                  {Locale.truncateLeft(item.file, Math.max(2, 36 - changeCountWidth(item)))}
                 </text>
                 <box flexDirection="row" gap={1} flexShrink={0}>
                   <Show when={item.additions}>