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-07-03 01:14:59 +02:00
|
|
|
/* eslint
|
|
|
|
@typescript-eslint/no-non-null-assertion: "off",
|
|
|
|
*/
|
|
|
|
|
2021-07-05 18:15:03 +02:00
|
|
|
import { fieldFocused } 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";
|
2021-07-19 15:27:11 +02:00
|
|
|
import { getCurrentField } from "./helpers";
|
2021-02-08 19:45:42 +01:00
|
|
|
|
2021-08-06 17:21:47 +02:00
|
|
|
export function deferFocusDown(editingArea: EditingArea): void {
|
|
|
|
editingArea.focus();
|
|
|
|
editingArea.caretToEnd();
|
2021-07-03 01:00:52 +02:00
|
|
|
|
2021-08-06 17:21:47 +02:00
|
|
|
if (editingArea.getSelection().anchorNode === null) {
|
|
|
|
// selection is not inside editable after focusing
|
|
|
|
editingArea.caretToEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
bridgeCommand(`focus:${editingArea.ord}`);
|
2021-07-05 18:15:03 +02:00
|
|
|
fieldFocused.set(true);
|
2021-02-08 19:45:42 +01:00
|
|
|
}
|
|
|
|
|
2021-08-06 17:21:47 +02:00
|
|
|
export function saveFieldIfFieldChanged(
|
|
|
|
editingArea: EditingArea,
|
|
|
|
focusTo: Element | null
|
|
|
|
): void {
|
|
|
|
const fieldChanged =
|
|
|
|
editingArea !== getCurrentField() && !editingArea.contains(focusTo);
|
2021-02-08 19:45:42 +01:00
|
|
|
|
2021-08-06 17:21:47 +02:00
|
|
|
saveField(editingArea, fieldChanged ? "blur" : "key");
|
2021-07-05 18:15:03 +02:00
|
|
|
fieldFocused.set(false);
|
2021-08-06 17:21:47 +02:00
|
|
|
|
|
|
|
if (fieldChanged) {
|
|
|
|
editingArea.resetHandles();
|
|
|
|
}
|
2021-02-08 19:45:42 +01:00
|
|
|
}
|