From 64db04f1bb8d1edf78fd8c011309771378c851e4 Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Wed, 21 Apr 2021 14:18:44 +0200 Subject: [PATCH] Prefer exec over matchAll --- ts/editor/cloze.ts | 14 +++++++++----- ts/tsconfig.json | 9 +-------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/ts/editor/cloze.ts b/ts/editor/cloze.ts index 9d3be3530..8a3a6491a 100644 --- a/ts/editor/cloze.ts +++ b/ts/editor/cloze.ts @@ -17,11 +17,15 @@ function getCurrentHighestCloze(increment: boolean): number { let highest = 0; forEditorField([], (field) => { - const matches = field.editingArea.editable.fieldHTML.matchAll(clozePattern); - highest = Math.max( - highest, - ...[...matches].map((match: RegExpMatchArray): number => Number(match[1])) - ); + const fieldHTML = field.editingArea.editable.fieldHTML; + const matches: number[] = []; + let match: RegExpMatchArray | null = null; + + while ((match = clozePattern.exec(fieldHTML))) { + matches.push(Number(match[1])); + } + + highest = Math.max(highest, ...matches); }); if (increment) { diff --git a/ts/tsconfig.json b/ts/tsconfig.json index 63afaad58..bc98946fd 100644 --- a/ts/tsconfig.json +++ b/ts/tsconfig.json @@ -3,14 +3,7 @@ "compilerOptions": { "target": "es6", "module": "es6", - "lib": [ - "es2017", - "es2020.string", - "es2019.array", - "es2018.promise", - "dom", - "dom.iterable" - ], + "lib": ["es2017", "es2019.array", "es2018.promise", "dom", "dom.iterable"], "baseUrl": ".", "paths": { "anki/*": ["../bazel-bin/ts/lib/*"],