Skip to content

Commit

Permalink
made keymap public (#4053)
Browse files Browse the repository at this point in the history
* made keymap public
* better docs
  • Loading branch information
asturur authored Jul 1, 2017
1 parent f6a7c29 commit 5e7e665
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/mixins/itext_key_behavior.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,17 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
},

/**
* @private
*/
_keysMap: {
* For functionalities on keyDown
* Map a special key to a function of the instance/prototype
* If you need different behaviour for ESC or TAB or arrows, you have to change
* this map setting the name of a function that you build on the fabric.Itext or
* your prototype.
* the map change will affect all Instances unless you need for only some text Instances
* in that case you have to clone this object and assign your Instance.
* this.keysMap = fabric.util.object.clone(this.keysMap);
* The function must be in fabric.Itext.prototype.myFunction And will receive event as args[0]
*/
keysMap: {
9: 'exitEditing',
27: 'exitEditing',
33: 'moveCursorUp',
Expand All @@ -50,17 +58,17 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
},

/**
* @private
* For functionalities on keyUp + ctrl || cmd
*/
_ctrlKeysMapUp: {
ctrlKeysMapUp: {
67: 'copy',
88: 'cut'
},

/**
* @private
* For functionalities on keyDown + ctrl || cmd
*/
_ctrlKeysMapDown: {
ctrlKeysMapDown: {
65: 'selectAll'
},

Expand All @@ -77,11 +85,11 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
if (!this.isEditing || this.inCompositionMode) {
return;
}
if (e.keyCode in this._keysMap) {
this[this._keysMap[e.keyCode]](e);
if (e.keyCode in this.keysMap) {
this[this.keysMap[e.keyCode]](e);
}
else if ((e.keyCode in this._ctrlKeysMapDown) && (e.ctrlKey || e.metaKey)) {
this[this._ctrlKeysMapDown[e.keyCode]](e);
else if ((e.keyCode in this.ctrlKeysMapDown) && (e.ctrlKey || e.metaKey)) {
this[this.ctrlKeysMapDown[e.keyCode]](e);
}
else {
return;
Expand Down Expand Up @@ -109,8 +117,8 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
this._copyDone = false;
return;
}
if ((e.keyCode in this._ctrlKeysMapUp) && (e.ctrlKey || e.metaKey)) {
this[this._ctrlKeysMapUp[e.keyCode]](e);
if ((e.keyCode in this.ctrlKeysMapUp) && (e.ctrlKey || e.metaKey)) {
this[this.ctrlKeysMapUp[e.keyCode]](e);
}
else {
return;
Expand Down

0 comments on commit 5e7e665

Please sign in to comment.