Files
tp-rich-text-box/tp-rtb-code.js
2025-07-06 19:03:59 +02:00

35 lines
774 B
JavaScript

import { TpRtbBaseExtension } from './tp-rtb-base-extension.js';
import Code from '@tiptap/extension-code';
class TpRtbCode extends TpRtbBaseExtension {
constructor() {
super();
this.label = 'Code';
}
getExtension() {
return Code;
}
_handleClick() {
if (this.parentEditor && this.parentEditor.editor) {
this.parentEditor.editor.chain().focus().toggleCode().run();
}
}
_setupEditorListeners() {
const { editor } = this.parentEditor;
// Update button state when selection changes
editor.on('selectionUpdate', () => {
this.active = editor.isActive('code');
});
editor.on('focus', () => {
this.active = editor.isActive('code');
});
}
}
customElements.define('tp-rtb-code', TpRtbCode);