From f3b16a9f9dccde7613de88243a0eaa6809c14880 Mon Sep 17 00:00:00 2001 From: Maciej Barelkowski Date: Wed, 11 Mar 2020 12:32:19 +0100 Subject: [PATCH] fix(properties-panel): make sure to always paste as plain text Related to https://github.com/bpmn-io/bpmn-js-properties-panel/issues/265 --- lib/PropertiesPanel.js | 10 ++++++++++ test/spec/PropertiesPanelSpec.js | 5 +++++ test/spec/properties/PropertiesProvider.js | 9 +++++++++ 3 files changed, 24 insertions(+) diff --git a/lib/PropertiesPanel.js b/lib/PropertiesPanel.js index a63395c..2794c3d 100644 --- a/lib/PropertiesPanel.js +++ b/lib/PropertiesPanel.js @@ -525,6 +525,16 @@ PropertiesPanel.prototype._bindListeners = function(container) { domDelegate.bind(container, 'input, textarea, [contenteditable]', 'input', debounce(handleChange, DEBOUNCE_DELAY)); domDelegate.bind(container, 'input, textarea, select, [contenteditable]', 'change', handleChange); + // paste as plain text only + domDelegate.bind(container, '[contenteditable]', 'paste', handlePaste); + + function handlePaste(event) { + var text = (event.clipboardData || window.clipboardData).getData('text'); + document.execCommand('insertText', false, text); + + event.preventDefault(); + } + domDelegate.bind(container, '[data-action]', 'click', function onClick(event) { // triggers on all inputs diff --git a/test/spec/PropertiesPanelSpec.js b/test/spec/PropertiesPanelSpec.js index 1ec649d..0f48532 100644 --- a/test/spec/PropertiesPanelSpec.js +++ b/test/spec/PropertiesPanelSpec.js @@ -253,5 +253,10 @@ describe('properties-panel', function() { }); + describe('listeners', function() { + // Cannot be tested due to paste events not affecting document's contents per default. + // Cf. https://developer.mozilla.org/en-US/docs/Web/API/Element/paste_event + it('should paste to [contenteditable] as plain text'); + }); }); diff --git a/test/spec/properties/PropertiesProvider.js b/test/spec/properties/PropertiesProvider.js index 703080d..173d450 100644 --- a/test/spec/properties/PropertiesProvider.js +++ b/test/spec/properties/PropertiesProvider.js @@ -220,6 +220,15 @@ function createGroups(element, cmmnFactory) { } } ] + }, + { + id: 'inputs', + entries: [ + { + id: 'contenteditable', + html: '
Content editable:
' + } + ] } ]; }