Skip to content

Commit 2ce7790

Browse files
committed
plan: suppress stale pending-focus jumps during background refresh
1 parent ab43bdb commit 2ce7790

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

static/plan.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,7 @@
829829
endDate: loadedEndDate,
830830
centerDateOverride: centerDateEl.value,
831831
append: false,
832+
suppressPendingFocus: true,
832833
});
833834
if (tableWrapEl) {
834835
tableWrapEl.scrollTop = prevScrollTop;
@@ -977,6 +978,10 @@
977978
};
978979
}
979980

981+
function clearPendingFocus() {
982+
pendingFocus = { date: "", field: "distance" };
983+
}
984+
980985
function mergeSavePayload(existingPayload, incomingPayload) {
981986
const base = existingPayload && typeof existingPayload === "object" ? existingPayload : {};
982987
const next = incomingPayload && typeof incomingPayload === "object" ? incomingPayload : {};
@@ -1011,7 +1016,9 @@
10111016
if (!isIsoDateString(dateKey)) return;
10121017
const nextPayload = mergeSavePayload(pendingPlanSaves.get(dateKey), payload || {});
10131018
pendingPlanSaves.set(dateKey, nextPayload);
1014-
if (isIsoDateString(nextFocusDate) && !preserveFocus) {
1019+
if (preserveFocus) {
1020+
clearPendingFocus();
1021+
} else if (isIsoDateString(nextFocusDate)) {
10151022
if (!isIsoDateString(saveMaxNextFocusDate) || nextFocusDate > saveMaxNextFocusDate) {
10161023
saveMaxNextFocusDate = nextFocusDate;
10171024
}
@@ -1781,6 +1788,7 @@
17811788
append = false,
17821789
centerDateInView = "",
17831790
centerBehavior = "auto",
1791+
suppressPendingFocus = false,
17841792
} = {}) {
17851793
const requestVersion = ++loadRequestVersion;
17861794
const params = new URLSearchParams();
@@ -1852,7 +1860,9 @@
18521860
if (isIsoDateString(payloadStart)) loadedStartDate = payloadStart;
18531861
if (isIsoDateString(payloadEnd)) loadedEndDate = payloadEnd;
18541862
}
1855-
applyPendingFocus();
1863+
if (!suppressPendingFocus) {
1864+
applyPendingFocus();
1865+
}
18561866
const centerTarget = String(centerDateInView || "").trim();
18571867
if (isIsoDateString(centerTarget)) {
18581868
requestAnimationFrame(() => {

0 commit comments

Comments
 (0)