Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

made keymap public #4053

Merged
merged 2 commits into from
Jul 1, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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