mirror of
https://github.com/zadam/trilium.git
synced 2025-12-06 07:24:25 +01:00
refactor: avoid recursive updates in mathLiveInput by normalizing value before updateing
This commit is contained in:
parent
56834cb88a
commit
1471a72633
@ -283,33 +283,29 @@ export default class MainFormView extends View {
|
|||||||
const mathLiveInput = new MathLiveInputView( this.locale );
|
const mathLiveInput = new MathLiveInputView( this.locale );
|
||||||
|
|
||||||
const onInput = () => {
|
const onInput = () => {
|
||||||
const rawValue = mathLiveInput.value ?? '';
|
let equationInput = ( mathLiveInput.value ?? '' ).trim();
|
||||||
let equationInput = rawValue.trim();
|
|
||||||
|
|
||||||
// If input has delimiters
|
// If input has delimiters, strip them and update the display mode.
|
||||||
if ( hasDelimiters( equationInput ) ) {
|
if ( hasDelimiters( equationInput ) ) {
|
||||||
// Get equation without delimiters
|
|
||||||
const params = extractDelimiters( equationInput );
|
const params = extractDelimiters( equationInput );
|
||||||
|
|
||||||
// Remove delimiters from input field
|
|
||||||
mathLiveInput.value = params.equation;
|
|
||||||
|
|
||||||
equationInput = params.equation;
|
equationInput = params.equation;
|
||||||
|
|
||||||
// Update display button and preview
|
|
||||||
this.displayButtonView.isOn = params.display;
|
this.displayButtonView.isOn = params.display;
|
||||||
}
|
}
|
||||||
|
|
||||||
const normalizedEquation = equationInput.length ? equationInput : null;
|
const normalizedEquation = equationInput.length ? equationInput : null;
|
||||||
|
|
||||||
|
// Update self if needed.
|
||||||
if ( mathLiveInput.value !== normalizedEquation ) {
|
if ( mathLiveInput.value !== normalizedEquation ) {
|
||||||
mathLiveInput.value = normalizedEquation;
|
mathLiveInput.value = normalizedEquation;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sync to raw LaTeX textarea
|
// Sync to raw LaTeX textarea if its value is different.
|
||||||
this.rawLatexInputView.value = equationInput;
|
if ( this.rawLatexInputView.value !== equationInput ) {
|
||||||
|
this.rawLatexInputView.value = equationInput;
|
||||||
|
}
|
||||||
|
|
||||||
if ( this.previewEnabled && this.mathView ) {
|
// Update preview if enabled and its value is different.
|
||||||
// Update preview
|
if ( this.previewEnabled && this.mathView && this.mathView.value !== equationInput ) {
|
||||||
this.mathView.value = equationInput;
|
this.mathView.value = equationInput;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user