Skip to content

Commit d29e5e7

Browse files
committed
fix(rich-editor): exempt an active @-mention query from the per-group cap
The per-group MAX_PER_GROUP limit is meant to keep the unfiltered menu from flooding; applying it while a query is active hid matches past the eighth in a category, so search couldn't reach them. Cap only when there's no query. Adds a regression test (12 matches shown when searching).
1 parent 8c5cc52 commit d29e5e7

2 files changed

Lines changed: 30 additions & 5 deletions

File tree

apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/mention/mention-list.test.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,29 @@ describe('MentionList keyboard nav', () => {
7575
expect(command).toHaveBeenCalledWith(items[1])
7676
})
7777

78+
it('an active query is exempt from the per-group cap (search reaches every match)', () => {
79+
const ref = createRef<MentionListHandle>()
80+
const command = vi.fn()
81+
const store = createMentionStore()
82+
// 12 matches in one group — more than MAX_PER_GROUP (8).
83+
const many: MentionItem[] = Array.from({ length: 12 }, (_, i) => ({
84+
kind: 'file',
85+
id: `x${i}`,
86+
label: `report-${i}`,
87+
group: 'Files',
88+
icon: File,
89+
}))
90+
91+
act(() => {
92+
root.render(
93+
<MentionList ref={ref} query='report' command={command} store={store} editor={editor} />
94+
)
95+
})
96+
act(() => store.set(many))
97+
98+
expect(container.querySelectorAll('[role="option"]').length).toBe(12)
99+
})
100+
78101
it('accepts the active item on Tab, like Enter', () => {
79102
const ref = createRef<MentionListHandle>()
80103
const command = vi.fn()

apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/mention/mention-list.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ interface MentionListProps {
2121
editor: Editor
2222
}
2323

24-
/** Per-group cap so a large workspace can't flood the menu; filtering still searches the full set. */
24+
/** Per-group cap so a large workspace can't flood the *unfiltered* menu; an active query is exempt so
25+
* search reaches every match, not just the first eight in a category. */
2526
const MAX_PER_GROUP = 8
2627

2728
/** Category heading order in the menu. */
@@ -48,9 +49,10 @@ export const MentionList = forwardRef<MentionListHandle, MentionListProps>(funct
4849
const containerRef = useRef<HTMLDivElement>(null)
4950

5051
/**
51-
* Filtered, group-capped, flattened in category order; `index` is the flat position for nav. A single
52-
* pass over the full set filters by label and buckets by group (capped), then reads the buckets in
53-
* category order — avoiding a separate filter pass per group.
52+
* Filtered, flattened in category order; `index` is the flat position for nav. A single pass over the
53+
* full set filters by label and buckets by group, then reads the buckets in category order — avoiding
54+
* a separate filter pass per group. The per-group cap applies only to the unfiltered menu; once a
55+
* query is active every match is shown so search can reach items past the eighth in a category.
5456
*/
5557
const { flat, groups } = useMemo(() => {
5658
const q = query.trim().toLowerCase()
@@ -59,7 +61,7 @@ export const MentionList = forwardRef<MentionListHandle, MentionListProps>(funct
5961
if (q && !item.label.toLowerCase().includes(q)) continue
6062
const bucket = byGroup.get(item.group)
6163
if (!bucket) byGroup.set(item.group, [item])
62-
else if (bucket.length < MAX_PER_GROUP) bucket.push(item)
64+
else if (q || bucket.length < MAX_PER_GROUP) bucket.push(item)
6365
}
6466

6567
const ordered: { group: string; items: { item: MentionItem; index: number }[] }[] = []

0 commit comments

Comments
 (0)