notes and cleanup...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-04-22 06:36:30 +03:00
parent b2c9a5cb34
commit d0f0894da2

View File

@ -777,27 +777,29 @@ var KeyboardPrototype = {
.map(function(s){ return shift_key.join(s) }) .map(function(s){ return shift_key.join(s) })
: []) : [])
.unique() } .unique() }
var normalize = this.normalizeKey // NOTE: the generated list is in the following order:
// - longest chain first
// - shifted keys first
// - modifiers are skipped in order, left to right
// XXX carefully revise key search order...
var keyCombinations = function(key, shift_key){ var keyCombinations = function(key, shift_key){
if(key.length <= 1){ if(key.length <= 1){
return key return key
} }
// generate recursively, breadth first...
var _combinations = function(level, res){ var _combinations = function(level, res){
var next = [] var next = []
level level
.map(function(elem){ .map(function(elem){
var c = normalize(elem) var c = elem.join('+++')
c = typeof(c) == typeof('str') ? c : c.join('+++')
res.indexOf(c) < 0 res.indexOf(c) < 0
&& res.push(c) && res.push(c)
&& elem && elem
//.reverse()
.slice(0, -1) .slice(0, -1)
.map(function(_, i){ .map(function(_, i){
var s = elem.slice() var s = elem.slice()
s.splice(i, 1) s.splice(i, 1)
s.length > 0 s.length > 0
//&& next.push(s.reverse())
&& next.push(s) && next.push(s)
}) })
}) })
@ -805,11 +807,11 @@ var KeyboardPrototype = {
&& _combinations(next, res) && _combinations(next, res)
return res return res
} }
return _combinations(shift_key ? [key, shift_key] : [key], []) return _combinations(shift_key && shift_key.length > 0 ?
// XXX is there a better way??? [key, shift_key]
//.map(function(e){ return e.split(/\+\+\+/g).concat(key.slice(-1)) }) : [key], [])
.map(function(e){ return joinKeys(e.split(/\+\+\+/g)) }) .map(function(e){ return joinKeys(e.split(/\+\+\+/g)) })
.reduce(function(a, b){ return a.concat(b) }, []) .reduce(function(a, b){ return a.concat(b) }, [])
} }
var walkAliases = function(bindings, handler, modifiers){ var walkAliases = function(bindings, handler, modifiers){
var seen = [] var seen = []
@ -845,6 +847,8 @@ var KeyboardPrototype = {
//var keys = joinKeys(key, shift_key).unique() //var keys = joinKeys(key, shift_key).unique()
var keys = keyCombinations(key, shift_key) var keys = keyCombinations(key, shift_key)
console.log(keys)
// get modes... // get modes...
var modes = mode == '*' ? Object.keys(keyboard) var modes = mode == '*' ? Object.keys(keyboard)
: mode == 'test' || mode == '?' ? this.modes() : mode == 'test' || mode == '?' ? this.modes()