mirror of
https://github.com/zadam/trilium.git
synced 2025-11-06 13:26:01 +01:00
Fix writer and seperate schema
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import Command from '@ckeditor/ckeditor5-core/src/command';
|
||||
|
||||
import { getSelectedMathModelWidget } from './utils';
|
||||
|
||||
export default class MathCommand extends Command {
|
||||
@@ -9,17 +10,18 @@ export default class MathCommand extends Command {
|
||||
|
||||
model.change( writer => {
|
||||
let mathtex;
|
||||
if ( selectedElement && selectedElement.is( 'mathtex' ) ) {
|
||||
if ( selectedElement && ( selectedElement.is( 'element', 'mathtex-inline' ) ||
|
||||
selectedElement.is( 'element', 'mathtex-display' ) ) ) {
|
||||
// Update selected element
|
||||
const typeAttr = selectedElement.getAttribute( 'type' );
|
||||
|
||||
// Use already set type if found and is not forced
|
||||
const type = forceOutputType ? outputType : typeAttr || outputType;
|
||||
|
||||
mathtex = writer.createElement( 'mathtex', { equation, type, display } );
|
||||
mathtex = writer.createElement( display ? 'mathtex-display' : 'mathtex-inline', { equation, type, display } );
|
||||
} else {
|
||||
// Create new model element
|
||||
mathtex = writer.createElement( 'mathtex', { equation, type: outputType, display } );
|
||||
mathtex = writer.createElement( display ? 'mathtex-display' : 'mathtex-inline', { equation, type: outputType, display } );
|
||||
}
|
||||
model.insertContent( mathtex );
|
||||
writer.setSelection( mathtex, 'on' );
|
||||
@@ -29,9 +31,10 @@ export default class MathCommand extends Command {
|
||||
refresh() {
|
||||
const model = this.editor.model;
|
||||
const selection = model.document.selection;
|
||||
const selectedElement = selection.getSelectedElement();
|
||||
|
||||
const isAllowed = model.schema.checkChild( selection.focus.parent, 'mathtex' );
|
||||
this.isEnabled = isAllowed;
|
||||
this.isEnabled = selectedElement === null || ( selectedElement.is( 'element', 'mathtex-inline' ) ||
|
||||
selectedElement.is( 'element', 'mathtex-display' ) );
|
||||
|
||||
const selectedEquation = getSelectedMathModelWidget( selection );
|
||||
this.value = selectedEquation ? selectedEquation.getAttribute( 'equation' ) : null;
|
||||
|
||||
Reference in New Issue
Block a user