From be08b59aa0058e1997e25de6fdaedd5be2b6fbdf Mon Sep 17 00:00:00 2001 From: xintaofei Date: Mon, 23 Mar 2026 18:15:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=8A=8A=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E9=99=84=E5=8A=A0=E5=88=B0=E4=BC=9A=E8=AF=9D=EF=BC=88=E4=B8=B4?= =?UTF-8?q?=E6=97=B6=E5=A4=84=E7=90=86=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/chat/message-input.tsx | 25 +++++++++++++++++++ .../layout/aux-panel-file-tree-tab.tsx | 22 +++++++++++++++- src/lib/session-attachment-events.ts | 18 +++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/src/components/chat/message-input.tsx b/src/components/chat/message-input.tsx index 2aa83cc..80637e9 100644 --- a/src/components/chat/message-input.tsx +++ b/src/components/chat/message-input.tsx @@ -46,7 +46,9 @@ import type { } from "@/lib/types" import { ATTACH_FILE_TO_SESSION_EVENT, + APPEND_TEXT_TO_SESSION_EVENT, type AttachFileToSessionDetail, + type AppendTextToSessionDetail, } from "@/lib/session-attachment-events" import { ModeSelector } from "@/components/chat/mode-selector" import { SessionConfigSelector } from "@/components/chat/session-config-selector" @@ -778,6 +780,29 @@ export function MessageInput({ } }, [appendResourceAttachments, attachmentTabId]) + useEffect(() => { + if (!attachmentTabId) return + + const handleAppendText = (event: Event) => { + const customEvent = event as CustomEvent + if (!customEvent.detail) return + if (customEvent.detail.tabId !== attachmentTabId) return + const appendText = customEvent.detail.text + setText((prev) => { + if (prev.length === 0) return appendText + return prev.endsWith(" ") ? prev + appendText : prev + " " + appendText + }) + requestAnimationFrame(() => { + textareaRef.current?.focus() + }) + } + + window.addEventListener(APPEND_TEXT_TO_SESSION_EVENT, handleAppendText) + return () => { + window.removeEventListener(APPEND_TEXT_TO_SESSION_EVENT, handleAppendText) + } + }, [attachmentTabId]) + useEffect(() => { let cancelled = false const unlisteners: Array<() => void | Promise> = [] diff --git a/src/components/layout/aux-panel-file-tree-tab.tsx b/src/components/layout/aux-panel-file-tree-tab.tsx index 6875666..7ced47f 100644 --- a/src/components/layout/aux-panel-file-tree-tab.tsx +++ b/src/components/layout/aux-panel-file-tree-tab.tsx @@ -38,7 +38,10 @@ import { stopFileTreeWatch, } from "@/lib/tauri" import { disposeTauriListener } from "@/lib/tauri-listener" -import { emitAttachFileToSession } from "@/lib/session-attachment-events" +import { + emitAttachFileToSession, + emitAppendTextToSession, +} from "@/lib/session-attachment-events" import type { FileTreeChangedEvent, FileTreeNode, @@ -612,6 +615,17 @@ function RenderNode({ const isGitMenuDisabled = !gitEnabled || isGitignoreIgnored const shouldRenderChildren = expandedPaths.has(node.path) + const handleAttachDirToSession = () => { + if (!activeSessionTabId) return + const relativePath = node.path.endsWith("/") + ? `@${node.path} ` + : `@${node.path}/ ` + emitAppendTextToSession({ + tabId: activeSessionTabId, + text: relativePath, + }) + } + const handleOpenDirInSystemExplorer = async () => { try { await revealItemInDir(absolutePath) @@ -669,6 +683,12 @@ function RenderNode({ + + {t("attachToCurrentSession")} + {t("new")} diff --git a/src/lib/session-attachment-events.ts b/src/lib/session-attachment-events.ts index ad1c7ae..d16cd58 100644 --- a/src/lib/session-attachment-events.ts +++ b/src/lib/session-attachment-events.ts @@ -15,3 +15,21 @@ export function emitAttachFileToSession( }) ) } + +export const APPEND_TEXT_TO_SESSION_EVENT = "codeg:append-text-to-session" + +export interface AppendTextToSessionDetail { + tabId: string + text: string +} + +export function emitAppendTextToSession( + detail: AppendTextToSessionDetail +): void { + if (typeof window === "undefined") return + window.dispatchEvent( + new CustomEvent(APPEND_TEXT_TO_SESSION_EVENT, { + detail, + }) + ) +}