Fix some errors thrown on the JS console when dragging text in the Query Tool. Fixes #4552

This commit is contained in:
Aditya Toshniwal
2019-08-02 11:28:57 +01:00
committed by Dave Page
parent 0cfd76c279
commit 99a8b70e00
3 changed files with 30 additions and 17 deletions

View File

@@ -367,19 +367,27 @@ define('tools.querytool', [
if(self.handler.is_query_tool) {
self.query_tool_obj.setOption('dragDrop', true);
self.query_tool_obj.on('drop', (editor, e) => {
/* Stop firefox from redirecting */
if(e.preventDefault) {
e.preventDefault();
}
if (e.stopPropagation) {
e.stopPropagation();
var dropDetails = null;
try {
JSON.parse(e.dataTransfer.getData('text'));
/* Stop firefox from redirecting */
if(e.preventDefault) {
e.preventDefault();
}
if (e.stopPropagation) {
e.stopPropagation();
}
} catch(error) {
/* if parsing fails, it must be the drag internal of codemirror text */
return;
}
var cursor = editor.coordsChar({
left: e.x,
top: e.y,
});
var dropDetails = JSON.parse(e.dataTransfer.getData('text'));
e.codemirrorIgnore = true;
editor.replaceRange(dropDetails.text, cursor);
editor.focus();
editor.setSelection({