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:
parent
245384ef50
commit
14de80b24b
@ -629,7 +629,28 @@ export function MentionPopover({
|
|||||||
selectedIndexRef.current = prev;
|
selectedIndexRef.current = prev;
|
||||||
} else if (e.key === 'Enter' || e.key === 'Tab') {
|
} else if (e.key === 'Enter' || e.key === 'Tab') {
|
||||||
const item = vis[selectedIndexRef.current];
|
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();
|
e.preventDefault();
|
||||||
handleSelectRef.current(item);
|
handleSelectRef.current(item);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user