From 25def4f7413e0357d6315cd8404d8008709b914b Mon Sep 17 00:00:00 2001 From: Hikaru Y Date: Tue, 10 Jan 2023 07:51:09 +0900 Subject: [PATCH] Fix spaces not handled properly when entering text around MathJax (#2307) Regressed in #2288 https://forums.ankiweb.net/t/2-1-56-qt6-pressing-space-after-mathjax-inserts-nbsp-with-escaped/26147 --- ts/editable/frame-handle.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ts/editable/frame-handle.ts b/ts/editable/frame-handle.ts index b090166bd..ce42a03cb 100644 --- a/ts/editable/frame-handle.ts +++ b/ts/editable/frame-handle.ts @@ -95,7 +95,7 @@ function restoreHandleContent(mutations: MutationRecord[]): void { continue; } - referenceNode = target.parentElement.moveTextOutOfFrame(); + referenceNode = target.parentElement.moveTextOutOfFrame(target.data); } } @@ -200,9 +200,9 @@ export abstract class FrameHandle extends HTMLElement { abstract notifyMoveIn(offset: number): void; - moveTextOutOfFrame(): Text { + moveTextOutOfFrame(data: string): Text { const frameElement = this.parentElement! as FrameElement; - const cleaned = this.innerHTML.replace(spaceRegex, ""); + const cleaned = data.replace(spaceRegex, ""); const text = new Text(cleaned); if (this.placement === "beforebegin") { @@ -223,7 +223,9 @@ export abstract class FrameHandle extends HTMLElement { subscribeToCompositionEvent(): void { this.unsubscribe = isComposing.subscribe((composing) => { if (!composing) { - placeCaretAfter(this.moveTextOutOfFrame()); + if (this.firstChild && nodeIsText(this.firstChild)) { + placeCaretAfter(this.moveTextOutOfFrame(this.firstChild.data)); + } this.unsubscribeToCompositionEvent(); } });