Skip to content

Build your personal knowledge base with Trilium Notes

Fix sync bug

Meinzzzz633a09d414dc
diff --git a/packages/ckeditor5-math/src/ui/mainformview.ts b/packages/ckeditor5-math/src/ui/mainformview.ts
index 8e7d62ed4f..1c2403e18f 100644
--- a/packages/ckeditor5-math/src/ui/mainformview.ts
+++ b/packages/ckeditor5-math/src/ui/mainformview.ts
@@ -116,7 +116,7 @@ export default class MainFormView extends View {
this.mathInputView.on( 'mathfieldReady', () => {
const mathfieldView = this.mathInputView.mathFieldFocusableView;
- if ( mathfieldView.element ) {
+ if ( mathfieldView.element && !this._focusables.has( mathfieldView ) ) {
this._focusables.add( mathfieldView, 0 );
this.focusTracker.add( mathfieldView.element );
}
diff --git a/packages/ckeditor5-math/src/ui/mathinputview.ts b/packages/ckeditor5-math/src/ui/mathinputview.ts
index a5531fca8f..945bebc794 100644
--- a/packages/ckeditor5-math/src/ui/mathinputview.ts
+++ b/packages/ckeditor5-math/src/ui/mathinputview.ts
@@ -91,13 +91,24 @@ export default class MathInputView extends View {
textarea.addEventListener( 'input', () => {
const val = textarea.value;
+ this.value = val || null;
if ( this.mathfield ) {
- this.mathfield.setValue( val, { silenceNotifications: true } );
+ if ( val === '' ) {
+ this.mathfield.remove();
+ this.mathfield = null;
+ this._createMathField();
+ } else {
+ this.mathfield.setValue( val, { silenceNotifications: true } );
+ }
}
- this.value = val || null;
+ this._isSyncing = false;
} );
this.on( 'change:value', ( _e, _n, val ) => {
+ if ( this._isSyncing ) {
+ return;
+ }
+ this._isSyncing = true;
const newVal = val ?? '';
textarea.value = newVal;
if ( this.mathfield && this.mathfield.value !== newVal ) {
@@ -167,6 +178,7 @@ export default class MathInputView extends View {
const val = mf.value;
this.latexTextAreaView.element.value = val;
this.value = val || null;
+ this._isSyncing = false;
} );
container.appendChild( mf );