Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(editor): release keys from empty mention picker (#8517)

Multica Eve9e7e529b7fcb
diff --git a/packages/views/editor/extensions/mention-suggestion.test.tsx b/packages/views/editor/extensions/mention-suggestion.test.tsx
index c75681b046..2a8bd3de81 100644
--- a/packages/views/editor/extensions/mention-suggestion.test.tsx
+++ b/packages/views/editor/extensions/mention-suggestion.test.tsx
@@ -178,6 +178,28 @@ function itemArgs(query: string) {
};
}
+const PICKER_INTERACTION_KEYS: KeyboardEventInit[] = [
+ { key: "Enter" },
+ { key: "Enter", shiftKey: true },
+ { key: "Enter", metaKey: true },
+ { key: "Enter", ctrlKey: true },
+ { key: "Enter", altKey: true },
+ { key: "Tab" },
+ { key: "ArrowUp" },
+ { key: "ArrowDown" },
+ { key: "n", ctrlKey: true },
+ { key: "j", ctrlKey: true },
+ { key: "p", ctrlKey: true },
+ { key: "k", ctrlKey: true },
+];
+
+function pressPickerInteractionKeys(ref: MentionListRef | null): boolean[] {
+ if (!ref) return [];
+ return PICKER_INTERACTION_KEYS.map((init) =>
+ ref.onKeyDown({ event: new KeyboardEvent("keydown", init) }),
+ );
+}
+
describe("createMentionSuggestion", () => {
beforeEach(() => {
searchIssuesMock.mockReset();
@@ -258,7 +280,7 @@ describe("createMentionSuggestion", () => {
);
});
- it("does not select a runtime-required mention row by click or keyboard", () => {
+ it("keeps picker keys inert when every mention row is disabled", () => {
const command = vi.fn<(item: MentionItem) => void>();
const ref = createRef<MentionListRef>();
render(
@@ -284,11 +306,10 @@ describe("createMentionSuggestion", () => {
});
expect(row).toHaveAttribute("aria-disabled", "true");
fireEvent.click(row);
- expect(
- ref.current?.onKeyDown({
- event: new KeyboardEvent("keydown", { key: "Enter" }),
- }),
- ).toBe(true);
+
+ expect(pressPickerInteractionKeys(ref.current)).toEqual(
+ PICKER_INTERACTION_KEYS.map(() => true),
+ );
expect(command).not.toHaveBeenCalled();
});
@@ -357,14 +378,23 @@ describe("createMentionSuggestion", () => {
expect(searchProjectsMock).not.toHaveBeenCalled();
});
- it("captures Enter while the popup has no selectable items", () => {
+ it("lets picker keys reach the editor while search has no result rows", async () => {
+ searchIssuesMock.mockResolvedValue({ issues: [], total: 0 });
const ref = createRef<MentionListRef>();
render(<I18nWrapper><MentionList ref={ref} items={[]} query="协作" command={vi.fn()} /></I18nWrapper>);
- expect(
- ref.current?.onKeyDown({ event: new KeyboardEvent("keydown", { key: "Enter" }) }),
- ).toBe(true);
+ expect(screen.getByText("Searching...")).toBeInTheDocument();
+ expect(pressPickerInteractionKeys(ref.current)).toEqual(
+ PICKER_INTERACTION_KEYS.map(() => false),
+ );
+
+ await waitFor(() => {
+ expect(screen.getByText("No results")).toBeInTheDocument();
+ });
+ expect(pressPickerInteractionKeys(ref.current)).toEqual(
+ PICKER_INTERACTION_KEYS.map(() => false),
+ );
});
// MUL-3685: plain Tab accepts the highlighted row exactly like Enter.
@@ -414,16 +444,6 @@ describe("createMentionSuggestion", () => {
expect(command).not.toHaveBeenCalled();
});
- it("captures Tab while the popup has no selectable items, like Enter", () => {
- const ref = createRef<MentionListRef>();
-
- render(<I18nWrapper><MentionList ref={ref} items={[]} query="协作" command={vi.fn()} /></I18nWrapper>);
-
- expect(
- ref.current?.onKeyDown({ event: new KeyboardEvent("keydown", { key: "Tab" }) }),
- ).toBe(true);
- });
-
// MUL-3607: groupItems() re-buckets the list (current → recent → search →
// users → issues), so an item that sits LATER in the data array can render
// NEAR THE TOP. Selection must follow the rendered order — otherwise the
diff --git a/packages/views/editor/extensions/mention-suggestion.tsx b/packages/views/editor/extensions/mention-suggestion.tsx
index 1cff127f30..5236a4d147 100644
--- a/packages/views/editor/extensions/mention-suggestion.tsx
+++ b/packages/views/editor/extensions/mention-suggestion.tsx
@@ -409,9 +409,14 @@ export const MentionList = forwardRef<MentionListRef, MentionListProps>(
// see pickerNavigationDirection.
const direction = pickerNavigationDirection(event);
if (direction !== null) {
+ // With no rows, including while remote search is pending, the picker
+ // has nothing to navigate. Let the host editor own the key instead.
+ if (orderedItems.length === 0) return false;
const selectableIndexes = orderedItems.flatMap((item, index) =>
item.disabledReason ? [] : [index],
);
+ // Rows exist but all are disabled: keep the picker inert rather than
+ // moving the caret behind the visible popup.
if (selectableIndexes.length === 0) return true;
const current = selectableIndexes.indexOf(selectedIndex);
const delta =
@@ -427,6 +432,11 @@ export const MentionList = forwardRef<MentionListRef, MentionListProps>(
// Enter is the canonical accept; plain Tab is an additive alias (see
// isPickerAcceptKey). Shift/modifier+Tab fall through to focus nav.
if (isPickerAcceptKey(event)) {
+ // An empty picker cannot accept anything, so preserve the editor's
+ // newline, submit shortcut, and focus-navigation behavior.
+ if (orderedItems.length === 0) return false;
+ // A non-empty list can still have no selectable row when every item
+ // is disabled. Keep those visible rows inert instead of falling through.
if (selectedIndex < 0) return true;
selectItem(orderedItems[selectedIndex]);
return true;