Rich text / foldkit-mixins-richtext

slashMenu

function · packages/richtext-dom/src/editor.ts:334

function slashMenu<Payload>(
  entries: ReadonlyArray<SlashEntry<Payload>>,
  textBefore: string,
  index: number,
): SlashMenu<Payload> | undefined

The menu the caret is in, or undefined when its text is not a slash command — the one value that decides both whether to render a menu and what Enter means, so the view and update cannot disagree.

index is what the menu last highlighted. A stale index — fewer matches than it named, or a negative one — falls back to the first match, because a query that narrows must not leave Enter with nothing to choose. A query that matches nothing is still a menu: it renders as empty, and highlighted is undefined, which is what keeps /zzz from choosing anything.