From 6fe7401eb9425abbfa747c470fe919ca60e70282 Mon Sep 17 00:00:00 2001 From: iVy Deliz Date: Tue, 5 Nov 2024 15:36:08 -0700 Subject: [PATCH] Add "scroll to activity" to activity directive table context menu (#1433) --- src/stores/plan.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) 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) + }); + } }