支持把目录附加到会话(临时处理)
This commit is contained in:
@@ -46,7 +46,9 @@ import type {
|
|||||||
} from "@/lib/types"
|
} from "@/lib/types"
|
||||||
import {
|
import {
|
||||||
ATTACH_FILE_TO_SESSION_EVENT,
|
ATTACH_FILE_TO_SESSION_EVENT,
|
||||||
|
APPEND_TEXT_TO_SESSION_EVENT,
|
||||||
type AttachFileToSessionDetail,
|
type AttachFileToSessionDetail,
|
||||||
|
type AppendTextToSessionDetail,
|
||||||
} from "@/lib/session-attachment-events"
|
} from "@/lib/session-attachment-events"
|
||||||
import { ModeSelector } from "@/components/chat/mode-selector"
|
import { ModeSelector } from "@/components/chat/mode-selector"
|
||||||
import { SessionConfigSelector } from "@/components/chat/session-config-selector"
|
import { SessionConfigSelector } from "@/components/chat/session-config-selector"
|
||||||
@@ -778,6 +780,29 @@ export function MessageInput({
|
|||||||
}
|
}
|
||||||
}, [appendResourceAttachments, attachmentTabId])
|
}, [appendResourceAttachments, attachmentTabId])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!attachmentTabId) return
|
||||||
|
|
||||||
|
const handleAppendText = (event: Event) => {
|
||||||
|
const customEvent = event as CustomEvent<AppendTextToSessionDetail>
|
||||||
|
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(() => {
|
useEffect(() => {
|
||||||
let cancelled = false
|
let cancelled = false
|
||||||
const unlisteners: Array<() => void | Promise<void>> = []
|
const unlisteners: Array<() => void | Promise<void>> = []
|
||||||
|
|||||||
@@ -38,7 +38,10 @@ import {
|
|||||||
stopFileTreeWatch,
|
stopFileTreeWatch,
|
||||||
} from "@/lib/tauri"
|
} from "@/lib/tauri"
|
||||||
import { disposeTauriListener } from "@/lib/tauri-listener"
|
import { disposeTauriListener } from "@/lib/tauri-listener"
|
||||||
import { emitAttachFileToSession } from "@/lib/session-attachment-events"
|
import {
|
||||||
|
emitAttachFileToSession,
|
||||||
|
emitAppendTextToSession,
|
||||||
|
} from "@/lib/session-attachment-events"
|
||||||
import type {
|
import type {
|
||||||
FileTreeChangedEvent,
|
FileTreeChangedEvent,
|
||||||
FileTreeNode,
|
FileTreeNode,
|
||||||
@@ -612,6 +615,17 @@ function RenderNode({
|
|||||||
const isGitMenuDisabled = !gitEnabled || isGitignoreIgnored
|
const isGitMenuDisabled = !gitEnabled || isGitignoreIgnored
|
||||||
const shouldRenderChildren = expandedPaths.has(node.path)
|
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 () => {
|
const handleOpenDirInSystemExplorer = async () => {
|
||||||
try {
|
try {
|
||||||
await revealItemInDir(absolutePath)
|
await revealItemInDir(absolutePath)
|
||||||
@@ -669,6 +683,12 @@ function RenderNode({
|
|||||||
</FileTreeFolder>
|
</FileTreeFolder>
|
||||||
</ContextMenuTrigger>
|
</ContextMenuTrigger>
|
||||||
<ContextMenuContent>
|
<ContextMenuContent>
|
||||||
|
<ContextMenuItem
|
||||||
|
onSelect={handleAttachDirToSession}
|
||||||
|
disabled={!activeSessionTabId}
|
||||||
|
>
|
||||||
|
{t("attachToCurrentSession")}
|
||||||
|
</ContextMenuItem>
|
||||||
<ContextMenuSub>
|
<ContextMenuSub>
|
||||||
<ContextMenuSubTrigger>{t("new")}</ContextMenuSubTrigger>
|
<ContextMenuSubTrigger>{t("new")}</ContextMenuSubTrigger>
|
||||||
<ContextMenuSubContent>
|
<ContextMenuSubContent>
|
||||||
|
|||||||
@@ -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<AppendTextToSessionDetail>(APPEND_TEXT_TO_SESSION_EVENT, {
|
||||||
|
detail,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user