Skip to content

Commit

Permalink
Added condition to avoid Shape JSON paste
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinoch authored and Vinoch committed Sep 24, 2019
1 parent 666355e commit 39ff0e4
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ exports.create = function(element, defaultFormatting, drawtext = true ) {

dom.handleEvent(textArea, 'input', function() {
var newText = textArea.value;
if (textAreaContent != newText) {
if (!isShapeJSON(newText) && textAreaContent != newText) {
textAreaContent = '';
textArea.value = '';
if (newText === plainClipboard) {
Expand All @@ -372,6 +372,19 @@ exports.create = function(element, defaultFormatting, drawtext = true ) {
}
});

var isShapeJSON = function( text ) {
try {
var obj = JSON.parse( text );
if( obj[0] && obj[0].data && obj[0].data.defId ) {
return true;
} else {
return false;
}
} catch( error ) {
return false;
}
}

var updateTextArea = function() {
focusChar = focusChar === null ? doc.selection.end : focusChar;
var endChar = doc.byOrdinal(focusChar);
Expand Down

0 comments on commit 39ff0e4

Please sign in to comment.