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

This commit is contained in:
Elian Doran 2025-06-12 10:12:17 +03:00
parent be718ce4e0
commit 995de2b740
No known key found for this signature in database

View File

@ -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' });
}
}
}