Skip to content

Commit

Permalink
Fix dragging text within prompt input
Browse files Browse the repository at this point in the history
  • Loading branch information
missionfloyd committed Apr 29, 2024
1 parent 1c0a0c4 commit 4c7b22d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion javascript/dragdrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ function eventHasFiles(e) {
return false;
}

function isURL(url) {
try {
const _ = new URL(url);
return true;
} catch {
return false;
}
}

function dragDropTargetIsPrompt(target) {
if (target?.placeholder && target?.placeholder.indexOf("Prompt") >= 0) return true;
if (target?.parentNode?.parentNode?.className?.indexOf("prompt") > 0) return true;
Expand All @@ -77,7 +86,7 @@ window.document.addEventListener('dragover', e => {
window.document.addEventListener('drop', async e => {
const target = e.composedPath()[0];
const url = e.dataTransfer.getData('text/uri-list') || e.dataTransfer.getData('text/plain');
if (!eventHasFiles(e) && !url) return;
if (!eventHasFiles(e) && !isURL(url)) return;

if (dragDropTargetIsPrompt(target)) {
e.stopPropagation();
Expand Down

0 comments on commit 4c7b22d

Please sign in to comment.