mirror of
https://github.com/docmost/docmost.git
synced 2026-05-07 06:23:06 +08:00
fix(editor): disable slash and emoji menus inside code blocks (#1897)
The slash command menu (/) and emoji menu (:) were incorrectly triggering when typing inside code blocks, breaking keyboard navigation and confusing users who type paths like /work or symbols like := in their code. Added an `allow` function to both SlashCommand and EmojiCommand extensions that checks if the cursor is inside a code block and disables the menu accordingly. Closes #1730
This commit is contained in:
@@ -15,6 +15,14 @@ const Command = Extension.create({
|
||||
command: ({ editor, range, props }) => {
|
||||
props.command({ editor, range, props });
|
||||
},
|
||||
allow: ({ state, range }) => {
|
||||
const $from = state.doc.resolve(range.from);
|
||||
// Disable emoji menu inside code blocks
|
||||
if ($from.parent.type.name === "codeBlock") {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
} as Partial<SuggestionOptions>,
|
||||
};
|
||||
},
|
||||
|
||||
@@ -17,6 +17,14 @@ const Command = Extension.create({
|
||||
command: ({ editor, range, props }) => {
|
||||
props.command({ editor, range, props });
|
||||
},
|
||||
allow: ({ state, range }) => {
|
||||
const $from = state.doc.resolve(range.from);
|
||||
// Disable slash menu inside code blocks
|
||||
if ($from.parent.type.name === 'codeBlock') {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
} as Partial<SuggestionOptions>,
|
||||
};
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user