fix: clear keybindings after exit whiteboard

This commit is contained in:
Peng Xiao
2022-08-10 23:46:59 +08:00
parent da880becae
commit 878b4e7d9d
3 changed files with 15 additions and 12 deletions

View File

@@ -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)
})

View File

@@ -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>[]

View File

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