Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add scroll to navigate functionality #2855

Merged
merged 1 commit into from
Oct 21, 2024
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
5 changes: 4 additions & 1 deletion src/components/GobanContainer/GobanContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ interface GobanContainerProps {
goban?: GobanRenderer;
/** callback that is called when the goban detects a resize. */
onResize?: () => void;
/** callback that is called when user scrolls on goban container. */
onWheel?: React.WheelEventHandler<HTMLDivElement> | undefined;
/** Additional props to pass to the PersistentElement that wraps the goban_div */
extra_props?: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>;
}
Expand All @@ -39,6 +41,7 @@ interface GobanContainerProps {
export function GobanContainer({
goban,
onResize: onResizeCb,
onWheel,
extra_props,
}: GobanContainerProps): JSX.Element {
const ref_goban_container = React.useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -119,7 +122,7 @@ export function GobanContainer({
}

return (
<div ref={ref_goban_container} className="goban-container">
<div ref={ref_goban_container} className="goban-container" onWheel={onWheel}>
<OgsResizeDetector onResize={onResize} targetRef={ref_goban_container} />
<PersistentElement className="Goban" elt={goban_div} extra_props={extra_props} />
</div>
Expand Down
1 change: 1 addition & 0 deletions src/lib/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export const defaults = {
"unicode-filter": false,
"variations-in-chat-enabled": true,
"start-in-zen-mode": false,
"scroll-to-navigate": false,
"show-empty-chat-notification": true,
"chat-subscribe-group-chat-unread": true,
"chat-subscribe-group-mentions": true,
Expand Down
25 changes: 24 additions & 1 deletion src/views/Game/Game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ export function Game(): JSX.Element | null {
const [ai_review_enabled, set_ai_review_enabled] = React.useState(
preferences.get("ai-review-enabled"),
);
const [scroll_to_navigate, _setScrollToNavigate] = React.useState(
preferences.get("scroll-to-navigate"),
);
const [phase, set_phase] = React.useState<GobanEnginePhase>();
const [selected_ai_review_uuid, set_selected_ai_review_uuid] = React.useState<string | null>(
null,
Expand Down Expand Up @@ -408,6 +411,22 @@ export function Game(): JSX.Element | null {
},
[set_squashed, set_view_mode, squashed, view_mode],
);

const onWheel: React.WheelEventHandler<HTMLDivElement> = React.useCallback(
(event) => {
if (!scroll_to_navigate) {
return;
}

if (event.deltaY > 0) {
nav_next();
} else if (event.deltaY < 0) {
nav_prev();
}
},
[scroll_to_navigate],
);

const setAnalyzeTool = (tool: AnalysisTool | "erase", subtool: string) => {
if (!goban.current) {
return false;
Expand Down Expand Up @@ -1720,7 +1739,11 @@ export function Game(): JSX.Element | null {
{frag_rengo_header()}
</div>
)}
<GobanContainer goban={goban.current} onResize={onResize} />
<GobanContainer
goban={goban.current}
onResize={onResize}
onWheel={onWheel}
/>

{frag_below_board_controls()}

Expand Down
8 changes: 8 additions & 0 deletions src/views/Settings/GamePreferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export function GamePreferences(): JSX.Element {
);
const [variation_move_count, _setVariationMoveCount] = usePreference("variation-move-count");
const [zen_mode_by_default, _setZenModeByDefault] = usePreference("start-in-zen-mode");
const [scroll_to_navigate, setScrollToNavigate] = usePreference("scroll-to-navigate");

function setDockDelay(ev: React.ChangeEvent<HTMLInputElement>) {
const new_delay = parseFloat(ev.target.value);
Expand Down Expand Up @@ -281,6 +282,13 @@ export function GamePreferences(): JSX.Element {
})}
</span>
</PreferenceLine>

<PreferenceLine
title={_("Scroll to navigate")}
description={_("Scroll mousewheel to navigate moves on the game page")}
>
<Toggle checked={scroll_to_navigate} onChange={setScrollToNavigate} />
</PreferenceLine>
</div>
);
}
Loading