mirror of
https://github.com/zadam/trilium.git
synced 2025-11-13 08:45:50 +01:00
feat(math): support multi-line formula editing
This commit is contained in:
@@ -94,7 +94,6 @@ export async function renderEquation(
|
||||
el => {
|
||||
renderMathJax3( equation, el, display, () => {
|
||||
if ( preview ) {
|
||||
moveAndScaleElement( element, el );
|
||||
el.style.visibility = 'visible';
|
||||
}
|
||||
} );
|
||||
@@ -115,7 +114,6 @@ export async function renderEquation(
|
||||
if ( preview && isMathJaxVersion2( MathJax ) ) {
|
||||
// eslint-disable-next-line new-cap
|
||||
MathJax.Hub.Queue( () => {
|
||||
moveAndScaleElement( element, el );
|
||||
el.style.visibility = 'visible';
|
||||
} );
|
||||
}
|
||||
@@ -139,7 +137,6 @@ export async function renderEquation(
|
||||
} );
|
||||
}
|
||||
if ( preview ) {
|
||||
moveAndScaleElement( element, el );
|
||||
el.style.visibility = 'visible';
|
||||
}
|
||||
}
|
||||
@@ -295,47 +292,7 @@ function getPreviewElement(
|
||||
previewEl.setAttribute( 'id', previewUid );
|
||||
previewEl.classList.add( ...previewClassName );
|
||||
previewEl.style.visibility = 'hidden';
|
||||
document.body.appendChild( previewEl );
|
||||
|
||||
let ticking = false;
|
||||
|
||||
const renderTransformation = () => {
|
||||
if ( !ticking ) {
|
||||
window.requestAnimationFrame( () => {
|
||||
if ( previewEl ) {
|
||||
moveElement( element, previewEl );
|
||||
ticking = false;
|
||||
}
|
||||
} );
|
||||
|
||||
ticking = true;
|
||||
}
|
||||
};
|
||||
|
||||
// Create scroll listener for following
|
||||
window.addEventListener( 'resize', renderTransformation );
|
||||
window.addEventListener( 'scroll', renderTransformation );
|
||||
element.appendChild( previewEl );
|
||||
}
|
||||
return previewEl;
|
||||
}
|
||||
|
||||
function moveAndScaleElement( parent: HTMLElement, child: HTMLElement ) {
|
||||
// Move to right place
|
||||
moveElement( parent, child );
|
||||
|
||||
// Scale parent element same as preview
|
||||
const domRect = child.getBoundingClientRect();
|
||||
parent.style.width = domRect.width + 'px';
|
||||
parent.style.height = domRect.height + 'px';
|
||||
}
|
||||
|
||||
function moveElement( parent: HTMLElement, child: HTMLElement ) {
|
||||
const domRect = parent.getBoundingClientRect();
|
||||
const left = window.scrollX + domRect.left;
|
||||
const top = window.scrollY + domRect.top;
|
||||
child.style.position = 'absolute';
|
||||
child.style.left = left + 'px';
|
||||
child.style.top = top + 'px';
|
||||
child.style.zIndex = 'var(--ck-z-panel)';
|
||||
child.style.pointerEvents = 'none';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user