2021-04-13 10:57:08 +02:00
|
|
|
// Copyright: Ankitects Pty Ltd and contributors
|
|
|
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
2021-02-09 04:38:04 +01:00
|
|
|
|
2021-04-27 23:08:47 +02:00
|
|
|
import { enableButtons, disableButtons } from "./toolbar";
|
2021-06-30 19:55:56 +02:00
|
|
|
import type { EditingArea } from "./editing-area";
|
2021-02-08 19:45:42 +01:00
|
|
|
|
2021-06-30 19:55:56 +02:00
|
|
|
import { saveField } from "./change-timer";
|
2021-02-08 19:45:42 +01:00
|
|
|
import { bridgeCommand } from "./lib";
|
|
|
|
|
|
|
|
export function onFocus(evt: FocusEvent): void {
|
|
|
|
const currentField = evt.currentTarget as EditingArea;
|
2021-06-17 22:02:06 +02:00
|
|
|
currentField.focus();
|
2021-07-03 01:00:52 +02:00
|
|
|
|
|
|
|
if (currentField.shadowRoot!.getSelection()!.anchorNode === null) {
|
|
|
|
// selection is not inside editable after focusing
|
|
|
|
currentField.caretToEnd();
|
|
|
|
}
|
|
|
|
|
2021-03-08 20:40:23 +01:00
|
|
|
bridgeCommand(`focus:${currentField.ord}`);
|
2021-04-19 23:51:09 +02:00
|
|
|
enableButtons();
|
2021-02-08 19:45:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export function onBlur(evt: FocusEvent): void {
|
2021-02-23 12:55:04 +01:00
|
|
|
const previousFocus = evt.currentTarget as EditingArea;
|
2021-03-08 20:40:23 +01:00
|
|
|
const currentFieldUnchanged = previousFocus === document.activeElement;
|
2021-02-08 19:45:42 +01:00
|
|
|
|
2021-03-08 20:40:23 +01:00
|
|
|
saveField(previousFocus, currentFieldUnchanged ? "key" : "blur");
|
2021-04-19 23:51:09 +02:00
|
|
|
disableButtons();
|
2021-02-08 19:45:42 +01:00
|
|
|
}
|