From 1dcfc191bc02cb6ee197497ca4dd10a34752a578 Mon Sep 17 00:00:00 2001 From: Jorgen Nystad Date: Wed, 10 Aug 2022 11:18:15 +0200 Subject: [PATCH] Use previous selection when focus origins from key event Selection should be restored to its previous state when using tab to navigate a page with ProseMirror and other focusable elements with selection (inputs). This is similar to how textareas work. --- src/domchange.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/domchange.ts b/src/domchange.ts index 9ce05843..144bcb6e 100644 --- a/src/domchange.ts +++ b/src/domchange.ts @@ -80,7 +80,7 @@ export function readDOMChange(view: EditorView, from: number, to: number, typeOv if (from < 0) { let origin = view.input.lastSelectionTime > Date.now() - 50 ? view.input.lastSelectionOrigin : null let newSel = selectionFromDOM(view, origin) - if (newSel && !view.state.selection.eq(newSel)) { + if (origin && newSel && !view.state.selection.eq(newSel)) { let tr = view.state.tr.setSelection(newSel) if (origin == "pointer") tr.setMeta("pointer", true) else if (origin == "key") tr.scrollIntoView()