Skip to content

Commit

Permalink
fix: fixed test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
arnog committed Jan 29, 2025
1 parent 72394d1 commit 9651695
Show file tree
Hide file tree
Showing 9 changed files with 2,679 additions and 2,691 deletions.
5,345 changes: 2,668 additions & 2,677 deletions src/api.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/core/atom-class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export class Atom<T extends (Argument | null)[] = (Argument | null)[]> {
this.command = options.command ?? this.value ?? '';
this.mode = options.mode ?? 'math';
if (options.isFunction) this.isFunction = true;
if (options.isRoot) this.isRoot = true;
if (options.isRoot || this.type === 'root') this.isRoot = true;
if (options.limits) this.subsupPlacement = options.limits;
this.style = { ...(options.style ?? {}) };
this.displayContainsHighlight = options.displayContainsHighlight ?? false;
Expand Down
4 changes: 2 additions & 2 deletions src/editor-mathfield/mathfield-private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ export class _Mathfield implements Mathfield, KeyboardDelegateInterface {
const body = parseLatex(elementText, { context: this.context });
let root: Atom;
if (body.length === 1 && body[0].isRoot) root = body[0];
else root = new Atom({ type: 'root', mode, body, isRoot: true });
else root = new Atom({ type: 'root', mode, body });

this.model = new _Model(this, mode, root);

Expand Down Expand Up @@ -1756,7 +1756,7 @@ If you are using Vue, this may be because you are using the runtime-only build o

onCompositionStart(_composition: string): void {
// Clear the selection if there is one
this.model.deleteAtoms(range(this.model.selection));
deleteRange(this.model, range(this.model.selection), 'insertText');
const caretPoint = getCaretPoint(this.field!);
if (!caretPoint) return;
requestAnimationFrame(() => {
Expand Down
8 changes: 4 additions & 4 deletions src/editor-model/model-private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,18 +316,18 @@ export class _Model implements Model {
* Note that an atom with children is included in the result only if
* all its children are in range.
*/
getAtoms(arg: Selection, options?: GetAtomOptions): Readonly<Atom[]>;
getAtoms(arg: Range, options?: GetAtomOptions): Readonly<Atom[]>;
getAtoms(arg: Selection, options?: GetAtomOptions): ReadonlyArray<Atom>;
getAtoms(arg: Range, options?: GetAtomOptions): ReadonlyArray<Atom>;
getAtoms(
from: Offset,
to?: Offset,
options?: GetAtomOptions
): Readonly<Atom[]>;
): ReadonlyArray<Atom>;
getAtoms(
arg1: Selection | Range | Offset,
arg2?: Offset | GetAtomOptions,
arg3?: GetAtomOptions
): Readonly<Atom[]> {
): ReadonlyArray<Atom> {
let options = arg3 ?? {};
if (isSelection(arg1)) {
options = (arg2 as GetAtomOptions) ?? {};
Expand Down
2 changes: 1 addition & 1 deletion src/latex-commands/definitions-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ const DEFAULT_MACROS: MacroDictionary = {
'iff': {
primitive: true,
captureSelection: true,
def: '\\;\\char"27FA\\;', // >2,000 Note: additional spaces around the arrows
def: '\\;\\Longleftrightarrow\\;}', // >2,000 Note: additional spaces around the arrows, as per AMSMATH package definition
},
'nicefrac': '^{#1}\\!\\!/\\!_{#2}',

Expand Down
2 changes: 0 additions & 2 deletions src/public/mathlive-ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ export function convertLatexToMarkup(
//
const root = new Atom({
type: 'root',
isRoot: true,
mode: parseMode,
body: parseLatex(text, { context: effectiveContext, parseMode, mathstyle }),
});
Expand Down Expand Up @@ -237,7 +236,6 @@ export function convertLatexToAsciiMath(
return atomToAsciiMath(
new Atom({
type: 'root',
isRoot: true,
body: parseLatex(latex, { parseMode }),
})
);
Expand Down
1 change: 0 additions & 1 deletion src/virtual-keyboard/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ function latexToMarkup(latex: string): string {
const root = new Atom({
mode: 'math',
type: 'root',
isRoot: true,
body: parseLatex(latex, {
context,
args: (arg) =>
Expand Down
4 changes: 2 additions & 2 deletions test/math-ascii.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('ASCII MATH', function () {
equalASCIIMath('\\Gamma +1', 'Gamma+1');
equalASCIIMath('\\frac{\\pi }{2\\pi }', '(pi)/(2pi)');

equalASCIIMath('x\\in \\R ', 'x in RR');
equalASCIIMath('x\\in \\mathbb{R} ', 'x in RR');

// Avoid collisions with digits
expect(convertLatexToAsciiMath('1^2 3^4')).toBe('1^2 3^4');
Expand All @@ -81,7 +81,7 @@ describe('ASCII MATH', function () {
equalASCIIMath('\\left\\lbrack1,1\\right\\rbrack', '[1,1]');
equalASCIIMath('\\left\\lbrace1,1\\right\\rbrace', '{1,1}');
equalASCIIMath('\\left(1,1\\right)', '(1,1)');

expect(convertAsciiMathToLatex('1/2')).toBe('\\frac{1}{2}');
expect(convertAsciiMathToLatex('(1/2)')).toBe('\\left(\\frac{1}{2}\\right)');
expect(convertAsciiMathToLatex('1/2sin x')).toBe('\\frac{1}{2}\\sin x');
Expand Down
2 changes: 1 addition & 1 deletion test/smoke/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ <h2>MathML</h2>
};

mf.addEventListener('mount', () => {
setupMathfield(mf);
// setupMathfield(mf);
mf.addEventListener("input", (ev) => updateContent(mf));


Expand Down

0 comments on commit 9651695

Please sign in to comment.