From d598652caaaf4f1e0a8cf2538b5f6c17a36f363e Mon Sep 17 00:00:00 2001 From: Rain-Zheng <67583056+Rain-Zheng@users.noreply.github.com> Date: Wed, 17 Apr 2024 00:58:09 +0800 Subject: [PATCH] restore selection (#2577) --- .../lib/edit/EditPlugin.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts b/packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts index 73a994c473b..bd3b9f043ce 100644 --- a/packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts +++ b/packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts @@ -141,6 +141,16 @@ export class EditPlugin implements EditorPlugin { if (handled) { rawEvent.preventDefault(); + + // Restore the selection to avoid the cursor jump issue + // See: https://issues.chromium.org/issues/330596261 + const selection = editor.getDOMSelection(); + const doc = this.editor?.getDocument(); + doc?.defaultView?.requestAnimationFrame(() => { + if (this.editor) { + this.editor.setDOMSelection(selection); + } + }); } } }