debug: add @mention console logs

main
sp mac bookpro 2605 2026-06-07 20:31:46 +08:00
parent 92799189e2
commit d649d4364d
1 changed files with 13 additions and 0 deletions

View File

@ -60,14 +60,25 @@ export default function ChatInput(props: {
const textBeforeCursor = value.slice(0, cursorPos); const textBeforeCursor = value.slice(0, cursorPos);
const atIndex = textBeforeCursor.lastIndexOf('@'); const atIndex = textBeforeCursor.lastIndexOf('@');
console.log('[@mention] input change:', {
value,
cursorPos,
textBeforeCursor,
atIndex,
agentListLength: agentList.length,
agentList: agentList.map(a => ({ id: a.id, name: a.name }))
});
if (atIndex !== -1 && (atIndex === 0 || /\s$/.test(textBeforeCursor.slice(0, atIndex)))) { if (atIndex !== -1 && (atIndex === 0 || /\s$/.test(textBeforeCursor.slice(0, atIndex)))) {
const query = textBeforeCursor.slice(atIndex + 1); const query = textBeforeCursor.slice(atIndex + 1);
console.log('[@mention] matched @ at position:', { atIndex, query });
if (!query.includes(' ')) { if (!query.includes(' ')) {
setMentionQuery(query); setMentionQuery(query);
// 计算位置 // 计算位置
const textarea = e.target; const textarea = e.target;
const rect = textarea.getBoundingClientRect(); const rect = textarea.getBoundingClientRect();
setMentionPos({ top: rect.bottom, left: rect.left + 10 }); setMentionPos({ top: rect.bottom, left: rect.left + 10 });
console.log('[@mention] show popover:', { top: rect.bottom, left: rect.left + 10, query });
setShowMentionPopover(true); setShowMentionPopover(true);
return; return;
} }
@ -78,6 +89,8 @@ export default function ChatInput(props: {
const filteredAgents = agentList.filter(a => const filteredAgents = agentList.filter(a =>
a.name.toLowerCase().includes(mentionQuery.toLowerCase()) a.name.toLowerCase().includes(mentionQuery.toLowerCase())
); );
console.log('[@mention] filtered:', { mentionQuery, count: filteredAgents.length, agents: filteredAgents.map(a => a.name) });
const handleSelectAgent = (agent: Agent) => { const handleSelectAgent = (agent: Agent) => {
const textarea = inputRef.current; const textarea = inputRef.current;