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 处理

View File

@ -296,8 +296,8 @@ export function getInputAreaScript(): string {
return `
// 注意getModeSelectorScript() 已在 webviewContent.ts 开头加载,这里不再重复加载
${getModelSelectorScript()}
${getContextButtonScript()}
${getContextDisplayScript()}
${getContextButtonScript()}
${getContextCompressScript()}
${getOptimizeButtonScript()}
@ -438,6 +438,11 @@ export function getInputAreaScript(): string {
autoResizeTextarea(); // 重置输入框高度
messageInput.focus();
// 清空上下文项
if (window.clearContextItems) {
window.clearContextItems();
}
// 重置优化状态
resetOptimizeButton();
}

View File

@ -26,16 +26,16 @@ export function getUserInfoComponentContent(): string {
</div>
</div>
<!-- 升级到Pro按钮 (仅BASIC会员显示) -->
<div class="upgrade-pro-wrapper" id="upgradeProWrapper" style="display: none;">
<!-- <div class="upgrade-pro-wrapper" id="upgradeProWrapper" style="display: none;">
<button class="upgrade-pro-btn" id="upgradeProBtn">升级到 Pro</button>
</div>
</div> -->
</div>
<div class="user-detail-body">
<div class="user-detail-item">
<!-- <div class="user-detail-item">
<span class="detail-label">剩余 Credits</span>
<span class="detail-value" id="creditsDetail">-</span>
</div>
</div> -->
<div class="user-detail-item logout-item" id="logoutItem">
<span class="detail-label">账户管理</span>
<span class="detail-value logout-link">退出登录</span>