From 2d4de33cf3160342c4c704c294e643c3e11071b1 Mon Sep 17 00:00:00 2001 From: Lee Doughty <32392044+leedoughty@users.noreply.github.com> Date: Mon, 1 Dec 2025 18:54:46 +0000 Subject: [PATCH] Ensure trailing spaces are placed outside cloze deletions (#4446) --- ts/lib/tslib/wrap.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ts/lib/tslib/wrap.ts b/ts/lib/tslib/wrap.ts index 39b10e9d1..e22c3e6d8 100644 --- a/ts/lib/tslib/wrap.ts +++ b/ts/lib/tslib/wrap.ts @@ -4,7 +4,12 @@ import { getRange, getSelection } from "./cross-browser"; function wrappedExceptForWhitespace(text: string, front: string, back: string): string { - const match = text.match(/^(\s*)([^]*?)(\s*)$/)!; + const normalizedText = text + .replace(/ /g, " ") + .replace(/ /g, " ") + .replace(/\u00A0/g, " "); + + const match = normalizedText.match(/^(\s*)([^]*?)(\s*)$/)!; return match[1] + front + match[2] + back + match[3]; }