fix: 修复AI询问时选项点击后选中状态丢失的问题
- 添加 answeredQuestions Map 存储已回答问题的状态 - 在重新渲染时恢复选中状态和 answered 类 - 已回答的问题自动隐藏输入框并禁用点击事件 - 确保用户选择在页面更新时保持显示
This commit is contained in:
@ -116,23 +116,19 @@ async function handleUserMessageWithBackend(
|
||||
return new Promise((resolve, reject) => {
|
||||
currentSession!.sendMessage(text, {
|
||||
onText: (fullText, isStreaming) => {
|
||||
if (isStreaming) {
|
||||
// 流式更新消息
|
||||
panel.webview.postMessage({
|
||||
command: "updateStreamingMessage",
|
||||
text: fullText,
|
||||
});
|
||||
}
|
||||
// 注意:完成时通过 onComplete 发送分段消息
|
||||
// 不再单独处理文本,统一通过 onSegmentUpdate 处理
|
||||
},
|
||||
|
||||
onSegmentUpdate: (segments) => {
|
||||
// 实时发送段落更新,按后端返回顺序展示
|
||||
panel.webview.postMessage({
|
||||
command: "updateSegments",
|
||||
segments: segments,
|
||||
});
|
||||
},
|
||||
|
||||
onToolStart: (toolName) => {
|
||||
// 实时显示工具状态
|
||||
panel.webview.postMessage({
|
||||
command: "toolStart",
|
||||
toolName,
|
||||
});
|
||||
// 同时更新状态栏
|
||||
// 更新状态栏
|
||||
panel.webview.postMessage({
|
||||
command: "updateStatus",
|
||||
text: `正在执行 ${toolName}...`,
|
||||
@ -141,25 +137,15 @@ async function handleUserMessageWithBackend(
|
||||
},
|
||||
|
||||
onToolComplete: (toolName, result) => {
|
||||
// 实时更新工具状态
|
||||
panel.webview.postMessage({
|
||||
command: "toolComplete",
|
||||
toolName,
|
||||
result,
|
||||
});
|
||||
// 工具完成,不需要单独处理,通过 onSegmentUpdate 统一更新
|
||||
},
|
||||
|
||||
onToolError: (toolName, error) => {
|
||||
// 实时显示工具错误
|
||||
panel.webview.postMessage({
|
||||
command: "toolError",
|
||||
toolName,
|
||||
error,
|
||||
});
|
||||
// 工具错误,不需要单独处理,通过 onSegmentUpdate 统一更新
|
||||
},
|
||||
|
||||
onQuestion: (askId, question, options) => {
|
||||
// 问题会在分段消息中显示,这里只更新状态栏
|
||||
// 只更新状态栏,问题显示由 onSegmentUpdate 统一处理
|
||||
panel.webview.postMessage({
|
||||
command: "updateStatus",
|
||||
text: "等待用户回答...",
|
||||
@ -173,13 +159,14 @@ async function handleUserMessageWithBackend(
|
||||
command: "hideStatus",
|
||||
});
|
||||
|
||||
// 发送分段消息
|
||||
console.log('[MessageHandler] 发送分段消息, 段落数:', segments.length);
|
||||
// 最后一次发送完整的段落
|
||||
console.log('[MessageHandler] 对话完成, 段落数:', segments.length);
|
||||
console.log('[MessageHandler] segments 内容:', JSON.stringify(segments));
|
||||
|
||||
const result = await panel.webview.postMessage({
|
||||
command: "receiveSegments",
|
||||
command: "updateSegments",
|
||||
segments: segments,
|
||||
isComplete: true,
|
||||
});
|
||||
console.log('[MessageHandler] postMessage 返回值:', result);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user