Skip to content

Commit

Permalink
Set text/plain drag data from tabs #3618
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Sep 5, 2024
1 parent 0d74bb6 commit 758dbdd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
7 changes: 4 additions & 3 deletions webextensions/common/retrieve-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function log(...args) {
internalLogger('common/retrieve-url', ...args);
}

export const kTYPE_PLAIN_TEXT = 'text/plain';
export const kTYPE_X_MOZ_URL = 'text/x-moz-url';
export const kTYPE_URI_LIST = 'text/uri-list';
export const kTYPE_MOZ_TEXT_INTERNAL = 'text/x-moz-text-internal';
Expand All @@ -23,7 +24,7 @@ const ACCEPTABLE_DATA_TYPES = [
kTYPE_URI_LIST,
kTYPE_X_MOZ_URL,
kTYPE_MOZ_TEXT_INTERNAL,
'text/plain'
kTYPE_PLAIN_TEXT,
];

let mFileURLResolver = null;
Expand Down Expand Up @@ -102,7 +103,7 @@ export async function fromClipboard({ selection } = {}) {
if (await mSelectionClipboardProvider.isAvailable()) {
const maybeUrlString = await mSelectionClipboardProvider.getTextData();
if (maybeUrlString)
urls.push(...fromData(maybeUrlString, 'text/plain'));
urls.push(...fromData(maybeUrlString, kTYPE_PLAIN_TEXT));
return sanitizeURLs(urls);
}
}
Expand Down Expand Up @@ -172,7 +173,7 @@ function fromData(data, type) {
.trim()
.split('\n');

case 'text/plain':
case kTYPE_PLAIN_TEXT:
return data
.replace(/\r/g, '\n')
.replace(/\n\n+/g, '\n')
Expand Down
9 changes: 7 additions & 2 deletions webextensions/sidebar/drag-and-drop.js
Original file line number Diff line number Diff line change
Expand Up @@ -789,23 +789,28 @@ function onDragStart(event, options = {}) {
}).catch(ApiTabs.createErrorSuppressor());

if (!dataOverridden) {
const urls = [];
const mozUrl = [];
const urlList = [];
for (const draggedTab of dragData.tabs) {
draggedTab.$TST.addState(Constants.kTAB_STATE_DRAGGING);
TabsStore.addDraggingTab(draggedTab);
if (!dragData.individualOnOutside ||
mozUrl.length == 0) {
urls.push(draggedTab.url);
mozUrl.push(`${draggedTab.url}\n${draggedTab.title}`);
urlList.push(`#${draggedTab.title}\n${draggedTab.url}`);
}
}
mCurrentDragDataForExternals[RetrieveURL.kTYPE_PLAIN_TEXT] = urls.join('\n');
mCurrentDragDataForExternals[RetrieveURL.kTYPE_X_MOZ_URL] = mozUrl.join('\n');
mCurrentDragDataForExternals[RetrieveURL.kTYPE_URI_LIST] = urlList.join('\n');
if (allowBookmark) {
log('set kTYPE_X_MOZ_URL');
log('set kTYPE_PLAIN_TEXT ', mCurrentDragDataForExternals[RetrieveURL.kTYPE_PLAIN_TEXT]);
dt.setData(RetrieveURL.kTYPE_PLAIN_TEXT, mCurrentDragDataForExternals[RetrieveURL.kTYPE_PLAIN_TEXT]);
log('set kTYPE_X_MOZ_URL ', mCurrentDragDataForExternals[RetrieveURL.kTYPE_X_MOZ_URL]);
dt.setData(RetrieveURL.kTYPE_X_MOZ_URL, mCurrentDragDataForExternals[RetrieveURL.kTYPE_X_MOZ_URL]);
log('set kTYPE_URI_LIST');
log('set kTYPE_URI_LIST ', mCurrentDragDataForExternals[RetrieveURL.kTYPE_URI_LIST]);
dt.setData(RetrieveURL.kTYPE_URI_LIST, mCurrentDragDataForExternals[RetrieveURL.kTYPE_URI_LIST]);
}
}
Expand Down

0 comments on commit 758dbdd

Please sign in to comment.