MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / withPlatform

Function withPlatform

packages/app-core/src/lib/keymaps.test.ts:30–55  ·  view source on GitHub ↗
(platform: NodeJS.Platform, run: () => T)

Source from the content-addressed store, hash-verified

28}
29
30function withPlatform<T>(platform: NodeJS.Platform, run: () => T): T {
31 const host = globalThis as typeof globalThis & {
32 window?: { zen?: { platformSync?: () => NodeJS.Platform } }
33 }
34 const previousWindow = host.window
35 Object.defineProperty(host, 'window', {
36 value: {
37 ...(previousWindow ?? {}),
38 zen: { ...(previousWindow?.zen ?? {}), platformSync: () => platform }
39 },
40 configurable: true
41 })
42
43 try {
44 return run()
45 } finally {
46 if (previousWindow === undefined) {
47 Reflect.deleteProperty(host, 'window')
48 } else {
49 Object.defineProperty(host, 'window', {
50 value: previousWindow,
51 configurable: true
52 })
53 }
54 }
55}
56
57describe('shortcutBindingFromEvent', () => {
58 it('uses the typed character on Colemak (Cmd+P fires on the key that types p)', () => {

Callers 1

keymaps.test.tsFile · 0.85

Calls 1

runFunction · 0.70

Tested by

no test coverage detected