Use new focusEditingArea and blurEditingArea to delegate to editing area

This commit is contained in:
Henrik Giesel 2021-01-28 19:52:49 +01:00
parent aed38de228
commit 08a6f8f02f

View File

@ -19,7 +19,7 @@ String.prototype.format = function (...args: string[]): string {
}; };
function setFGButton(col: string): void { function setFGButton(col: string): void {
$("#forecolor")[0].style.backgroundColor = col; document.getElementById("forecolor").style.backgroundColor = col;
} }
function saveNow(keepFocus: boolean): void { function saveNow(keepFocus: boolean): void {
@ -33,7 +33,7 @@ function saveNow(keepFocus: boolean): void {
saveField("key"); saveField("key");
} else { } else {
// triggers onBlur, which saves // triggers onBlur, which saves
currentField.blur(); currentField.blurEditingArea();
} }
} }
@ -52,7 +52,7 @@ interface Selection {
function onKey(evt: KeyboardEvent): void { function onKey(evt: KeyboardEvent): void {
// esc clears focus, allowing dialog to close // esc clears focus, allowing dialog to close
if (evt.code === "Escape") { if (evt.code === "Escape") {
currentField.blur(); currentField.blurEditingArea();
return; return;
} }
@ -279,10 +279,11 @@ function onFocus(evt: FocusEvent): void {
} }
function focusField(n: number): void { function focusField(n: number): void {
if (n === null) { const field = document.getElementById(`f${n}`) as EditingContainer;
return;
if (field) {
field.focusEditingArea();
} }
$(`#f${n}`).focus();
} }
function focusIfField(x: number, y: number): boolean { function focusIfField(x: number, y: number): boolean {
@ -290,7 +291,7 @@ function focusIfField(x: number, y: number): boolean {
for (let i = 0; i < elements.length; i++) { for (let i = 0; i < elements.length; i++) {
let elem = elements[i] as EditingContainer; let elem = elements[i] as EditingContainer;
if (elem.classList.contains("field")) { if (elem.classList.contains("field")) {
elem.focus(); elem.focusEditingArea();
// the focus event may not fire if the window is not active, so make sure // the focus event may not fire if the window is not active, so make sure
// the current field is set // the current field is set
currentField = elem; currentField = elem;
@ -504,6 +505,14 @@ class EditingContainer extends HTMLDivElement {
return this.editingShadow.getSelection(); return this.editingShadow.getSelection();
} }
focusEditingArea(): void {
this.editingArea.focus();
}
blurEditingArea(): void {
this.editingArea.blur();
}
set fieldHTML(content: string) { set fieldHTML(content: string) {
this.editingArea.fieldHTML = content; this.editingArea.fieldHTML = content;
} }