Add display toggle

This commit is contained in:
Sauli Anto
2019-09-17 15:47:58 +03:00
parent 13a10dcfdd
commit a89cadeac5
5 changed files with 50 additions and 9 deletions

View File

@@ -2,7 +2,7 @@ import Command from '@ckeditor/ckeditor5-core/src/command';
import { getSelectedMathModelWidget } from './utils';
export default class MathCommand extends Command {
execute( equation ) {
execute( equation, display ) {
const model = this.editor.model;
const selection = model.document.selection;
const selectedElement = selection.getSelectedElement();
@@ -12,11 +12,10 @@ export default class MathCommand extends Command {
if ( selectedElement && selectedElement.is( 'mathtex' ) ) {
// Update selected element
const mode = selectedElement.getAttribute( 'mode' );
const display = selectedElement.getAttribute( 'display' );
mathtex = writer.createElement( 'mathtex', { equation, mode, display } );
} else {
// Create new model element
mathtex = writer.createElement( 'mathtex', { equation, mode: 'script', display: true } );
mathtex = writer.createElement( 'mathtex', { equation, mode: 'script', display } );
}
model.insertContent( mathtex );
writer.setSelection( mathtex, 'on' );
@@ -31,6 +30,8 @@ export default class MathCommand extends Command {
this.isEnabled = isAllowed;
const selectedEquation = getSelectedMathModelWidget( selection );
console.log(selectedEquation);
this.value = selectedEquation ? selectedEquation.getAttribute( 'equation' ) : null;
this.display = selectedEquation ? selectedEquation.getAttribute( 'display' ) : null;
}
}