fix: 发送消息后清空上下文文件列表

修复了发送消息后上下文文件仍然显示在输入框中的问题。

   - 在 sendMessage() 函数中添加 clearContextItems() 调用
   - 调整脚本加载顺序,确保 contextDisplay 在 contextButton 之前初始化
This commit is contained in:
Roe-xin
2026-02-26 19:05:49 +08:00
parent c9e9df3825
commit c3e3012a94
3 changed files with 25 additions and 9 deletions

View File

@ -46,7 +46,8 @@ export async function handleUserMessage(
text: string,
extensionPath?: string,
mode?: RunMode,
serviceTier?: ServiceTier // 新增:服务等级参数
serviceTier?: ServiceTier, // 服务等级参数
contextItems?: Array<{ id: number; type: string; path: string }> // 上下文项参数
) {
console.log("收到用户消息:", text);
@ -199,7 +200,8 @@ export async function handleUserMessage(
extensionPath,
mode,
undefined,
serviceTier
serviceTier,
contextItems
);
return;
} catch (error) {
@ -236,10 +238,19 @@ async function handleUserMessageWithBackend(
extensionPath: string,
mode?: RunMode,
reuseTaskId?: string, // 可选,复用现有 taskId用于 Plan 模式确认后继续执行)
serviceTier?: ServiceTier // 新增:服务等级参数
serviceTier?: ServiceTier, // 服务等级参数
contextItems?: Array<{ id: number; type: string; path: string }> // 上下文项参数
): Promise<void> {
const historyManager = ChatHistoryManager.getInstance();
// 处理上下文项:在消息前附加文件/文件夹路径
let enhancedText = text;
if (contextItems && contextItems.length > 0) {
console.log("[MessageHandler] 处理上下文项:", contextItems.length);
const paths = contextItems.map(item => item.path).join('\n');
enhancedText = `${paths}\n\n${text}`;
}
// 获取 historyManager 中的 taskId由 ICHelperPanel 创建)
// 优先使用 reuseTaskId其次使用 historyManager 的 taskId
const taskIdToUse = reuseTaskId || historyManager.getCurrentTaskId();
@ -267,7 +278,7 @@ async function handleUserMessageWithBackend(
return new Promise((resolve, reject) => {
currentSession!.sendMessage(
text,
enhancedText,
{
onText: (fullText, isStreaming) => {
// 不再单独处理文本,统一通过 onSegmentUpdate 处理