18 lines
534 B
TypeScript
18 lines
534 B
TypeScript
const EDITABLE_SELECTOR = [
|
|
"input",
|
|
"textarea",
|
|
"select",
|
|
'[contenteditable=""]',
|
|
'[contenteditable="true"]',
|
|
'[contenteditable="plaintext-only"]',
|
|
'[role="textbox"]',
|
|
].join(",");
|
|
|
|
/**
|
|
* Whether a text-editing element owns the keyboard. Shortcuts that share
|
|
* their chord with native editing (mod+z) must yield when this is true.
|
|
*/
|
|
export function isEditableFocused(target: EventTarget | null = document.activeElement): boolean {
|
|
return target instanceof Element && target.closest(EDITABLE_SELECTOR) !== null;
|
|
}
|