Skip to content

Commit

Permalink
Ignore dragover event of already finished drag session on other windo…
Browse files Browse the repository at this point in the history
…ws more robustly #3374
  • Loading branch information
piroor committed Sep 7, 2023
1 parent a5827b5 commit 29d3438
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
2 changes: 2 additions & 0 deletions webextensions/common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ export const kCOMMAND_BOOKMARK_TABS_WITH_DIALOG = 'treestyletab:bookmark-tabs-wi

export const kNOTIFY_TAB_MOUSEDOWN = 'treestyletab:tab-mousedown';
export const kNOTIFY_TAB_MOUSEDOWN_EXPIRED = 'treestyletab:tab-mousedown-expired';
export const kNOTIFY_TAB_DRAG_START = 'treestyletab:tab-drag-start';
export const kNOTIFY_TAB_DRAG_FINISH = 'treestyletab:tab-drag-finish';

export const kNOTIFY_SIDEBAR_FOCUS = 'treestyletab:sidebar-focus';
export const kNOTIFY_SIDEBAR_BLUR = 'treestyletab:sidebar-blur';
Expand Down
26 changes: 24 additions & 2 deletions webextensions/sidebar/drag-and-drop.js
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,6 @@ let mLastBrowserInfo = null;
function onDragStart(event, options = {}) {
log('onDragStart: start ', event, options);
clearDraggingTabsState(); // clear previous state anyway
mFinishedDragSessionIds.clear();
if (configs.enableWorkaroundForBug1548949)
configs.workaroundForBug1548949DroppedTabs = '';

Expand Down Expand Up @@ -877,6 +876,12 @@ function onDragStart(event, options = {}) {

const sanitizedDragData = sanitizeDragData(dragData);
dt.setData(kTREE_DROP_TYPE, JSON.stringify(sanitizedDragData));

mFinishedDragSessionIds.clear();
browser.runtime.sendMessage({
type: Constants.kNOTIFY_TAB_DRAG_START,
sessionId: sanitizedDragData.sessionId,
});
log(`onDragStart: starting drag session ${sanitizedDragData.sessionId}`);

// Because addon cannot read drag data across private browsing mode,
Expand Down Expand Up @@ -1314,8 +1319,13 @@ function onDrop(event) {
let dragData = event.dataTransfer.getData(kTREE_DROP_TYPE);
dragData = (dragData && JSON.parse(dragData)) || mCurrentDragData;
const sessionId = dragData && dragData.sessionId || '';
if (sessionId)
if (sessionId) {
mFinishedDragSessionIds.add(sessionId);
browser.runtime.sendMessage({
type: Constants.kNOTIFY_TAB_DRAG_FINISH,
sessionId,
});
}

log(`onDrop ${sessionId}`, dropActionInfo, event.dataTransfer);

Expand Down Expand Up @@ -1423,6 +1433,10 @@ async function onDragEnd(event) {
dragData.tab = dragData.tab && Tab.get(dragData.tab.id) || dragData.tab;
dragData.tabs = dragData.tabs && dragData.tabs.map(tab => tab && Tab.get(tab.id) || tab);
mFinishedDragSessionIds.add(dragData.sessionId);
browser.runtime.sendMessage({
type: Constants.kNOTIFY_TAB_DRAG_FINISH,
sessionId: dragData.sessionId,
});
log(`onDragEnd: finishing drag session ${dragData.sessionId}`);
}

Expand Down Expand Up @@ -1696,6 +1710,14 @@ function onMessage(message, _sender, _respond) {
if (!message.dragData)
onFinishDrag();
break;

case Constants.kNOTIFY_TAB_DRAG_START:
mFinishedDragSessionIds.clear();
break;

case Constants.kNOTIFY_TAB_DRAG_FINISH:
mFinishedDragSessionIds.add(message.sessionId);
break;
}
}

Expand Down

0 comments on commit 29d3438

Please sign in to comment.