mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 18:30:09 +00:00
fixes and refactoring...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
f0a032979c
commit
e63041c570
@ -629,6 +629,8 @@ var KeyboardActions = actions.Actions({
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
}],
|
}],
|
||||||
|
// XXX NEXT/DROP handling needs more testing...
|
||||||
|
// XXX should dropped key handling be done here or in .keyboard.keys()???
|
||||||
getKeysForAction: ['- Interface/',
|
getKeysForAction: ['- Interface/',
|
||||||
core.doc`Get normalized, flat set of actions and keys that trigger them...
|
core.doc`Get normalized, flat set of actions and keys that trigger them...
|
||||||
|
|
||||||
@ -650,6 +652,8 @@ var KeyboardActions = actions.Actions({
|
|||||||
function(actions, modes){
|
function(actions, modes){
|
||||||
var that = this
|
var that = this
|
||||||
var res = {}
|
var res = {}
|
||||||
|
var kb = this.keyboard
|
||||||
|
var keybindings = this.keybindings
|
||||||
|
|
||||||
// Normalize handler to one of the following forms:
|
// Normalize handler to one of the following forms:
|
||||||
// - "<action>"
|
// - "<action>"
|
||||||
@ -679,17 +683,17 @@ var KeyboardActions = actions.Actions({
|
|||||||
actions.map(normalizeHandler)
|
actions.map(normalizeHandler)
|
||||||
: actions
|
: actions
|
||||||
|
|
||||||
modes = modes || this.keyboard.modes()
|
modes = modes || kb.modes()
|
||||||
modes = modes == '*' ? Object.keys(this.keybindings)
|
modes = modes == '*' ? Object.keys(keybindings)
|
||||||
: modes instanceof Array ? modes
|
: modes instanceof Array ? modes
|
||||||
: [modes]
|
: [modes]
|
||||||
|
|
||||||
var keys = this.keyboard.keys()
|
var keys = kb.keys('?')
|
||||||
|
|
||||||
// build the result -- flatten the key list...
|
// build the result -- flatten the key list...
|
||||||
modes.forEach(function(mode){
|
modes.forEach(function(mode){
|
||||||
mode in keys
|
if(mode in keys){
|
||||||
&& Object.keys(keys[mode])
|
Object.keys(keys[mode])
|
||||||
// parse the actions...
|
// parse the actions...
|
||||||
.forEach(function(action){
|
.forEach(function(action){
|
||||||
var t = normalizeHandler(action)
|
var t = normalizeHandler(action)
|
||||||
@ -697,6 +701,7 @@ var KeyboardActions = actions.Actions({
|
|||||||
res[t] = (res[t] || []).concat(keys[mode][action])
|
res[t] = (res[t] || []).concat(keys[mode][action])
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|||||||
@ -576,6 +576,10 @@ var KeyboardPrototype = {
|
|||||||
// .keys('*')
|
// .keys('*')
|
||||||
// -> keys
|
// -> keys
|
||||||
//
|
//
|
||||||
|
// List only applicable handlers...
|
||||||
|
// .keys('?')
|
||||||
|
// -> keys
|
||||||
|
//
|
||||||
// List keys for handler...
|
// List keys for handler...
|
||||||
// .keys(handler)
|
// .keys(handler)
|
||||||
// -> keys
|
// -> keys
|
||||||
@ -603,6 +607,9 @@ var KeyboardPrototype = {
|
|||||||
// NOTE: this will also return non-key aliases...
|
// NOTE: this will also return non-key aliases...
|
||||||
// NOTE: to match several compatible handlers, pass a list of handlers,
|
// NOTE: to match several compatible handlers, pass a list of handlers,
|
||||||
// the result for each will be merged into one common list.
|
// the result for each will be merged into one common list.
|
||||||
|
//
|
||||||
|
// XXX this and .handler(..) in part repeat handling dropped keys,
|
||||||
|
// can we unify this???
|
||||||
keys: function(handler){
|
keys: function(handler){
|
||||||
var that = this
|
var that = this
|
||||||
var res = {}
|
var res = {}
|
||||||
@ -613,7 +620,7 @@ var KeyboardPrototype = {
|
|||||||
|
|
||||||
handler = arguments.length > 1 ? [].slice.call(arguments)
|
handler = arguments.length > 1 ? [].slice.call(arguments)
|
||||||
: handler == null ? '*'
|
: handler == null ? '*'
|
||||||
: handler == '*' || handler instanceof Function ? handler
|
: handler == '*' || handler == '?' || handler instanceof Function ? handler
|
||||||
: handler instanceof Array ? handler
|
: handler instanceof Array ? handler
|
||||||
: [handler]
|
: [handler]
|
||||||
|
|
||||||
@ -632,9 +639,22 @@ var KeyboardPrototype = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var modes = handler == '?' ? this.modes() : '*'
|
||||||
|
var drop = []
|
||||||
|
var next = []
|
||||||
|
|
||||||
Object.keys(keyboard).forEach(function(mode){
|
Object.keys(keyboard).forEach(function(mode){
|
||||||
|
// skip non-applicable modes...
|
||||||
|
if(modes != '*' && modes.indexOf(mode) < 0){
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var bindings = keyboard[mode]
|
var bindings = keyboard[mode]
|
||||||
|
|
||||||
|
if(handler == '?'){
|
||||||
|
next = next.concat(bindings.NEXT || [])
|
||||||
|
}
|
||||||
|
|
||||||
// build a reverse index...
|
// build a reverse index...
|
||||||
var rev = {}
|
var rev = {}
|
||||||
// NOTE: this will not work for handlers that are not strings
|
// NOTE: this will not work for handlers that are not strings
|
||||||
@ -652,7 +672,8 @@ var KeyboardPrototype = {
|
|||||||
})
|
})
|
||||||
|
|
||||||
var seen = []
|
var seen = []
|
||||||
var handlers = handler == '*' ? Object.keys(rev)
|
var handlers = handler == '*' || handler == '?' ?
|
||||||
|
Object.keys(rev)
|
||||||
: handler instanceof Function ?
|
: handler instanceof Function ?
|
||||||
Object.keys(rev)
|
Object.keys(rev)
|
||||||
.filter(handler)
|
.filter(handler)
|
||||||
@ -660,6 +681,19 @@ var KeyboardPrototype = {
|
|||||||
|
|
||||||
handlers
|
handlers
|
||||||
.forEach(function(h){
|
.forEach(function(h){
|
||||||
|
if(handler == '?'&& h == 'NEXT'){
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var keys = (rev[h] || []).map(that.normalizeKey.bind(that))
|
||||||
|
|
||||||
|
if(handler == '?' && h == 'DROP'){
|
||||||
|
drop = drop == '*' ? '*' : drop.concat(keys)
|
||||||
|
next = next
|
||||||
|
.filter(function(k){ return keys.indexOf(k) >= 0 })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var keys = (rev[h] || []).map(that.normalizeKey.bind(that))
|
var keys = (rev[h] || []).map(that.normalizeKey.bind(that))
|
||||||
|
|
||||||
// find all reachable keys from the ones we just found in reverse...
|
// find all reachable keys from the ones we just found in reverse...
|
||||||
@ -679,11 +713,29 @@ var KeyboardPrototype = {
|
|||||||
seen.push(seen)
|
seen.push(seen)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if(handler == '?'){
|
||||||
|
keys = keys
|
||||||
|
.filter(function(key){
|
||||||
|
var k = that.splitKey(key)
|
||||||
|
return next.indexOf(key) >= 0
|
||||||
|
|| next.indexOf(k) >= 0
|
||||||
|
|| (drop != '*'
|
||||||
|
&& drop.indexOf(key) < 0
|
||||||
|
&& drop.indexOf(k) < 0)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if(keys.length > 0){
|
if(keys.length > 0){
|
||||||
var m = res[mode] = res[mode] || {}
|
var m = res[mode] = res[mode] || {}
|
||||||
m[h] = keys
|
m[h] = keys
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if(handler == '?'){
|
||||||
|
drop = drop == '*' || bindings.drop == '*' ?
|
||||||
|
'*'
|
||||||
|
: drop.concat(bindings.drop || [])
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return res
|
return res
|
||||||
@ -771,6 +823,9 @@ var KeyboardPrototype = {
|
|||||||
// - search for key code without modifiers
|
// - search for key code without modifiers
|
||||||
// - if an alias is found it is first checked with and then
|
// - if an alias is found it is first checked with and then
|
||||||
// without modifiers
|
// without modifiers
|
||||||
|
//
|
||||||
|
// XXX this and .keys('?') in part repeat handling dropped keys,
|
||||||
|
// can we unify this???
|
||||||
handler: function(mode, key, handler){
|
handler: function(mode, key, handler){
|
||||||
var that = this
|
var that = this
|
||||||
var keyboard = this.keyboard
|
var keyboard = this.keyboard
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user