From 0c81bbce04c1998b92ed0c1fa08d1cd5d13f3f56 Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Sat, 5 Feb 2022 06:58:31 +0100 Subject: [PATCH] Fix field not restored if active (#1639) * Fix field not being restored after Undo, if field also has focus * Execute moveCaretToEnd after undoing a change - Otherwise the caret might be placed in seemingly random positions * Fix wording of comments * Remove autofocus functionality of EditingArea - instead await a tick in focusField - We used the autofocus prop for the initial focus setting when opening the editor. However it seems that awaiting tick in focusField also does the trick. --- ts/editor/EditingArea.svelte | 22 +++++++++---------- ts/editor/EditorField.svelte | 2 -- ts/editor/NoteEditor.svelte | 21 +++++++++++------- .../plain-text-input/PlainTextInput.svelte | 9 ++++---- .../rich-text-input/RichTextInput.svelte | 2 +- 5 files changed, 30 insertions(+), 26 deletions(-) diff --git a/ts/editor/EditingArea.svelte b/ts/editor/EditingArea.svelte index 6dc95ea0a..be5654a79 100644 --- a/ts/editor/EditingArea.svelte +++ b/ts/editor/EditingArea.svelte @@ -9,10 +9,17 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html export interface EditingInputAPI { readonly name: string; - focus(): void; - refocus(): void; focusable: boolean; - moveCaretToEnd(): void; + /** + * The reaction to a user-initiated focus, e.g. by clicking on the + * editor label, or pressing Tab. + */ + focus(): void; + /** + * Behaves similar to a refresh, e.g. sync with content, put the caret + * into a neutral position, and/or clear selections. + */ + refocus(): void; } export interface EditingAreaAPI { @@ -29,7 +36,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html diff --git a/ts/editor/EditorField.svelte b/ts/editor/EditorField.svelte index 23fa633b7..5915b9c25 100644 --- a/ts/editor/EditorField.svelte +++ b/ts/editor/EditorField.svelte @@ -44,7 +44,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html export let content: Writable; export let field: FieldData; - export let autofocus = false; const directionStore = writable<"ltr" | "rtl">(); setContext(directionKey, directionStore); @@ -88,7 +87,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html