From 741e8cf43d5f7c8473a2f49808b10f99c535ec2c Mon Sep 17 00:00:00 2001 From: Kureev Alexey Date: Sun, 25 May 2014 18:15:54 +0400 Subject: [PATCH] Copy/Paste from/to external resources --- src/mixins/itext_key_behavior.mixin.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/mixins/itext_key_behavior.mixin.js b/src/mixins/itext_key_behavior.mixin.js index 60b502e5..4746db6f 100644 --- a/src/mixins/itext_key_behavior.mixin.js +++ b/src/mixins/itext_key_behavior.mixin.js @@ -13,6 +13,9 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot fabric.util.addListener(this.hiddenTextarea, 'keydown', this.onKeyDown.bind(this)); fabric.util.addListener(this.hiddenTextarea, 'keypress', this.onKeyPress.bind(this)); + fabric.util.addListener(this.hiddenTextarea, 'copy', this.copy.bind(this)); + fabric.util.addListener(this.hiddenTextarea, 'paste', this.paste.bind(this)); + if (!this._clickHandlerInitialized && this.canvas) { fabric.util.addListener(this.canvas.upperCanvasEl, 'click', this.onClick.bind(this)); @@ -38,8 +41,6 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot */ _ctrlKeysMap: { 65: 'selectAll', - 67: 'copy', - 86: 'paste', 88: 'cut' }, @@ -65,7 +66,6 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot return; } - e.preventDefault(); e.stopPropagation(); this.canvas && this.canvas.renderAll(); @@ -84,8 +84,10 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot /** * Copies selected text */ - copy: function() { + copy: function(ev) { var selectedText = this.getSelectedText(); + ev.clipboardData.setData('text', selectedText); + this.copiedText = selectedText; this.copiedStyles = this.getSelectionStyles( this.selectionStart, @@ -95,9 +97,11 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot /** * Pastes text */ - paste: function() { - if (this.copiedText) { - this.insertChars(this.copiedText); + paste: function(ev) { + var copiedText = ev.clipboardData.getData('text'); + + if (copiedText) { + this.insertChars(copiedText); } }, @@ -120,7 +124,6 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot this.insertChars(String.fromCharCode(e.which)); - e.preventDefault(); e.stopPropagation(); }, @@ -608,4 +611,4 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot } } } -}); +}); \ No newline at end of file