Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 13 additions & 18 deletions packages/editor/src/core/extensions/mentions/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,44 @@ import { TMentionHandler } from "@/types";
import { MentionsListDropdown, MentionsListDropdownProps } from "./mentions-list-dropdown";

export const renderMentionsDropdown =
(props: Pick<TMentionHandler, "searchCallback">): SuggestionOptions["render"] =>
// @ts-expect-error - Tiptap types are incorrect
(args: Pick<TMentionHandler, "searchCallback">): SuggestionOptions["render"] =>
() => {
const { searchCallback } = props;
const { searchCallback } = args;
let component: ReactRenderer<CommandListInstance, MentionsListDropdownProps> | null = null;

return {
onStart: ({ clientRect, editor }) => {
onStart: (props) => {
if (!searchCallback) return;
if (!clientRect) return;
if (!props.clientRect) return;
component = new ReactRenderer<CommandListInstance, MentionsListDropdownProps>(MentionsListDropdown, {
props: {
...props,
searchCallback,
},
editor: editor,
editor: props.editor,
});
editor.commands.addActiveDropbarExtension(CORE_EXTENSIONS.MENTION);
props.editor.commands.addActiveDropbarExtension(CORE_EXTENSIONS.MENTION);
const element = component.element as HTMLElement;
element.style.position = "absolute";
element.style.zIndex = "100";
document.body.appendChild(element);
updateFloatingUIFloaterPosition(editor, element);
updateFloatingUIFloaterPosition(props.editor, element);
},
onUpdate: ({ clientRect, editor }) => {
onUpdate: (props) => {
component?.updateProps(props);
if (!clientRect) return;
if (!props.clientRect) return;
if (component?.element) {
updateFloatingUIFloaterPosition(editor, component?.element as HTMLElement);
updateFloatingUIFloaterPosition(props.editor, component?.element as HTMLElement);
}
},
onKeyDown: ({ event }) => {
if (event.key === "Escape") {
component?.destroy();
component = null;
return true;
}

const navigationKeys = ["ArrowUp", "ArrowDown", "Enter"];

if (navigationKeys.includes(event.key)) {
event?.stopPropagation();
return component?.ref?.onKeyDown({ event });
}
return component?.ref?.onKeyDown({ event });
return component?.ref?.onKeyDown({ event }) ?? false;
Comment on lines 45 to +51
Copy link

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The simplified keyboard handling removes the specific navigation key filtering and event propagation control that was present in the original code. This could lead to unintended behavior where all keyboard events are passed to the component regardless of their type.

Copilot uses AI. Check for mistakes.
},
onExit: ({ editor }) => {
editor.commands.removeActiveDropbarExtension(CORE_EXTENSIONS.MENTION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ export const SlashCommandsMenu = forwardRef((props: SlashCommandsMenuProps, ref)
);
// handle arrow key navigation
useEffect(() => {
const navigationKeys = ["ArrowUp", "ArrowDown", "Enter"];
const onKeyDown = (e: KeyboardEvent) => {
if (navigationKeys.includes(e.key)) {
if (DROPDOWN_NAVIGATION_KEYS.includes(e.key)) {
e.preventDefault();
const currentSection = selectedIndex.section;
const currentItem = selectedIndex.item;
Expand Down
Loading