Fix and enhance navigate to time functionality
• Add i18n support for navigate button and dialog title • Update ChangeDate component to return DateTime object alongside ISO string • Fix closest date finding algorithm to handle cases where exact month doesn't exist • Add navigate to time (g) shortcut to keyboard shortcuts modal
This commit is contained in:
@@ -143,3 +143,24 @@ export function findMonthGroupForDate(timelineManager: TimelineManager, targetYe
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function findClosestGroupForDate(timelineManager: TimelineManager, targetYearMonth: TimelineYearMonth) {
|
||||
let closestMonth: MonthGroup | undefined;
|
||||
let minDifference = Number.MAX_SAFE_INTEGER;
|
||||
|
||||
for (const month of timelineManager.months) {
|
||||
const { year, month: monthNum } = month.yearMonth;
|
||||
|
||||
// Calculate the absolute difference in months
|
||||
const yearDiff = Math.abs(year - targetYearMonth.year);
|
||||
const monthDiff = Math.abs(monthNum - targetYearMonth.month);
|
||||
const totalDiff = yearDiff * 12 + monthDiff;
|
||||
|
||||
if (totalDiff < minDifference) {
|
||||
minDifference = totalDiff;
|
||||
closestMonth = month;
|
||||
}
|
||||
}
|
||||
|
||||
return closestMonth;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
runAssetOperation,
|
||||
} from '$lib/managers/timeline-manager/internal/operations-support.svelte';
|
||||
import {
|
||||
findClosestGroupForDate,
|
||||
findMonthGroupForAsset as findMonthGroupForAssetUtil,
|
||||
findMonthGroupForDate,
|
||||
getAssetWithOffset,
|
||||
@@ -523,9 +524,13 @@ export class TimelineManager {
|
||||
}
|
||||
|
||||
async getClosestAssetToDate(dateTime: TimelineDateTime) {
|
||||
const monthGroup = findMonthGroupForDate(this, dateTime);
|
||||
let monthGroup = findMonthGroupForDate(this, dateTime);
|
||||
if (!monthGroup) {
|
||||
return;
|
||||
// if exact match not found, find closest
|
||||
monthGroup = findClosestGroupForDate(this, dateTime);
|
||||
if (!monthGroup) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
await this.loadMonthGroup(dateTime, { cancelable: false });
|
||||
const asset = monthGroup.findClosest(dateTime);
|
||||
|
||||
Reference in New Issue
Block a user