Allow some objects to be dragged/dropped into the Query Tool to insert their signature into the query text. Fixes #4139

This commit is contained in:
Aditya Toshniwal
2019-06-27 10:30:05 -04:00
committed by Dave Page
parent bdb8f20aed
commit 173b812b93
10 changed files with 390 additions and 3 deletions

View File

@@ -341,8 +341,31 @@ define('tools.querytool', [
gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter'],
extraKeys: pgBrowser.editor_shortcut_keys,
scrollbarStyle: 'simple',
dragDrop: false,
});
if(self.handler.is_query_tool) {
self.query_tool_obj.setOption('dragDrop', true);
self.query_tool_obj.on('drop', (editor, e) => {
var cursor = editor.coordsChar({
left: e.x,
top: e.y,
});
var dropDetails = JSON.parse(e.dataTransfer.getData('text'));
e.codemirrorIgnore = true;
e.dataTransfer.clearData('text');
editor.replaceRange(dropDetails.text, cursor);
editor.focus();
editor.setSelection({
...cursor,
ch: cursor.ch + dropDetails.cur.from,
},{
...cursor,
ch: cursor.ch +dropDetails.cur.to,
});
});
}
pgBrowser.Events.on('pgadmin:query_tool:sql_panel:focus', ()=>{
self.query_tool_obj.focus();
});