2023-02-06 19:35:50 +01:00
|
|
|
import { Plugin } from 'ckeditor5/src/core';
|
|
|
|
import { global, logWarning } from 'ckeditor5/src/utils';
|
2020-11-07 22:19:00 +02:00
|
|
|
import blockAutoformatEditing from '@ckeditor/ckeditor5-autoformat/src/blockautoformatediting';
|
|
|
|
import Math from './math';
|
|
|
|
|
|
|
|
export default class AutoformatMath extends Plugin {
|
|
|
|
static get requires() {
|
2023-02-06 19:35:50 +01:00
|
|
|
return [ Math, 'Autoformat' ];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
init() {
|
|
|
|
const editor = this.editor;
|
|
|
|
|
|
|
|
if ( !editor.plugins.has( 'Math' ) ) {
|
|
|
|
logWarning( 'autoformat-math-feature-missing', editor );
|
|
|
|
}
|
2020-11-07 22:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
afterInit() {
|
|
|
|
const editor = this.editor;
|
|
|
|
const command = editor.commands.get( 'math' );
|
|
|
|
|
|
|
|
if ( command ) {
|
2023-02-06 19:35:50 +01:00
|
|
|
const callback = () => {
|
|
|
|
if ( !command.isEnabled ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
command.display = true;
|
|
|
|
|
|
|
|
// Wait until selection is removed.
|
|
|
|
global.window.setTimeout(
|
|
|
|
() => editor.plugins.get( 'MathUI' )._showUI(),
|
|
|
|
50
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
blockAutoformatEditing( editor, this, /^\$\$$/, callback );
|
|
|
|
blockAutoformatEditing( editor, this, /^\\\[$/, callback );
|
2020-11-07 22:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static get pluginName() {
|
|
|
|
return 'AutoformatMath';
|
|
|
|
}
|
|
|
|
}
|