Skip to content

Commit

Permalink
fix: #486 naming conflict for argument isMac in the type definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
josdejong committed Sep 27, 2024
1 parent 4263d6f commit 9fac7a3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/lib/components/modals/CopyPasteModal.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<svelte:options immutable={true} />

<script lang="ts">
import { isMac } from '$lib/utils/navigatorUtils.js'
import { isMacDevice } from '$lib/utils/navigatorUtils.js'
import Header from './Header.svelte'
import Modal from './Modal.svelte'
export let onClose: () => void
const ctrl = isMac() ? '' : 'Ctrl'
const ctrl = isMacDevice() ? '' : 'Ctrl'
</script>

<Modal {onClose} className="jse-copy-paste">
Expand Down
10 changes: 7 additions & 3 deletions src/lib/utils/keyBindings.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// inspiration: https://github.com/andrepolischuk/keycomb

import { isMac as _isMac } from './navigatorUtils.js'
import { isMacDevice } from './navigatorUtils.js'

// KeyComboEvent is a subset of KeyboardEvent
export interface KeyComboEvent {
Expand All @@ -19,7 +19,11 @@ export interface KeyComboEvent {
* meta keys "Ctrl" ("Command" on Mac), and "Alt" ("Alt" or "Option" on Mac)
* So pressing "Command" and "A"on Mac will return "Ctrl+A"
*/
export function keyComboFromEvent(event: KeyComboEvent, separator = '+', isMac = _isMac): string {
export function keyComboFromEvent(
event: KeyComboEvent,
separator = '+',
isMac = isMacDevice
): string {
const combi = []

if (isCtrlKeyDown(event, isMac)) {
Expand Down Expand Up @@ -48,7 +52,7 @@ export function keyComboFromEvent(event: KeyComboEvent, separator = '+', isMac =
*/
export function isCtrlKeyDown(
event: { ctrlKey: boolean; metaKey: boolean },
isMac = _isMac
isMac = isMacDevice
): boolean {
// metaKey is the Command key ⌘ on a Mac (but the Windows Key ⊞ on Windows)
return event.ctrlKey || (event.metaKey && isMac())
Expand Down
2 changes: 1 addition & 1 deletion src/lib/utils/navigatorUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ declare global {
}
}

export function isMac() {
export function isMacDevice() {
return (
typeof navigator !== 'undefined' &&
(navigator?.platform?.toUpperCase().includes('MAC') ??
Expand Down

0 comments on commit 9fac7a3

Please sign in to comment.