add support for bindkey.position
This commit is contained in:
parent
abe0286420
commit
b0ce5630c9
1 changed files with 26 additions and 9 deletions
|
|
@ -87,9 +87,12 @@ MultiHashHandler.prototype = HashHandler.prototype;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.bindKey = function(key, command, asDefault) {
|
this.bindKey = function(key, command, position) {
|
||||||
if (typeof key == "object")
|
if (typeof key == "object") {
|
||||||
|
if (position == undefined)
|
||||||
|
position = key.position;
|
||||||
key = key[this.platform];
|
key = key[this.platform];
|
||||||
|
}
|
||||||
if (!key)
|
if (!key)
|
||||||
return;
|
return;
|
||||||
if (typeof command == "function")
|
if (typeof command == "function")
|
||||||
|
|
@ -110,11 +113,15 @@ MultiHashHandler.prototype = HashHandler.prototype;
|
||||||
}
|
}
|
||||||
var binding = this.parseKeys(keyPart);
|
var binding = this.parseKeys(keyPart);
|
||||||
var id = KEY_MODS[binding.hashId] + binding.key;
|
var id = KEY_MODS[binding.hashId] + binding.key;
|
||||||
this._addCommandToBinding(chain + id, command, asDefault);
|
this._addCommandToBinding(chain + id, command, position);
|
||||||
}, this);
|
}, this);
|
||||||
};
|
};
|
||||||
|
|
||||||
this._addCommandToBinding = function(keyId, command, asDefault) {
|
function getPosition(command) {
|
||||||
|
return typeof command == "object" && command.bindKey
|
||||||
|
&& command.bindKey.position || 0;
|
||||||
|
}
|
||||||
|
this._addCommandToBinding = function(keyId, command, position) {
|
||||||
var ckb = this.commandKeyBinding, i;
|
var ckb = this.commandKeyBinding, i;
|
||||||
if (!command) {
|
if (!command) {
|
||||||
delete ckb[keyId];
|
delete ckb[keyId];
|
||||||
|
|
@ -126,11 +133,21 @@ MultiHashHandler.prototype = HashHandler.prototype;
|
||||||
} else if ((i = ckb[keyId].indexOf(command)) != -1) {
|
} else if ((i = ckb[keyId].indexOf(command)) != -1) {
|
||||||
ckb[keyId].splice(i, 1);
|
ckb[keyId].splice(i, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (asDefault || command.isDefault)
|
if (typeof position != "number") {
|
||||||
ckb[keyId].unshift(command);
|
if (position || command.isDefault)
|
||||||
else
|
position = -100;
|
||||||
ckb[keyId].push(command);
|
else
|
||||||
|
position = getPosition(command);
|
||||||
|
}
|
||||||
|
var commands = ckb[keyId];
|
||||||
|
for (i = 0; i < commands.length; i++) {
|
||||||
|
var other = commands[i];
|
||||||
|
var otherPos = getPosition(other);
|
||||||
|
if (otherPos > position)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
commands.splice(i, 0, command);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue