From d0c6f0d7ba89279279a9893631713194f6653e08 Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Fri, 3 Dec 2021 12:41:12 +0100 Subject: [PATCH] Fix focus lost after adding note if non-sticky (#1523) --- ts/editable/ContentEditable.svelte | 7 ++++++- ts/editor/CodeMirror.svelte | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ts/editable/ContentEditable.svelte b/ts/editable/ContentEditable.svelte index f37831bb2..8ae96d89c 100644 --- a/ts/editable/ContentEditable.svelte +++ b/ts/editable/ContentEditable.svelte @@ -7,6 +7,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html import { updateAllState } from "../components/WithState.svelte"; import { saveSelection, restoreSelection } from "../domlib/location"; import { on, preventDefault } from "../lib/events"; + import { caretToEnd } from "../lib/dom"; import { registerShortcut } from "../lib/shortcuts"; export let nodes: Writable; @@ -29,7 +30,11 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html "focus", () => { if (location) { - restoreSelection(editable, location); + try { + restoreSelection(editable, location); + } catch { + caretToEnd(editable); + } } }, { once: true }, diff --git a/ts/editor/CodeMirror.svelte b/ts/editor/CodeMirror.svelte index 5f91ced1a..b4dfd7b1e 100644 --- a/ts/editor/CodeMirror.svelte +++ b/ts/editor/CodeMirror.svelte @@ -57,6 +57,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html codeMirror.setSelections(ranges); } catch { ranges = null; + codeMirror.setCursor(codeMirror.lineCount(), 0); } } unsubscribe();