mirror of
https://github.com/Horizontal42/summarum.git
synced 2026-11-11 01:02:01 +03:00
perf: optimize drag/drop event loop performance
Co-authored-by: Horizontal42 <75383519+Horizontal42@users.noreply.github.com>
This commit is contained in:
parent
37cfd2144b
commit
b3c5c34221
1 changed files with 13 additions and 7 deletions
18
src/main.ts
18
src/main.ts
|
|
@ -140,7 +140,11 @@ function reorderDoc(srcId: string, targetId: string): void {
|
||||||
renderDocList();
|
renderDocList();
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupDocInteraction(el: HTMLElement, doc: DocMeta, list: HTMLElement): void {
|
function setupDocInteraction(
|
||||||
|
el: HTMLElement,
|
||||||
|
doc: DocMeta,
|
||||||
|
list: HTMLElement,
|
||||||
|
): void {
|
||||||
// Reordering uses plain mouse tracking, not the native HTML5 drag API —
|
// Reordering uses plain mouse tracking, not the native HTML5 drag API —
|
||||||
// Tauri's window-level file-drop hook (dragDropEnabled, needed for
|
// Tauri's window-level file-drop hook (dragDropEnabled, needed for
|
||||||
// dropping .numi files from Explorer) intercepts WebView2's own drag
|
// dropping .numi files from Explorer) intercepts WebView2's own drag
|
||||||
|
|
@ -163,7 +167,8 @@ function setupDocInteraction(el: HTMLElement, doc: DocMeta, list: HTMLElement):
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (!dragging) {
|
if (!dragging) {
|
||||||
if (Math.abs(ev.clientY - startY) < 4) return;
|
const dy = ev.clientY - startY;
|
||||||
|
if (dy > -4 && dy < 4) return;
|
||||||
dragging = true;
|
dragging = true;
|
||||||
suppressClick = true;
|
suppressClick = true;
|
||||||
el.classList.add("dragging");
|
el.classList.add("dragging");
|
||||||
|
|
@ -171,10 +176,9 @@ function setupDocInteraction(el: HTMLElement, doc: DocMeta, list: HTMLElement):
|
||||||
}
|
}
|
||||||
let over: HTMLElement | undefined;
|
let over: HTMLElement | undefined;
|
||||||
for (const item of cachedItems) {
|
for (const item of cachedItems) {
|
||||||
if (!over && item.el !== el) {
|
|
||||||
if (ev.clientY >= item.top && ev.clientY <= item.bottom) {
|
if (ev.clientY >= item.top && ev.clientY <= item.bottom) {
|
||||||
over = item.el;
|
if (item.el !== el) over = item.el;
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let newOver: HTMLElement | undefined;
|
let newOver: HTMLElement | undefined;
|
||||||
|
|
@ -341,7 +345,9 @@ async function closeActiveDoc(): Promise<void> {
|
||||||
void backupDeletedSheet(settings.dataDir, doc.title, content);
|
void backupDeletedSheet(settings.dataDir, doc.title, content);
|
||||||
delete data.contents[doc.id];
|
delete data.contents[doc.id];
|
||||||
removeDocById(doc.id);
|
removeDocById(doc.id);
|
||||||
const nextId = data.docs[idx] ? data.docs[idx].id : (data.docs[idx - 1]?.id ?? data.docs[0].id);
|
const nextId = data.docs[idx]
|
||||||
|
? data.docs[idx].id
|
||||||
|
: (data.docs[idx - 1]?.id ?? data.docs[0].id);
|
||||||
switchDoc(nextId);
|
switchDoc(nextId);
|
||||||
saveAppData(data);
|
saveAppData(data);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue