Use registerShortcut in inputHandlers + Avoid focus on color picker

This commit is contained in:
Henrik Giesel 2021-04-22 15:02:41 +02:00
parent 8ca40369a7
commit f6ef4d43cb
2 changed files with 17 additions and 15 deletions

View File

@ -74,5 +74,5 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
{title} {title}
on:click={delegateToInput} on:click={delegateToInput}
on:mousedown|preventDefault> on:mousedown|preventDefault>
<input bind:this={inputRef} type="color" on:change={onChange} /> <input tabindex="-1" bind:this={inputRef} type="color" on:change={onChange} />
</button> </button>

View File

@ -5,6 +5,7 @@ import { updateActiveButtons } from "editor-toolbar";
import { EditingArea } from "./editingArea"; import { EditingArea } from "./editingArea";
import { caretToEnd, nodeIsElement, getBlockElement } from "./helpers"; import { caretToEnd, nodeIsElement, getBlockElement } from "./helpers";
import { triggerChangeTimer } from "./changeTimer"; import { triggerChangeTimer } from "./changeTimer";
import { registerShortcut } from "anki/shortcuts";
export function onInput(event: Event): void { export function onInput(event: Event): void {
// make sure IME changes get saved // make sure IME changes get saved
@ -51,21 +52,22 @@ export function onKey(evt: KeyboardEvent): void {
triggerChangeTimer(currentField); triggerChangeTimer(currentField);
} }
globalThis.addEventListener("keydown", (evt: KeyboardEvent) => { function updateFocus(evt: FocusEvent) {
if (evt.code === "Tab") {
globalThis.addEventListener(
"focusin",
(evt: FocusEvent) => {
const newFocusTarget = evt.target; const newFocusTarget = evt.target;
if (newFocusTarget instanceof EditingArea) { if (newFocusTarget instanceof EditingArea) {
caretToEnd(newFocusTarget); caretToEnd(newFocusTarget);
updateActiveButtons(); updateActiveButtons();
} }
}, }
{ once: true }
); registerShortcut(
} () => document.addEventListener("focusin", updateFocus, { once: true }),
}); "Tab"
);
registerShortcut(
() => document.addEventListener("focusin", updateFocus, { once: true }),
"Shift+Tab"
);
export function onKeyUp(evt: KeyboardEvent): void { export function onKeyUp(evt: KeyboardEvent): void {
const currentField = evt.currentTarget as EditingArea; const currentField = evt.currentTarget as EditingArea;