From 1c781bab76c7db6f4b7a9250075857e177d341d3 Mon Sep 17 00:00:00 2001 From: Gelin Luo Date: Sat, 21 May 2016 09:15:19 +1000 Subject: [PATCH] fix #28: allow paste a string directly through API call --- src/Editor.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Editor.js b/src/Editor.js index 384ca21..f79d135 100644 --- a/src/Editor.js +++ b/src/Editor.js @@ -289,11 +289,15 @@ Editor.prototype.paste = function(evt){ self.selMgr.setRange(start, start); self.changed(); } + + var insert = typeof evt == 'string'; + + if(insert || evt.clipboardData){ + if (!insert) { + evt.preventDefault(); + } - if(evt.clipboardData){ - evt.preventDefault(); - - var pasted = evt.clipboardData.getData('text/plain'); + var pasted = insert ? evt : evt.clipboardData.getData('text/plain'); this.apply({ add: pasted, @@ -310,4 +314,5 @@ Editor.prototype.paste = function(evt){ applyPasted(self.getText().slice(start, newEnd)); }, 0); } + };