From 92382208674ae1b9a2dd62ac0fa98d67ce348bfe Mon Sep 17 00:00:00 2001 From: lyingbug Date: Tue, 13 Oct 2026 21:35:43 +0800 Subject: [PATCH] feat(chat): add global search to the @ mention menu and align its styling (#4249) --- frontend/src/components/Input-field.vue | 54 +- .../src/components/MentionSelector.test.ts | 21 + frontend/src/components/MentionSelector.vue | 1204 +++++++++-------- frontend/src/i18n/locales/en-US.ts | 8 +- frontend/src/i18n/locales/ja-JP.ts | 8 +- frontend/src/i18n/locales/ko-KR.ts | 8 +- frontend/src/i18n/locales/ru-RU.ts | 8 +- frontend/src/i18n/locales/zh-CN.ts | 8 +- frontend/src/i18n/locales/zh-TW.ts | 8 +- 9 files changed, 731 insertions(+), 596 deletions(-) diff --git a/frontend/src/components/Input-field.vue b/frontend/src/components/Input-field.vue index 0c35b822..2e3b2f5b 100644 --- a/frontend/src/components/Input-field.vue +++ b/frontend/src/components/Input-field.vue @@ -1272,9 +1272,14 @@ const updateModelDropdownPosition = () => { // Mention Logic let lastMentionQuery = ''; +// 关键词变化时旧请求可能晚于新请求返回;只采纳最新一次加载的结果 +let mentionLoadSeq = 0; const loadMentionItems = async (q: string, resetIndex = true, append = false) => { console.log('[Mention] loadMentionItems called with query:', q, 'append:', append); + const seq = append ? mentionLoadSeq : ++mentionLoadSeq; + const isStale = () => seq !== mentionLoadSeq; + const nextGroupCounts: Partial> = append ? mentionGroupCounts.value : {}; if (!append) { mentionOffset.value = 0; } @@ -1392,7 +1397,7 @@ const loadMentionItems = async (q: string, resetIndex = true, append = false) => orgName: kb.org_name || sharedAgentOrgName.value || undefined }; })); - mentionGroupCounts.value.kb = kbItems.length; + nextGroupCounts.kb = kbItems.length; const tagKeyword = q.trim(); const tagSources = availableKbs; @@ -1410,7 +1415,7 @@ const loadMentionItems = async (q: string, resetIndex = true, append = false) => })); })); tagItems = tagResults.flat(); - mentionGroupCounts.value.tag = tagItems.length; + nextGroupCounts.tag = tagItems.length; } catch (e) { console.error('[Mention] listKnowledgeTags error:', e); tagItems = []; @@ -1488,6 +1493,7 @@ const loadMentionItems = async (q: string, resetIndex = true, append = false) => fileTypesParam, searchOptions ); + if (isStale()) return; console.log('[Mention] searchKnowledge response:', res); if (res.data && Array.isArray(res.data)) { let files = res.data; @@ -1528,24 +1534,28 @@ const loadMentionItems = async (q: string, resetIndex = true, append = false) => if (!append) { const clientFiltered = !!mentionAllowedKbIds.value && fileItems.length < apiPageSize; if (!clientFiltered && rawTotal != null) { - mentionGroupCounts.value.file = rawTotal; + nextGroupCounts.file = rawTotal; } else { - delete mentionGroupCounts.value.file; + delete nextGroupCounts.file; } } } mentionHasMore.value = res.has_more || false; mentionOffset.value += fileItems.length; } catch (e) { + if (isStale()) return; console.error('[Mention] searchKnowledge error:', e); mentionHasMore.value = false; } finally { - mentionLoading.value = false; + if (!isStale()) mentionLoading.value = false; } } else { + if (isStale()) return; mentionHasMore.value = false; } + if (isStale()) return; + if (!append) mentionGroupCounts.value = nextGroupCounts; if (append) { // Append file items to existing list mentionItems.value = [...mentionItems.value, ...fileItems]; @@ -1571,6 +1581,21 @@ const loadMoreMentionItems = () => { } }; +let mentionSearchTimer: ReturnType | null = null; +const onMentionSearchInput = (q: string) => { + mentionQuery.value = q; + if (mentionSearchTimer) clearTimeout(mentionSearchTimer); + mentionSearchTimer = setTimeout(() => { + mentionSearchTimer = null; + loadMentionItems(q, true); + }, 180); +}; + +const closeMentionFromPopup = () => { + showMention.value = false; + void focusInput(); +}; + const getTextareaEl = () => { if (!textareaRef.value) return null; // If it's a native element @@ -1631,10 +1656,8 @@ const onInput = (val: string | InputEvent) => { showMention.value = false; return; } - // Only reload if query changed if (q !== mentionQuery.value) { - mentionQuery.value = q; - loadMentionItems(q, true); // Reset index when query changes + onMentionSearchInput(q); } } else { if (textBeforeCursor.endsWith('@')) { @@ -1655,7 +1678,7 @@ const onInput = (val: string | InputEvent) => { const rect = rectToCssPx(textarea.getBoundingClientRect(), zoom); const { width: vw, height: vh } = cssViewportSize(zoom); const scrollTop = textarea.scrollTop; - const menuHeight = 320; // 预估最大高度 + const menuHeight = 380; // 预估最大高度 let left = rect.left + coords.left; // Prevent menu from going off-screen horizontally @@ -1688,6 +1711,7 @@ const onInput = (val: string | InputEvent) => { }; } + if (mentionSearchTimer) clearTimeout(mentionSearchTimer); loadMentionItems(""); } } @@ -1734,7 +1758,7 @@ const triggerMention = () => { const zoom = getRootZoom(); const rect = rectToCssPx(textarea.getBoundingClientRect(), zoom); const { height: vh } = cssViewportSize(zoom); - const menuHeight = 320; + const menuHeight = 380; // 判断输入框上方空间 const spaceAbove = rect.top; @@ -1757,6 +1781,7 @@ const triggerMention = () => { }; } + if (mentionSearchTimer) clearTimeout(mentionSearchTimer); loadMentionItems(""); }; @@ -1967,6 +1992,7 @@ onUnmounted(() => { document.removeEventListener('click', closeAgentModeSelector); document.removeEventListener('click', closeModelSelector); document.removeEventListener('click', closeMentionSelector); + if (mentionSearchTimer) clearTimeout(mentionSearchTimer); if (resizeHandler) { window.removeEventListener('resize', resizeHandler); } @@ -2402,6 +2428,10 @@ const onKeydown = (val: string, event: { e: KeyboardEvent }) => { mentionSelectorRef.value?.confirmActive(); return; } + if (event.e.keyCode === 9 && !event.e.shiftKey) { // Tab + if (mentionSelectorRef.value?.enterActiveGroup()) event.e.preventDefault(); + return; + } if (event.e.keyCode === 27) { // Esc if (mentionSelectorRef.value?.leaveGroup()) { return; @@ -3010,7 +3040,9 @@ defineExpose({ diff --git a/frontend/src/components/MentionSelector.test.ts b/frontend/src/components/MentionSelector.test.ts index 8a0b49d5..a3b1dc9f 100644 --- a/frontend/src/components/MentionSelector.test.ts +++ b/frontend/src/components/MentionSelector.test.ts @@ -15,3 +15,24 @@ test('MCP mention hover shows catalog summary instead of a bare name', () => { assert.doesNotMatch(source, /detail-type-badge doc">MCP/) assert.doesNotMatch(source, /t-dialog/) }) + +test('mention menu exposes a search box that is editable only when opened from the button', () => { + assert.match(source, /class="mention-search__input"/) + assert.match(source, /:readonly="!searchable"/) + assert.match(source, /emit\('update:query'/) + assert.match(source, /emit\('close'\)/) +}) + +test('global search caps each group and lets the user drill into the full group', () => { + assert.match(source, /const FLAT_GROUP_LIMIT = 5/) + assert.match(source, /mentionDetail\.viewAll/) + assert.match(source, /enterActiveGroup/) + // 分组内输入关键词时保持在分组内过滤,而不是跳回全局结果 + assert.match(source, /isFlatMode = computed\(\(\) => !currentGroupType\.value && trimmedQuery\.value\.length > 0\)/) +}) + +test('mention menu follows the shared popover look of the other input selectors', () => { + assert.match(source, /border-radius: var\(--app-radius-lg\)/) + assert.match(source, /box-shadow: var\(--td-shadow-2\)/) + assert.doesNotMatch(source, /label: '标签'/) +}) diff --git a/frontend/src/components/MentionSelector.vue b/frontend/src/components/MentionSelector.vue index 3ead6a8b..3b27fdaf 100644 --- a/frontend/src/components/MentionSelector.vue +++ b/frontend/src/components/MentionSelector.vue @@ -1,276 +1,256 @@