Current section

Files

Jump to
keyboard_shortcuts src keyboard_shortcuts.ffi.mjs
Raw

src/keyboard_shortcuts.ffi.mjs

// See https://developer.mozilla.org/en-US/docs/Web/API/Navigator/platform ;
// "navigator.platform should almost always be avoided in favor of feature
// detection. But there is one case where, among the options you could use,
// navigator.platform may be the least-bad option: When you need to show
// users advice about whether the modifier key for keyboard shortcuts is the
// ⌘ command key (found on Apple systems) rather than the ⌃ control key
// (on non-Apple systems)
//
const isMac =
(navigator.platform && navigator.platform.toLowerCase().startsWith("mac")) ||
(navigator.platform &&
navigator.platform.toLowerCase().startsWith("iphone")) ||
(navigator.userAgent && /mac/i.test(navigator.userAgent.toLowerCase())) ||
navigator.userAgent?.platform?.startsWith("mac");
export const window_add_event_listener = (name, handler) => {
window.addEventListener(name, handler);
};
export const prevent_default = (event) => {
event.preventDefault();
};
export const is_mac = () => {
return isMac;
};