mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-16 20:11:08 +00:00
* fix terminal toolbar focus loss * restore focus after closing side panels * fix terminal side panel focus helper order
45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
type FocusTargetLike = {
|
|
tagName?: string | null;
|
|
isContentEditable?: boolean;
|
|
closest?: (selector: string) => unknown;
|
|
getAttribute?: (name: string) => string | null;
|
|
};
|
|
|
|
const EDITABLE_SELECTOR = 'input, textarea, select, [contenteditable=""], [contenteditable="true"], [role="textbox"]';
|
|
|
|
/**
|
|
* The terminal's top overlay sits above the xterm textarea. Pointer clicks on
|
|
* that layer should usually keep focus in the terminal so typing can continue.
|
|
* Only allow native focus changes for genuinely editable controls.
|
|
*/
|
|
export const shouldPreserveTerminalFocusOnMouseDown = (target: EventTarget | null): boolean => {
|
|
if (!target || typeof target !== "object") return true;
|
|
|
|
const candidate = target as FocusTargetLike;
|
|
const tagName = typeof candidate.tagName === "string"
|
|
? candidate.tagName.toUpperCase()
|
|
: "";
|
|
|
|
if (tagName === "INPUT" || tagName === "TEXTAREA" || tagName === "SELECT") {
|
|
return false;
|
|
}
|
|
|
|
if (candidate.isContentEditable) {
|
|
return false;
|
|
}
|
|
|
|
if (typeof candidate.getAttribute === "function") {
|
|
const contentEditable = candidate.getAttribute("contenteditable");
|
|
const role = candidate.getAttribute("role");
|
|
if (contentEditable === "" || contentEditable === "true" || role === "textbox") {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
if (typeof candidate.closest === "function" && candidate.closest(EDITABLE_SELECTOR)) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
};
|