Fix sync bug

This commit is contained in:
Meinzzzz 2025-12-11 23:06:13 +01:00
parent 29f0881c5a
commit 633a09d414
2 changed files with 16 additions and 4 deletions

View File

@ -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 );
}

View File

@ -91,13 +91,24 @@ export default class MathInputView extends View {
textarea.addEventListener( 'input', () => {
const val = textarea.value;
if ( this.mathfield ) {
this.mathfield.setValue( val, { silenceNotifications: true } );
}
this.value = val || null;
if ( this.mathfield ) {
if ( val === '' ) {
this.mathfield.remove();
this.mathfield = null;
this._createMathField();
} else {
this.mathfield.setValue( val, { silenceNotifications: true } );
}
}
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 );