public inbox for [email protected]  
help / color / mirror / Atom feed
From: Pradip Parkale <[email protected]>
To: pgadmin-hackers <[email protected]>
Subject: [pgAdmin][RM4436]Drag and drop is incorrect in codemirror boxes in node properties dialog
Date: Thu, 29 Apr 2021 11:17:01 +0530
Message-ID: <CAJ9T6Su5BtBAeWwyRS1ETOE51pa3Fg+7piVso67XJEeRdjZ96g@mail.gmail.com> (raw)

Hi Hackers,

Please find the attached patch for #4436 - Drag and drop is incorrect in
codemirror boxes in node properties dialog.


-- 
Thanks & Regards,
Pradip Parkale
Software Engineer | EnterpriseDB Corporation


Attachments:

  [application/octet-stream] RM4436.patch (1.8K, 3-RM4436.patch)
  download | inline diff:
diff --git a/web/pgadmin/static/js/backform.pgadmin.js b/web/pgadmin/static/js/backform.pgadmin.js
index 8f70fd3c0..e6b0f2480 100644
--- a/web/pgadmin/static/js/backform.pgadmin.js
+++ b/web/pgadmin/static/js/backform.pgadmin.js
@@ -2609,10 +2609,10 @@ define([
       // refresh the code mirror object on 'pg-property-tab-changed' event to
       // make it work properly.
       self.model.on('pg-property-tab-changed', this.refreshTextArea, this);
-
+      this.sqlCtrl.setOption('dragDrop', true);
       this.sqlCtrl.on('focus', this.onFocus);
       this.sqlCtrl.on('blur', this.onBlur);
-
+      this.sqlCtrl.on('drop', this.onDrop);
       // Refresh SQL Field to refresh the control lazily after it renders
       setTimeout(function() {
         self.refreshTextArea.apply(self);
@@ -2621,6 +2621,39 @@ define([
       return self;
     },
 
+    onDrop: function(editor, e){
+      var dropDetails = null;
+      try {
+        dropDetails = 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,
+      });
+      editor.replaceRange(dropDetails.text, cursor);
+      editor.focus();
+      editor.setSelection({
+        ...cursor,
+        ch: cursor.ch + dropDetails.cur.from,
+      },{
+        ...cursor,
+        ch: cursor.ch +dropDetails.cur.to,
+      });
+    },
+
     onFocus: function() {
       var $ctrl = this.$el.find('.pgadmin-controls').first();
       if (!$ctrl.hasClass('focused'))


view thread (2+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected]
  Subject: Re: [pgAdmin][RM4436]Drag and drop is incorrect in codemirror boxes in node properties dialog
  In-Reply-To: <CAJ9T6Su5BtBAeWwyRS1ETOE51pa3Fg+7piVso67XJEeRdjZ96g@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox