|
655 | 655 | rowIndex, |
656 | 656 | renderedRows, |
657 | 657 | nextRow ? nextRow.date : addDaysIso(row.date, 1), |
| 658 | + undefined, |
| 659 | + { preserveFocus: true }, |
658 | 660 | ); |
659 | 661 | appliedCount += 1; |
660 | 662 | } |
|
798 | 800 | refreshQueuedAfterFlight = true; |
799 | 801 | return; |
800 | 802 | } |
801 | | - if (!isIsoDateString(loadedEndDate)) return; |
802 | | - const startDate = isIsoDateString(refreshFromDate) ? refreshFromDate : loadedStartDate; |
| 803 | + if (!isIsoDateString(loadedStartDate) || !isIsoDateString(loadedEndDate)) return; |
| 804 | + const activeEl = document.activeElement; |
| 805 | + const activeIsInput = activeEl instanceof HTMLInputElement || activeEl instanceof HTMLSelectElement; |
| 806 | + const activeClassName = activeIsInput ? String(activeEl.className || "") : ""; |
| 807 | + const activeDate = activeIsInput && activeEl.dataset ? String(activeEl.dataset.date || "") : ""; |
| 808 | + const activeSessionIndex = activeIsInput && activeEl.dataset |
| 809 | + ? String(activeEl.dataset.sessionIndex || "0") |
| 810 | + : "0"; |
| 811 | + const restoreSelector = ( |
| 812 | + activeIsInput |
| 813 | + && isIsoDateString(activeDate) |
| 814 | + && ( |
| 815 | + activeClassName.includes("plan-session-distance") |
| 816 | + || activeClassName.includes("plan-session-type") |
| 817 | + || activeClassName.includes("plan-session-workout") |
| 818 | + ) |
| 819 | + ) |
| 820 | + ? `.${activeClassName.split(/\s+/).find((name) => name.startsWith("plan-session-"))}[data-date="${activeDate}"][data-session-index="${activeSessionIndex}"]` |
| 821 | + : ""; |
| 822 | + const prevScrollTop = tableWrapEl ? tableWrapEl.scrollTop : 0; |
| 823 | + const prevScrollLeft = tableWrapEl ? tableWrapEl.scrollLeft : 0; |
803 | 824 | refreshFromDate = ""; |
804 | 825 | refreshInFlight = true; |
805 | 826 | try { |
806 | 827 | await loadPlanRange({ |
807 | | - startDate, |
| 828 | + startDate: loadedStartDate, |
808 | 829 | endDate: loadedEndDate, |
809 | 830 | centerDateOverride: centerDateEl.value, |
810 | | - append: true, |
| 831 | + append: false, |
811 | 832 | }); |
| 833 | + if (tableWrapEl) { |
| 834 | + tableWrapEl.scrollTop = prevScrollTop; |
| 835 | + tableWrapEl.scrollLeft = prevScrollLeft; |
| 836 | + } |
| 837 | + if (restoreSelector) { |
| 838 | + const restoreTarget = bodyEl.querySelector(restoreSelector); |
| 839 | + if (restoreTarget instanceof HTMLElement) { |
| 840 | + restoreTarget.focus(); |
| 841 | + if (restoreTarget instanceof HTMLInputElement && typeof restoreTarget.select === "function") { |
| 842 | + restoreTarget.select(); |
| 843 | + } |
| 844 | + } |
| 845 | + } |
812 | 846 | } finally { |
813 | 847 | refreshInFlight = false; |
814 | 848 | if (refreshQueuedAfterFlight || isIsoDateString(refreshFromDate)) { |
|
1042 | 1076 | && batchMaxNextFocusDate > loadedEndDate |
1043 | 1077 | ); |
1044 | 1078 | if (needsAppendFuture) { |
1045 | | - const anchorDate = isIsoDateString(minSavedDate) ? minSavedDate : loadedEndDate; |
1046 | | - const appendStart = overlapStartForDate(anchorDate, loadedStartDate); |
1047 | 1079 | const appendTarget = addDaysIso(loadedEndDate, PLAN_APPEND_FUTURE_DAYS); |
1048 | 1080 | const appendEnd = batchMaxNextFocusDate > appendTarget ? batchMaxNextFocusDate : appendTarget; |
| 1081 | + const fullStart = isIsoDateString(loadedStartDate) ? loadedStartDate : overlapStartForDate(minSavedDate, ""); |
1049 | 1082 | await loadPlanRange({ |
1050 | | - startDate: appendStart, |
| 1083 | + startDate: fullStart, |
1051 | 1084 | endDate: appendEnd, |
1052 | 1085 | centerDateOverride: centerDateEl.value, |
1053 | | - append: true, |
| 1086 | + append: false, |
1054 | 1087 | }); |
1055 | 1088 | } else if ( |
1056 | 1089 | isIsoDateString(minSavedDate) |
|
0 commit comments