Переглянути джерело

fix: clear keybindings after exit whiteboard

Peng Xiao 3 роки тому
батько
коміт
878b4e7d9d

+ 14 - 1
tldraw/packages/core/src/lib/TLApp/TLApp.ts

@@ -184,8 +184,21 @@ export class TLApp<
     // eslint-disable-next-line @typescript-eslint/ban-ts-comment
     // @ts-ignore
     const shortcuts = (this.constructor['shortcuts'] || []) as TLShortcut<S, K>[]
+    const childrenShortcuts = Array.from(this.children.values())
+      // @ts-expect-error ???
+      .filter(c => c.constructor['shortcut'])
+      .map(child => {
+        return {
+          // @ts-expect-error ???
+          keys: child.constructor['shortcut'] as string | string[],
+          fn: (_: any, __: any, e: Event) => {
+            this.transition(child.id)
+            e.stopPropagation()
+          },
+        }
+      })
     this._disposables.push(
-      ...[...ownShortcuts, ...shortcuts].map(({ keys, fn }) => {
+      ...[...ownShortcuts, ...shortcuts, ...childrenShortcuts].map(({ keys, fn }) => {
         return KeyUtils.registerShortcut(keys, e => {
           fn(this, this, e)
         })

+ 0 - 10
tldraw/packages/core/src/lib/TLState.ts

@@ -417,16 +417,6 @@ export abstract class TLState<
       }
     }
 
-    // eslint-disable-next-line @typescript-eslint/ban-ts-comment
-    // @ts-ignore
-    const shortcut = this.constructor['shortcut'] as string
-    if (shortcut) {
-      KeyUtils.registerShortcut(shortcut, e => {
-        this.parent.transition(this.id)
-        e.stopPropagation()
-      })
-    }
-
     // eslint-disable-next-line @typescript-eslint/ban-ts-comment
     // @ts-ignore
     const shortcuts = this.constructor['shortcuts'] as TLShortcut<S, K>[]

+ 1 - 1
tldraw/packages/core/src/utils/KeyUtils.ts

@@ -26,7 +26,7 @@ export class KeyUtils {
     }
     Mousetrap.bind(keys, fn, 'keydown')
     return () => {
-      Mousetrap.unbind(keys)
+      Mousetrap.unbind(keys, 'keydown')
     }
   }
 }