Skip to content
Merged
Show file tree
Hide file tree
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
17 changes: 14 additions & 3 deletions src/features/rap/Hours.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Errors from "./Errors";
import { useAppSelector } from "../../hooks";
import { WindsAloftHour } from "../../models/WindsAloft";
import { OnOff } from "./extra/settings/settingEnums";
import { isApplePlatform } from "../../helpers/device";

const browser = detect();

Expand Down Expand Up @@ -162,6 +163,18 @@ interface TableProps {
hours: WindsAloftHour[];
}

function determineScrollBehaviorByModifierKey(e: KeyboardEvent): Distance {
if (isApplePlatform()) {
if (e.metaKey) return Distance.End;
if (e.altKey) return Distance.Page;
return Distance.Hour;
}

if (e.ctrlKey) return Distance.End;
if (e.altKey || e.metaKey) return Distance.Page;
return Distance.Hour;
}

export default function Hours({ hours }: TableProps) {
const elevation = useAppSelector((state) => state.weather.elevation);

Expand Down Expand Up @@ -205,9 +218,7 @@ export default function Hours({ hours }: TableProps) {
const callback = (e: KeyboardEvent) => {
if (!scrollViewRef.current) return;

let distance = Distance.Hour;
if (e.metaKey) distance = Distance.End;
if (e.altKey) distance = Distance.Page;
const distance = determineScrollBehaviorByModifierKey(e);

switch (e.key) {
case "ArrowLeft":
Expand Down
4 changes: 4 additions & 0 deletions src/helpers/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ export function isMobile() {
);
}

export function isApplePlatform(): boolean {
return /Mac|iPhone|iPad/.test(navigator.userAgent);
}

/**
* Important: Must check to make sure UA is Safari first
*/
Expand Down
Loading