Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 27 additions & 16 deletions lib/timeline/Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,13 @@ class Core {
this.range.stopRolling();

// Depending on the mouse wheel used chose the delta (some mice have the hardware for both)
const delta = isCurrentlyScrollingWithVerticalScrollWheel
? deltaY
: deltaX;
const delta = isCurrentlyScrollingWithVerticalScrollWheel ? deltaY : deltaX;

// Calculate a single scroll jump relative to the range scale
let diff = ((delta / 120) * (this.range.end - this.range.start)) / 20;
// Calculate visual range (excluding hidden periods) for consistent scroll speed
const absoluteRange = this.range.end - this.range.start;
const hiddenDuration = DateUtil.getHiddenDurationBetween(this.body.hiddenDates, this.range.start, this.range.end);
const visualRange = absoluteRange - hiddenDuration;
let diff = delta / 120 * visualRange / 20;

// Invert scroll direction
// ...unless the user uses a horizontal mouse-wheel as found on the "Logi Master" series.
Expand All @@ -298,17 +299,27 @@ class Core {
)
diff = -diff;

// calculate new start and end
const newStart = this.range.start + diff;
const newEnd = this.range.end + diff;
const options = {
animation: false,
byUser: true,
event: event,
};
this.range.setRange(newStart, newEnd, options);

event.preventDefault();
// Apply visual shift preserving visual span (like pinch-to-zoom does)
const currentVisualSpan = visualRange;
let newStart = this.range.start + diff;
let newEnd = this.range.end + diff;

// If crossing hidden boundaries, preserve visual span
const newHiddenDuration = DateUtil.getHiddenDurationBetween(this.body.hiddenDates, newStart, newEnd);
const newAbsoluteSpan = currentVisualSpan + newHiddenDuration;
newEnd = newStart + newAbsoluteSpan;

// snapping times away from hidden zones (same as pinch-to-zoom)
const safeStart = DateUtil.snapAwayFromHidden(this.body.hiddenDates, newStart, diff, true);
const safeEnd = DateUtil.snapAwayFromHidden(this.body.hiddenDates, newEnd, -diff, true);

const options = {
animation: false,
byUser: true,
event: event
};
this.range.setRange(safeStart, safeEnd, options);
event.preventDefault();

// Here in case of any future behaviour following after
return;
Expand Down