diff --git a/src/editor-mathfield/mathfield-private.ts b/src/editor-mathfield/mathfield-private.ts index 4a99b5966..88d874263 100644 --- a/src/editor-mathfield/mathfield-private.ts +++ b/src/editor-mathfield/mathfield-private.ts @@ -1716,26 +1716,20 @@ If you are using Vue, this may be because you are using the runtime-only build o // don't do that for custom elements, so we do it ourselves. @futureweb // - // Wait for the window/document visibility to change + // Wait for the window focus to change // (the mathfield gets blurred before the window) const controller = new AbortController(); const signal = controller.signal; - document.addEventListener( - 'visibilitychange', + window.addEventListener( + 'blur', () => { - if (document.visibilityState === 'hidden') { - document.addEventListener( - 'visibilitychange', - () => { - if ( - isValidMathfield(this) && - document.visibilityState === 'visible' - ) - this.focus({ preventScroll: true }); - }, - { once: true, signal } - ); - } + window.addEventListener( + 'focus', + () => { + if (isValidMathfield(this)) this.focus({ preventScroll: true }); + }, + { once: true, signal } + ); }, { once: true, signal } ); @@ -1745,6 +1739,12 @@ If you are using Vue, this may be because you are using the runtime-only build o document.addEventListener('focusin', () => controller.abort(), { once: true, }); + + // If user clicks anywhere, cancel the refocus (covers case where + // click doesn't cause an element to come into focus) + document.addEventListener('click', () => controller.abort(), { + once: true, + }); } } diff --git a/src/formats/atom-to-ascii-math.ts b/src/formats/atom-to-ascii-math.ts index 3d899d3af..18af766ed 100644 --- a/src/formats/atom-to-ascii-math.ts +++ b/src/formats/atom-to-ascii-math.ts @@ -256,9 +256,12 @@ export function atomToAsciiMath( result += atomToAsciiMath(genfracAtom.below, options); result += ')'; } else { - // No bar line, i.e. \choose, etc... - result += '(' + atomToAsciiMath(genfracAtom.above, options) + '),'; - result += '(' + atomToAsciiMath(genfracAtom.below, options) + ')'; + // No bar line, for \choose + result += '(('; + result += atomToAsciiMath(genfracAtom.above, options); + result += ') choose ('; + result += atomToAsciiMath(genfracAtom.below, options); + result += '))'; } if (genfracAtom.leftDelim || genfracAtom.rightDelim) { @@ -372,12 +375,8 @@ export function atomToAsciiMath( const rows: string[] = []; for (const row of array) { const cells: string[] = []; - for (const cell of row) - cells.push( - rowDelim[0] + atomToAsciiMath(cell, options) + rowDelim[1] - ); - - rows.push(cells.join(',')); + for (const cell of row) cells.push(atomToAsciiMath(cell, options)); + rows.push(rowDelim[0] + cells.join(',') + rowDelim[1]); } const delim = {