diff --git a/src/automath.js b/src/automath.js index 9a9bf6e6e..e2cf19286 100644 --- a/src/automath.js +++ b/src/automath.js @@ -5,7 +5,7 @@ import LiveRange from '@ckeditor/ckeditor5-engine/src/model/liverange'; import LivePosition from '@ckeditor/ckeditor5-engine/src/model/liveposition'; import global from '@ckeditor/ckeditor5-utils/src/dom/global'; -import { defaultConfig, extractDelimiters, hasDelimiters, delimitersCounts } from './utils'; +import { extractDelimiters, hasDelimiters, delimitersCounts } from './utils'; export default class AutoMath extends Plugin { static get requires() { @@ -59,7 +59,7 @@ export default class AutoMath extends Plugin { _mathBetweenPositions( leftPosition, rightPosition ) { const editor = this.editor; - const mathConfig = Object.assign( defaultConfig, this.editor.config.get( 'math' ) ); + const mathConfig = this.editor.config.get( 'math' ); const equationRange = new LiveRange( leftPosition, rightPosition ); const walker = equationRange.getWalker( { ignoreElementEnd: true } ); diff --git a/src/mathediting.js b/src/mathediting.js index 61a7c99a1..32a18d906 100644 --- a/src/mathediting.js +++ b/src/mathediting.js @@ -1,10 +1,10 @@ import Plugin from '@ckeditor/ckeditor5-core/src/plugin'; -import { toWidget } from '@ckeditor/ckeditor5-widget/src/utils'; +import { toWidget, viewToModelPositionOutsideModelElement } from '@ckeditor/ckeditor5-widget/src/utils'; import Widget from '@ckeditor/ckeditor5-widget/src/widget'; import MathCommand from './mathcommand'; -import { defaultConfig, renderEquation, extractDelimiters } from './utils'; +import { renderEquation, extractDelimiters } from './utils'; export default class MathEditing extends Plugin { static get requires() { @@ -21,6 +21,17 @@ export default class MathEditing extends Plugin { this._defineSchema(); this._defineConverters(); + + editor.editing.mapper.on( + 'viewToModelPosition', + viewToModelPositionOutsideModelElement( editor.model, viewElement => viewElement.hasClass( 'math' ) ) + ); + editor.config.define( 'math', { + engine: 'mathjax', + outputType: 'script', + forceOutputType: false, + enablePreview: true + } ); } _defineSchema() { @@ -36,7 +47,7 @@ export default class MathEditing extends Plugin { _defineConverters() { const conversion = this.editor.conversion; - const mathConfig = Object.assign( defaultConfig, this.editor.config.get( 'math' ) ); + const mathConfig = this.editor.config.get( 'math' ); // View -> Model conversion.for( 'upcast' ) @@ -114,13 +125,11 @@ export default class MathEditing extends Plugin { const styles = 'user-select: none; ' + ( display ? '' : 'display: inline-block;' ); const classes = 'ck-math-tex ' + ( display ? 'ck-math-tex-display' : 'ck-math-tex-inline' ); - // CKEngine render multiple times if using span instead of div - const mathtexView = viewWriter.createContainerElement( 'div', { + const mathtexView = viewWriter.createContainerElement( 'span', { style: styles, class: classes } ); - // Div is formatted as parent container const uiElement = viewWriter.createUIElement( 'div', null, function( domDocument ) { const domElement = this.toDomElement( domDocument ); diff --git a/src/mathui.js b/src/mathui.js index abd852052..221218710 100644 --- a/src/mathui.js +++ b/src/mathui.js @@ -10,7 +10,6 @@ import MainFormView from './ui/mainformview'; // Need math commands from there import MathEditing from './mathediting'; -import { defaultConfig } from './utils'; import mathIcon from '../theme/icons/math.svg'; @@ -69,7 +68,7 @@ export default class MathUI extends Plugin { const editor = this.editor; const mathCommand = editor.commands.get( 'math' ); - const mathConfig = Object.assign( defaultConfig, this.editor.config.get( 'math' ) ); + const mathConfig = this.editor.config.get( 'math' ); const formView = new MainFormView( editor.locale, mathConfig.engine, mathConfig.enablePreview, this._previewUid ); @@ -111,7 +110,7 @@ export default class MathUI extends Plugin { this._balloon.add( { view: this.formView, - position: this._getBalloonPositionData(), + position: this._getBalloonPositionData() } ); if ( this._balloon.visibleView === this.formView ) { diff --git a/src/utils.js b/src/utils.js index 812c6f34e..b96385590 100644 --- a/src/utils.js +++ b/src/utils.js @@ -2,13 +2,6 @@ import global from '@ckeditor/ckeditor5-utils/src/dom/global'; -export const defaultConfig = { - engine: 'mathjax', - outputType: 'script', - forceOutputType: false, - enablePreview: true -}; - export function getSelectedMathModelWidget( selection ) { const selectedElement = selection.getSelectedElement(); @@ -24,7 +17,7 @@ export function isMathJaxVersion3( version ) { return version && typeof version === 'string' && version.split( '.' ).length === 3 && version.split( '.' )[ 0 ] === '3'; } -// Check if equation has delimiters +// Check if equation has delimiters. export function hasDelimiters( text ) { return text.match( /^(\\\[.*?\\\]|\\\(.*?\\\))$/ ); } @@ -108,7 +101,7 @@ function selectRenderMode( element, preview, previewUid, cb ) { } } -function renderMathJax3( equation, element, display, after ) { +function renderMathJax3( equation, element, display, cb ) { let promiseFunction = undefined; if ( typeof MathJax.tex2chtmlPromise !== 'undefined' ) { promiseFunction = MathJax.tex2chtmlPromise; @@ -122,7 +115,7 @@ function renderMathJax3( equation, element, display, after ) { element.removeChild( element.firstChild ); } element.appendChild( node ); - after(); + cb(); } ); } }