fix: ctrl+a does not work on Windows in code block (#5692)
This commit is contained in:
52
shared/utils/browser.ts
Normal file
52
shared/utils/browser.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
const SSR = typeof window === "undefined";
|
||||
|
||||
/**
|
||||
* Returns true if the client is a touch device.
|
||||
*/
|
||||
export function isTouchDevice(): boolean {
|
||||
if (SSR) {
|
||||
return false;
|
||||
}
|
||||
return window.matchMedia?.("(hover: none) and (pointer: coarse)")?.matches;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the client is running on a Mac.
|
||||
*/
|
||||
export function isMac(): boolean {
|
||||
if (SSR) {
|
||||
return false;
|
||||
}
|
||||
return window.navigator.platform === "MacIntel";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the client is running on Windows.
|
||||
*/
|
||||
export function isWindows(): boolean {
|
||||
if (SSR) {
|
||||
return false;
|
||||
}
|
||||
return window.navigator.platform === "Win32";
|
||||
}
|
||||
|
||||
let supportsPassive = false;
|
||||
|
||||
try {
|
||||
const opts = Object.defineProperty({}, "passive", {
|
||||
get() {
|
||||
supportsPassive = true;
|
||||
},
|
||||
});
|
||||
// @ts-expect-error ts-migrate(2769) testPassive is not a real event
|
||||
window.addEventListener("testPassive", null, opts);
|
||||
// @ts-expect-error ts-migrate(2769) testPassive is not a real event
|
||||
window.removeEventListener("testPassive", null, opts);
|
||||
} catch (e) {
|
||||
// No-op
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the client supports passive event listeners
|
||||
*/
|
||||
export const supportsPassiveListener = supportsPassive;
|
||||
Reference in New Issue
Block a user