From d11d66ee79cc1a32db83bd3ac52809dd203ee66a Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Sat, 3 Jul 2021 01:00:52 +0200 Subject: [PATCH 1/2] Move selection into editable, if it's not there after focus --- ts/editor/focus-handlers.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ts/editor/focus-handlers.ts b/ts/editor/focus-handlers.ts index e72595d38..ee80a92ff 100644 --- a/ts/editor/focus-handlers.ts +++ b/ts/editor/focus-handlers.ts @@ -10,6 +10,12 @@ import { bridgeCommand } from "./lib"; export function onFocus(evt: FocusEvent): void { const currentField = evt.currentTarget as EditingArea; currentField.focus(); + + if (currentField.shadowRoot!.getSelection()!.anchorNode === null) { + // selection is not inside editable after focusing + currentField.caretToEnd(); + } + bridgeCommand(`focus:${currentField.ord}`); enableButtons(); } From f0e870f1ae31aaf707690f37ad8150475003c891 Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Sat, 3 Jul 2021 01:14:59 +0200 Subject: [PATCH 2/2] Allow non-null assertion in focus-handlers --- ts/editor/focus-handlers.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ts/editor/focus-handlers.ts b/ts/editor/focus-handlers.ts index ee80a92ff..7a03c6b7d 100644 --- a/ts/editor/focus-handlers.ts +++ b/ts/editor/focus-handlers.ts @@ -1,6 +1,10 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +/* eslint +@typescript-eslint/no-non-null-assertion: "off", + */ + import { enableButtons, disableButtons } from "./toolbar"; import type { EditingArea } from "./editing-area";