GitHub

@@ -572,11 +572,6 @@ export function useEditorMenu<T = any>(options: EditorMenuOptions<T>) {

572572573573

const handlers = {

574574

onStart: (suggestionProps: SuggestionProps) => {

575-

// When ignoreFilter is true, always use fresh items from the reactive source

576-

filteredItems.value = options.ignoreFilter

577-

? items.value.slice(0, limit)

578-

: suggestionProps.items as T[]

579-580575

// Start at first selectable item (index 0 in selectableItems)

581576

selectedIndex.value = 0

582577

@@ -586,6 +581,17 @@ export function useEditorMenu<T = any>(options: EditorMenuOptions<T>) {

586581

// Store the trigger position (where the `/`, `@`, or `:` is)

587582

triggerClientRect = suggestionProps.clientRect as () => DOMRect | null

588583584+

// The suggestion plugin emits a loading pass with placeholder (empty) items

585+

// before the resolved items arrive; skip it to avoid opening with no items.

586+

if (suggestionProps.loading) {

587+

return

588+

}

589+590+

// When ignoreFilter is true, always use fresh items from the reactive source

591+

filteredItems.value = options.ignoreFilter

592+

? items.value.slice(0, limit)

593+

: suggestionProps.items as T[]

594+589595

// Only show menu if there are items

590596

if (!filteredItems.value.length) {

591597

return

@@ -594,14 +600,20 @@ export function useEditorMenu<T = any>(options: EditorMenuOptions<T>) {

594600

showMenu()

595601

},

596602

onUpdate: (suggestionProps: SuggestionProps) => {

603+

// Update the command function

604+

commandFn = (item: T) => suggestionProps.command(item)

605+606+

// Skip the loading pass (placeholder items) so the menu stays mounted while the

607+

// resolved items are fetched, otherwise it is destroyed and recreated on every keystroke.

608+

if (suggestionProps.loading) {

609+

return

610+

}

611+597612

// When ignoreFilter is true, always use fresh items from the reactive source

598613

filteredItems.value = options.ignoreFilter

599614

? items.value.slice(0, limit)

600615

: suggestionProps.items as T[]

601616602-

// Update the command function

603-

commandFn = (item: T) => suggestionProps.command(item)

604-605617

// Reset selected index if out of bounds (comparing against selectableItems)

606618

if (selectedIndex.value >= selectableItems.value.length) {

607619

selectedIndex.value = Math.max(0, selectableItems.value.length - 1)

Read the original on github.com ↗