修复多选机制问题
This commit is contained in:
@@ -1,41 +1,38 @@
|
||||
import mousetrap from 'mousetrap'
|
||||
|
||||
let eventHub
|
||||
|
||||
const bindKeys = [
|
||||
'shift',
|
||||
'mod',
|
||||
'mod+a',
|
||||
]
|
||||
|
||||
const bindKey = () => {
|
||||
mousetrap.reset()
|
||||
mousetrap.bind('shift', (event, combo) => {
|
||||
eventHub.$emit('key_shift_down', { event, combo })
|
||||
return false
|
||||
}, 'keydown')
|
||||
mousetrap.bind('shift', (event, combo) => {
|
||||
eventHub.$emit('key_shift_up', { event, combo })
|
||||
return false
|
||||
}, 'keyup')
|
||||
mousetrap.bind('mod', (event, combo) => {
|
||||
eventHub.$emit('key_mod_down', { event, combo })
|
||||
return false
|
||||
}, 'keydown')
|
||||
mousetrap.bind('mod', (event, combo) => {
|
||||
eventHub.$emit('key_mod_up', { event, combo })
|
||||
return false
|
||||
}, 'keyup')
|
||||
mousetrap.bind('mod+a', (event, combo) => {
|
||||
eventHub.$emit('key_mod+a_down', { event, combo })
|
||||
return false
|
||||
}, 'keydown')
|
||||
mousetrap.bind('mod+a', (event, combo) => {
|
||||
eventHub.$emit('key_mod+a_up', { event, combo })
|
||||
return false
|
||||
}, 'keyup')
|
||||
for (const key of bindKeys) {
|
||||
mousetrap.bind(key, (event, combo) => {
|
||||
eventHub.$emit(`key_${key}_down`, { event, combo })
|
||||
return false
|
||||
}, 'keydown')
|
||||
mousetrap.bind(key, (event, combo) => {
|
||||
eventHub.$emit(`key_${key}_up`, { event, combo })
|
||||
return false
|
||||
}, 'keyup')
|
||||
}
|
||||
}
|
||||
|
||||
const unbindKey = () => {
|
||||
mousetrap.unbind('shift', 'keydown')
|
||||
mousetrap.unbind('shift', 'keyup')
|
||||
mousetrap.unbind('mod', 'keydown')
|
||||
mousetrap.unbind('mod', 'keyup')
|
||||
mousetrap.unbind('mod+a', 'keydown')
|
||||
mousetrap.unbind('mod+a', 'keyup')
|
||||
for (const key of bindKeys) {
|
||||
mousetrap.unbind(key, 'keydown')
|
||||
mousetrap.unbind(key, 'keyup')
|
||||
}
|
||||
}
|
||||
|
||||
const handleFocus = () => {
|
||||
for (const key of bindKeys) {
|
||||
eventHub.$emit(`key_${key}_up`, { combo: key })
|
||||
}
|
||||
}
|
||||
|
||||
export default () => {
|
||||
@@ -43,4 +40,5 @@ export default () => {
|
||||
|
||||
eventHub.$on('bindKey', bindKey)
|
||||
eventHub.$on('unbindKey', unbindKey)
|
||||
eventHub.$on('focus', handleFocus)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user