Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Drag and drop Feature in google doc from app script

58 views
Skip to first unread message

Ashish Burman

unread,
Oct 2, 2024, 1:57:43 AM10/2/24
to Google Apps Script Community
We are implementing a feature where we would like to drag and drop / or any other form to add some identifier in the doc to be replaced by recipients of the doc . some thing similar to the video attached. Any help would be appreciated 
I am using editor add on for google doc. 
drag_drop.mp4

Ed Robinson

unread,
Oct 3, 2024, 7:49:15 AM10/3/24
to Google Apps Script Community
Ashish,
dragging fields from a sidebar into a document is an awesome UI design, and it seems like it should be easy, but it is complicated and may be impossible to do

The reason drag and drop is complicated/impossible is:
- The sidebar is running in an iFrame, it has limited access to the parent frame in the browser, so managing drag 'n drop from iFrame to parent editor is unreliable
- Detecting where the drop happens, then translating that to a document insertion point is also complicated - The add-on has limited programmatic access to the "editor viewport"

Your add-on does have access to the current insertion point, selection, and document object. These are not enough for drag 'n drop, but do allow you to achieve a similar result with a different design

The option you have available  is:
- User puts the cursor in the document where they want the field
- They chose an action in your add-on sidebar (like "insert signature") and your add-on adds it as an element into the document
- Element is added at the current insertion point, and the user can then reposition the element using the Google Docs editor

This approach is not as graceful as drag 'n drop, but works reliably. 

Ed

Ashish Burman

unread,
Oct 3, 2024, 2:37:39 PM10/3/24
to Google Apps Script Community
Thanks Ed, I will be using the cursor and doc element for this. 
Reply all
Reply to author
Forward
0 new messages