From 90c73cbf54fb8714095d15781a2063fa8c052be7 Mon Sep 17 00:00:00 2001 From: Michael Meeks Date: Fri, 12 Jul 2019 11:39:16 +0100 Subject: [PATCH] clipboard: Improve selection management. Change-Id: I3b6318f9a0cc544b74564376426baf7d3759ee3e --- loleaflet/src/map/Clipboard.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/loleaflet/src/map/Clipboard.js b/loleaflet/src/map/Clipboard.js index 7b576c48b..42ca149a0 100644 --- a/loleaflet/src/map/Clipboard.js +++ b/loleaflet/src/map/Clipboard.js @@ -479,15 +479,21 @@ L.Clipboard = L.Class.extend({ _execOnElement: function(operation) { var serial = this._clipboardSerial; - var div = this._createDummyDiv('dummy content'); + var div = this._createDummyDiv('  '); var that = this; var doInvoke = function(ev) { console.log('Got event ' + ev.type + ' on transient editable'); + + var checkSelect = document.getSelection(); + if (checkSelect.isCollapsed) + console.log('Error: failed to select - cannot copy/paste'); + // forward with proper security credentials now. that[operation].call(that, ev); ev.preventDefault(); ev.stopPropagation(); + return false; }; var doSelect = function(ev) { @@ -501,6 +507,12 @@ L.Clipboard = L.Class.extend({ var rangeToSelect = document.createRange(); rangeToSelect.selectNodeContents(div); sel.addRange(rangeToSelect); + + var checkSelect = document.getSelection(); + if (checkSelect.isCollapsed) + console.log('Error: failed to select - cannot copy/paste'); + + return false; }; document['on' + operation] = doInvoke; document['onbefore' + operation] = doSelect;