Enhancement : #169 : Use several meta for shortcut

- can now use shift+ctrl+alt in shortcut definition
- paste opaque for selection remapped to ctrl+shift+V
This commit is contained in:
jdescottes 2014-04-24 13:28:21 +02:00
parent cf2c0e7045
commit a060e32b15
2 changed files with 29 additions and 22 deletions

View File

@ -19,7 +19,7 @@
$.subscribe(Events.SELECTION_MOVE_REQUEST, $.proxy(this.onSelectionMoved_, this)); $.subscribe(Events.SELECTION_MOVE_REQUEST, $.proxy(this.onSelectionMoved_, this));
pskl.app.shortcutService.addShortcut('ctrl+V', this.paste.bind(this)); pskl.app.shortcutService.addShortcut('ctrl+V', this.paste.bind(this));
pskl.app.shortcutService.addShortcut('shift+V', this.pasteOpaqueOnly.bind(this)); pskl.app.shortcutService.addShortcut('ctrl+shift+V', this.pasteOpaqueOnly.bind(this));
pskl.app.shortcutService.addShortcut('ctrl+X', this.cut.bind(this)); pskl.app.shortcutService.addShortcut('ctrl+X', this.cut.bind(this));
pskl.app.shortcutService.addShortcut('ctrl+C', this.copy.bind(this)); pskl.app.shortcutService.addShortcut('ctrl+C', this.copy.bind(this));
pskl.app.shortcutService.addShortcut('del', this.erase.bind(this)); pskl.app.shortcutService.addShortcut('del', this.erase.bind(this));

View File

@ -47,20 +47,31 @@
}; };
ns.ShortcutService.prototype.parseKey_ = function (key) { ns.ShortcutService.prototype.parseKey_ = function (key) {
var meta = 'normal'; var meta = this.getMetaKey_({
if (key.indexOf('ctrl+') === 0) { alt : key.indexOf('alt+') != -1,
meta = 'ctrl'; shift : key.indexOf('shift+') != -1,
key = key.replace('ctrl+', ''); ctrl : key.indexOf('ctrl+') != -1
} else if (key.indexOf('shift+') === 0) { });
meta = 'shift';
key = key.replace('shift+', ''); var parts = key.split('+');
} else if (key.indexOf('alt+') === 0) { key = parts[parts.length-1];
meta = 'alt';
key = key.replace('alt+', '');
}
return {meta : meta, key : key}; return {meta : meta, key : key};
}; };
ns.ShortcutService.prototype.getMetaKey_ = function (meta) {
var keyBuffer = [];
['alt', 'ctrl', 'shift'].forEach(function (metaKey) {
if (meta[metaKey]) {
keyBuffer.push(metaKey);
}
});
if (keyBuffer.length > 0) {
return keyBuffer.join('+');
} else {
return 'normal';
}
};
/** /**
* @private * @private
*/ */
@ -73,16 +84,12 @@
var keyShortcuts = this.shortcuts_[charkey]; var keyShortcuts = this.shortcuts_[charkey];
if(keyShortcuts) { if(keyShortcuts) {
var cb; var meta = this.getMetaKey_({
if (this.isCtrlKeyPressed_(evt)) { alt : this.isAltKeyPressed_(evt),
cb = keyShortcuts.ctrl; shift : this.isShiftKeyPressed_(evt),
} else if (this.isShiftKeyPressed_(evt)) { ctrl : this.isCtrlKeyPressed_(evt)
cb = keyShortcuts.shift; });
} else if (this.isAltKeyPressed_(evt)) { var cb = keyShortcuts[meta];
cb = keyShortcuts.alt;
} else {
cb = keyShortcuts.normal;
}
if(cb) { if(cb) {
var bubble = cb(charkey); var bubble = cb(charkey);