diff --git a/src/stores/plan.ts b/src/stores/plan.ts index 070abb224d..baf01d9a6a 100644 --- a/src/stores/plan.ts +++ b/src/stores/plan.ts @@ -6,6 +6,7 @@ import type { Tag } from '../types/tags'; import type { TimeRange } from '../types/timeline'; import gql from '../utilities/gql'; import { gqlSubscribable } from './subscribable'; +import { getIntervalInMs } from '../utilities/time'; /* Writeable. */ @@ -115,13 +116,15 @@ export function setActivityEditingLocked(locked: boolean) { activityEditingLocked.set(locked); } +// follows similar pattern to TimelineViewControls.scrollToSelection export function setViewTimeRangeAroundTime(timeInMs: number) { const currentViewTimeRange = get(viewTimeRange); - const padding = (currentViewTimeRange.end - currentViewTimeRange.start)/2; - const maxRange = get(maxTimeRange); - viewTimeRange.set({ - end: Math.min(maxRange.end, timeInMs + padding), - start: Math.max(maxRange.start, timeInMs - padding) - }); - + if (!isNaN(timeInMs) && (timeInMs < currentViewTimeRange.start || timeInMs > currentViewTimeRange.end)) { + const padding = (currentViewTimeRange.end - currentViewTimeRange.start) / 2; + const maxRange = get(maxTimeRange); + viewTimeRange.set({ + end: Math.min(maxRange.end, timeInMs + padding), + start: Math.max(maxRange.start, timeInMs - padding) + }); + } }