anki/ts/editor/focusHandlers.ts

25 lines
833 B
TypeScript
Raw Normal View History

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
import type { EditingArea } from "./editingArea";
import { saveField } from "./changeTimer";
import { bridgeCommand } from "./lib";
export function onFocus(evt: FocusEvent): void {
const currentField = evt.currentTarget as EditingArea;
currentField.focusEditable();
bridgeCommand(`focus:${currentField.ord}`);
// @ts-expect-error
editorToolbar.enableButtons();
}
export function onBlur(evt: FocusEvent): void {
const previousFocus = evt.currentTarget as EditingArea;
const currentFieldUnchanged = previousFocus === document.activeElement;
saveField(previousFocus, currentFieldUnchanged ? "key" : "blur");
// @ts-expect-error
editorToolbar.disableButtons();
}