fix(room): Enter on category navigates into it, not out of popover

When a category (Repository/User/AI) is selected and Enter is pressed,
append ':' to the textarea value to trigger the next-level item list.
E.g. '@ai' + Enter → '@ai:' → shows AI model items.
This commit is contained in:
ZhenYi 2026-04-18 00:42:08 +08:00
parent 245384ef50
commit 14de80b24b

View File

@ -629,7 +629,28 @@ export function MentionPopover({
selectedIndexRef.current = prev;
} else if (e.key === 'Enter' || e.key === 'Tab') {
const item = vis[selectedIndexRef.current];
if (item && item.type === 'item') {
if (!item) return;
if (item.type === 'category') {
// Enter a category: append ':' to textarea to trigger next-level list
e.preventDefault();
const category = item.category;
const textarea = textareaRef.current;
if (!textarea) return;
const curPos = textarea.selectionStart;
const val = textarea.value;
// Replace @xxx with @xxx: to enter the category
const textBefore = val.substring(0, ms.startPos);
const afterPartial = val.substring(ms.startPos + ms.category.length + 1); // skip '@' + category
const newVal = textBefore + '@' + category + ':' + afterPartial;
const newPos = ms.startPos + 1 + category.length + 1; // after '@ai:'
textarea.value = newVal;
textarea.setSelectionRange(newPos, newPos);
textarea.focus();
// Dispatch input event so React picks up the change
textarea.dispatchEvent(new Event('input', { bubbles: true }));
} else if (item.type === 'item') {
// Insert the mention
e.preventDefault();
handleSelectRef.current(item);
}