Skip to content

Build your personal knowledge base with Trilium Notes

feat(editor): hide balloon toolbar when in code block

Elian Doran995de2b7406b
diff --git a/packages/ckeditor5/src/plugins/code_block_toolbar.ts b/packages/ckeditor5/src/plugins/code_block_toolbar.ts
index ff9014fd87..4bdd30f0c6 100644
--- a/packages/ckeditor5/src/plugins/code_block_toolbar.ts
+++ b/packages/ckeditor5/src/plugins/code_block_toolbar.ts
@@ -1,4 +1,4 @@
-import { CodeBlock, Plugin, ViewDocumentFragment, WidgetToolbarRepository, type ViewNode } from "ckeditor5";
+import { BalloonToolbarShowEvent, CodeBlock, Plugin, ViewDocumentFragment, WidgetToolbarRepository, type ViewNode } from "ckeditor5";
import CodeBlockLanguageDropdown from "./code_block_language_dropdown";
import CopyToClipboardButton from "./copy_to_clipboard_button";
@@ -37,6 +37,18 @@ export default class CodeBlockToolbar extends Plugin {
return null;
}
});
+
+ // Hide balloon toolbar when in a code block
+ if (editor.plugins.has("BalloonToolbar")) {
+ editor.listenTo(editor.plugins.get('BalloonToolbar'), 'show', (evt) => {
+ const firstPosition = editor.model.document.selection.getFirstPosition();
+ const isInCodeBlock = firstPosition?.findAncestor('codeBlock');
+
+ if (isInCodeBlock) {
+ evt.stop(); // Prevent the balloon toolbar from showing
+ }
+ }, { priority: 'high' });
+ }
}
}