Skip to content

Commit

Permalink
Fix preview flickering effect
Browse files Browse the repository at this point in the history
  • Loading branch information
isaul32 committed Oct 9, 2019
1 parent 69a0264 commit 70fefa8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/mathui.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ export default class MathUI extends Plugin {
super.destroy();

this._form.destroy();

// Destroy preview element
let prewviewEl = document.getElementById( this._previewUid ); // eslint-disable-line
if ( prewviewEl ) {
prewviewEl.parentNode.removeChild( prewviewEl );
}
}

_showUI() {
Expand Down Expand Up @@ -151,7 +157,7 @@ export default class MathUI extends Plugin {
// Hide preview element
let prewviewEl = document.getElementById( this._previewUid );// eslint-disable-line
if ( prewviewEl ) {
prewviewEl.style.display = 'none';
prewviewEl.style.visibility = 'hidden';
}

this.editor.editing.view.focus();
Expand Down
7 changes: 4 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ export function renderEquation( equation, element, engine = 'katex', display = f
selectRenderMode( element, preview, previewUid, el => {
renderMathJax3( equation, el, display, () => {
if ( preview ) {
el.style.display = 'block';
moveAndScaleElement( element, el );
el.style.visibility = 'visible';
}
} );
} );
Expand All @@ -64,8 +64,8 @@ export function renderEquation( equation, element, engine = 'katex', display = f
if ( preview ) {
// eslint-disable-next-line
MathJax.Hub.Queue( () => {
el.style.display = 'block';
moveAndScaleElement( element, el );
el.style.visibility = 'visible';
} );
}
} );
Expand All @@ -78,8 +78,8 @@ export function renderEquation( equation, element, engine = 'katex', display = f
displayMode: display
} );
if ( preview ) {
el.style.display = 'block';
moveAndScaleElement( element, el );
el.style.visibility = 'visible';
}
} );
} else if ( typeof engine === 'function' ) {
Expand Down Expand Up @@ -140,6 +140,7 @@ function getPreviewElement( element, previewUid ) {
if ( !prewviewEl ) {
prewviewEl = document.createElement( 'div' ); // eslint-disable-line
prewviewEl.setAttribute( 'id', previewUid );
prewviewEl.style.visibility = 'hidden';
document.body.appendChild( prewviewEl ); // eslint-disable-line

let ticking = false;
Expand Down

0 comments on commit 70fefa8

Please sign in to comment.