Skip to content

Commit 64fcd86

Browse files
committed
fix: dnd: incorrect checking of consumed drop event in other sidebars
(resolves #1554)
1 parent eef3964 commit 64fcd86

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/services/drag-and-drop.actions.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -1211,11 +1211,17 @@ export async function onDragEnd(e: DragEvent): Promise<void> {
12111211
// Check if the drop event was consumed by another sidebar
12121212
const requestingDropStatus: Promise<boolean>[] = []
12131213
for (const win of Windows.otherWindows) {
1214-
if (win.id) requestingDropStatus.push(IPC.sidebar(win.id, 'isDropEventConsumed'))
1214+
if (win.id) {
1215+
const gettingStatus = browser.sidebarAction.isOpen({ windowId: win.id }).then(isOpen => {
1216+
if (isOpen && win.id) return IPC.sidebar(win.id, 'isDropEventConsumed')
1217+
else return false
1218+
})
1219+
requestingDropStatus.push(gettingStatus)
1220+
}
12151221
}
12161222
let consumed
12171223
try {
1218-
consumed = await Promise.all(requestingDropStatus)
1224+
consumed = await Utils.deadline(1500, [], Promise.all(requestingDropStatus))
12191225
} catch (err) {
12201226
Logs.err('DnD.onDragEnd: Cannot get drop status from other windows', err)
12211227
return

src/utils.ts

+10
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,16 @@ export async function sleep(ms = 1000): Promise<void> {
115115
})
116116
}
117117

118+
/**
119+
* Deadline
120+
*/
121+
export function deadline<T>(deadline: number, fallback: T, promise: Promise<T>): Promise<T> {
122+
return new Promise((ok, meh) => {
123+
setTimeout(() => ok(fallback), deadline)
124+
promise.then(ok).catch(meh)
125+
})
126+
}
127+
118128
/**
119129
* Bytes to readable string
120130
*/

0 commit comments

Comments
 (0)