diff --git a/packages/ckeditor5/src/plugins.ts b/packages/ckeditor5/src/plugins.ts index abf51f086..f96e444ee 100644 --- a/packages/ckeditor5/src/plugins.ts +++ b/packages/ckeditor5/src/plugins.ts @@ -31,6 +31,7 @@ import CodeBlockLanguageDropdown from "./plugins/code_block_language_dropdown.js import MoveBlockUpDownPlugin from "./plugins/move_block_updown.js"; import ScrollOnUndoRedoPlugin from "./plugins/scroll_on_undo_redo.js" import InlineCodeNoSpellcheck from "./plugins/inline_code_no_spellcheck.js"; +import DisableMentionInCodeBlock from "./plugins/disable_mention_in_codeblock.js"; /** * Plugins that are specific to Trilium and not part of the CKEditor 5 core, included in both text editors but not in the attribute editor. @@ -53,6 +54,7 @@ const TRILIUM_PLUGINS: typeof Plugin[] = [ MoveBlockUpDownPlugin, ScrollOnUndoRedoPlugin, InlineCodeNoSpellcheck, + DisableMentionInCodeBlock, ]; /** diff --git a/packages/ckeditor5/src/plugins/disable_mention_in_codeblock.ts b/packages/ckeditor5/src/plugins/disable_mention_in_codeblock.ts new file mode 100644 index 000000000..9407ba6f7 --- /dev/null +++ b/packages/ckeditor5/src/plugins/disable_mention_in_codeblock.ts @@ -0,0 +1,23 @@ +import { Plugin } from "ckeditor5"; + +/** + * Disables the mention feature (triggered by `@`) inside code blocks. + * This prevents the autocomplete popup from appearing when typing `@` within code blocks. + */ +export default class DisableMentionInCodeBlock extends Plugin { + public static get pluginName() { + return "DisableMentionInCodeBlock" as const; + } + + init() { + const editor = this.editor; + const schema = editor.model.schema; + + // Disallow mention attribute inside code blocks + schema.addAttributeCheck((context, attributeName) => { + if (attributeName === 'mention' && context.endsWith('codeBlock $text')) { + return false; + } + }); + } +}