mirror of
https://github.com/DustinBrett/daedalOS.git
synced 2025-12-06 00:20:05 +01:00
Safer query selectors
This commit is contained in:
parent
e99c948b47
commit
296d41874f
|
|
@ -276,11 +276,16 @@ const useFileKeyboardShortcuts = (
|
|||
if (focusOnEntry) {
|
||||
blurEntry();
|
||||
focusEntry(focusOnEntry);
|
||||
fileManagerRef.current
|
||||
?.querySelector(
|
||||
`button[aria-label='${focusOnEntry.replace(SHORTCUT_EXTENSION, "")}']`
|
||||
)
|
||||
?.scrollIntoView();
|
||||
|
||||
try {
|
||||
fileManagerRef.current
|
||||
?.querySelector(
|
||||
`button[aria-label='${CSS.escape(focusOnEntry.replace(SHORTCUT_EXTENSION, ""))}']`
|
||||
)
|
||||
?.scrollIntoView();
|
||||
} catch {
|
||||
// Ignore error getting/scrolling element
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -134,14 +134,18 @@ const useFocusableEntries = (
|
|||
);
|
||||
|
||||
if (lines.length > 1) {
|
||||
const element = fileManagerRef.current?.querySelector(
|
||||
`[aria-label='${textLabel}'] figcaption`
|
||||
);
|
||||
try {
|
||||
const element = fileManagerRef.current?.querySelector(
|
||||
`[aria-label='${CSS.escape(textLabel)}'] figcaption`
|
||||
);
|
||||
|
||||
if (element) {
|
||||
$labelHeightOffset =
|
||||
(lines.length - 1) *
|
||||
Number.parseFloat(window.getComputedStyle(element).lineHeight);
|
||||
if (element) {
|
||||
$labelHeightOffset =
|
||||
(lines.length - 1) *
|
||||
Number.parseFloat(window.getComputedStyle(element).lineHeight);
|
||||
}
|
||||
} catch {
|
||||
// Ignore error getting element
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,10 +22,17 @@ declare global {
|
|||
}
|
||||
}
|
||||
|
||||
export const getNavButtonByTitle = (title: string): HTMLButtonElement | null =>
|
||||
document.querySelector(
|
||||
`main > nav > div[title='${title}']`
|
||||
) as HTMLButtonElement;
|
||||
export const getNavButtonByTitle = (
|
||||
title: string
|
||||
): HTMLButtonElement | undefined => {
|
||||
try {
|
||||
return document.querySelector(
|
||||
`main > nav > div[title='${CSS.escape(title)}']`
|
||||
) as HTMLButtonElement;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
let metaDown = false;
|
||||
let metaComboUsed = false;
|
||||
|
|
|
|||
|
|
@ -510,11 +510,17 @@ export const updateIconPositionsIfEmpty = (
|
|||
const entryUrl = join(url, entry);
|
||||
|
||||
if (!iconPositions[entryUrl]) {
|
||||
const gridEntry = [...gridElement.children].find((element) =>
|
||||
element.querySelector(
|
||||
`button[aria-label="${entry.replace(SHORTCUT_EXTENSION, "")}"]`
|
||||
)
|
||||
);
|
||||
let gridEntry: Element | undefined;
|
||||
|
||||
try {
|
||||
gridEntry = [...gridElement.children].find((element) =>
|
||||
element.querySelector(
|
||||
`button[aria-label="${CSS.escape(entry.replace(SHORTCUT_EXTENSION, ""))}"]`
|
||||
)
|
||||
);
|
||||
} catch {
|
||||
// Ignore error getting element
|
||||
}
|
||||
|
||||
if (gridEntry instanceof HTMLElement) {
|
||||
const { x, y, height, width } = gridEntry.getBoundingClientRect();
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user