From 52438fe4c9ae074176f063bf2fff88afb5416809 Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Fri, 13 May 2022 05:02:03 +0200 Subject: [PATCH] Move focus into HTML editor when shown (#1861) * Move focus into input field, when input is shown * Change trapFocusOut to move focus into available inputs - This means that e.g. closing the HTML editor with focus in it will focus the visual editor in turn * Prevent Control+A unselecting tag editor when no tags exist --- ts/editor/EditingArea.svelte | 51 ++++++++++++++++--- ts/editor/NoteEditor.svelte | 22 +++++++- ts/editor/PlainTextBadge.svelte | 5 +- ts/editor/RichTextBadge.svelte | 8 ++- .../plain-text-input/PlainTextInput.svelte | 18 +++++-- .../rich-text-input/RichTextInput.svelte | 17 ++++++- ts/editor/tag-editor/TagEditor.svelte | 18 ++++++- ts/editor/tag-editor/TagInput.svelte | 6 +-- 8 files changed, 120 insertions(+), 25 deletions(-) diff --git a/ts/editor/EditingArea.svelte b/ts/editor/EditingArea.svelte index be5654a79..8aa156bed 100644 --- a/ts/editor/EditingArea.svelte +++ b/ts/editor/EditingArea.svelte @@ -7,7 +7,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html import contextProperty from "../sveltelib/context-property"; - export interface EditingInputAPI { + export interface FocusableInputAPI { readonly name: string; focusable: boolean; /** @@ -22,6 +22,16 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html refocus(): void; } + export interface EditingInputAPI extends FocusableInputAPI { + /** + * Check whether blurred target belongs to an editing input. + * The editing area can then restore focus to this input. + * + * @returns An editing input api that is associated with the event target. + */ + getInputAPI(target: EventTarget): Promise; + } + export interface EditingAreaAPI { content: Writable; editingInputs: Writable; @@ -36,7 +46,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html