From 547237277d3c9f2d7932a3d8d5cc284590132d19 Mon Sep 17 00:00:00 2001
From: Terry Truong <terry06890@gmail.com>
Date: Tue, 24 Jan 2023 21:03:32 +1100
Subject: For search, jump to 'appropriate' scale

---
 src/components/TimeLine.vue | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

(limited to 'src/components/TimeLine.vue')

diff --git a/src/components/TimeLine.vue b/src/components/TimeLine.vue
index 373439a..18ae107 100644
--- a/src/components/TimeLine.vue
+++ b/src/components/TimeLine.vue
@@ -88,7 +88,8 @@ import {moduloPositive, animateWithClass, getTextWidth} from '../util';
 import {
 	getDaysInMonth, MIN_CAL_DATE, MONTH_NAMES, HistDate, HistEvent, getImagePath, dateToYearStr, dateToTickStr,
 	MIN_DATE, MAX_DATE, MONTH_SCALE, DAY_SCALE, SCALES,
-	stepDate, getScaleRatio, getNumSubUnits, getUnitDiff, getEventPrecision, dateToUnit, dateToScaleDate,
+	stepDate, getScaleRatio, getNumSubUnits, getUnitDiff, getEventPrecision, getScaleForJump,
+		dateToUnit, dateToScaleDate,
 	TimelineState,
 } from '../lib';
 import {useStore} from '../store';
@@ -1332,12 +1333,8 @@ watch(() => props.searchTarget, () => {
 
 	if (!idToPos.value.has(event.id)){ // If not already visible
 		// Determine new time range
-		let tempScale = scale.value;
-		let targetDate = event.start;
-		if (targetDate.isEarlier(MIN_CAL_DATE) && tempScale < 1){ // Account for jumping out of calendar limits
-			tempScale = getEventPrecision(event);
-		}
-		targetDate = dateToScaleDate(targetDate, tempScale);
+		let tempScale = getScaleForJump(event);
+		let targetDate = dateToScaleDate(event.start, tempScale);
 		const startEndDiff = getUnitDiff(startDate.value, endDate.value, scale.value);
 		let targetStart = stepDate(targetDate, tempScale, {forward: false, count: Math.floor(startEndDiff / 2)});
 		if (targetStart.isEarlier(MIN_DATE)){
-- 
cgit v1.2.3

