From 054ae4643f3c4391e64a009bddd6e2de0fe4fd13 Mon Sep 17 00:00:00 2001 From: Chris Bilodeau <7334990+chrisbilodeau@users.noreply.github.com> Date: Fri, 3 Jan 2025 16:44:30 -0700 Subject: [PATCH 1/3] fix: use mod for default keybinds mod evaluates to ctrl on Windows/Linux and cmd on MacOS fixes https://github.com/franciscoBSalgueiro/en-croissant/issues/338 --- src/state/keybinds.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/state/keybinds.ts b/src/state/keybinds.ts index 7fdbf1ff..a03a419b 100644 --- a/src/state/keybinds.ts +++ b/src/state/keybinds.ts @@ -5,12 +5,12 @@ import type { } from "jotai/vanilla/utils/atomWithStorage"; const keys = { - NEW_TAB: { name: "New tab", keys: "ctrl+t" }, - CLOSE_TAB: { name: "Close tab", keys: "ctrl+w" }, - OPEN_FILE: { name: "Open File", keys: "ctrl+o" }, - SAVE_FILE: { name: "Save File", keys: "ctrl+s" }, + NEW_TAB: { name: "New tab", keys: "mod+t" }, + CLOSE_TAB: { name: "Close tab", keys: "mod+w" }, + OPEN_FILE: { name: "Open File", keys: "mod+o" }, + SAVE_FILE: { name: "Save File", keys: "mod+s" }, SWAP_ORIENTATION: { name: "Swap orientation", keys: "f" }, - CLEAR_SHAPES: { name: "Clear shapes", keys: "ctrl+l" }, + CLEAR_SHAPES: { name: "Clear shapes", keys: "mod+l" }, NEXT_MOVE: { name: "Next move", keys: "arrowright" }, PREVIOUS_MOVE: { name: "Previous move", keys: "arrowleft" }, GO_TO_BRANCH_START: { name: "Go to start of branch", keys: "arrowup" }, @@ -42,8 +42,8 @@ const keys = { ANNOTATION_DUBIOUS: { name: "Toggle dubious move annotation", keys: "4" }, ANNOTATION_MISTAKE: { name: "Toggle mistake move annotation", keys: "5" }, ANNOTATION_BLUNDER: { name: "Toggle blunder move annotation", keys: "6" }, - TOGGLE_ALL_ENGINES: { name: "Toggle all engines", keys: "ctrl+a" }, - TOGGLE_BLUR: { name: "Toggle blur", keys: "ctrl+b" }, + TOGGLE_ALL_ENGINES: { name: "Toggle all engines", keys: "mod+a" }, + TOGGLE_BLUR: { name: "Toggle blur", keys: "mod+b" }, PREVIOUS_GAME: { name: "Previous game", keys: "pageup" }, NEXT_GAME: { name: "Next game", keys: "pagedown" }, }; From 9187102dac800979a04410c16c62f776910f166f Mon Sep 17 00:00:00 2001 From: Chris Bilodeau <7334990+chrisbilodeau@users.noreply.github.com> Date: Mon, 6 Jan 2025 11:37:05 -0700 Subject: [PATCH 2/3] fix: use mod for board tab keybinds and make them configurable --- src/components/tabs/BoardsPage.tsx | 33 +++++++++++------------------- src/routes/__root.tsx | 4 ++-- src/state/keybinds.ts | 20 ++++++++++++++---- 3 files changed, 30 insertions(+), 27 deletions(-) diff --git a/src/components/tabs/BoardsPage.tsx b/src/components/tabs/BoardsPage.tsx index 37fd6a9b..8b38b5b3 100644 --- a/src/components/tabs/BoardsPage.tsx +++ b/src/components/tabs/BoardsPage.tsx @@ -131,27 +131,18 @@ export default function BoardsPage() { const keyMap = useAtomValue(keyMapAtom); useHotkeys([ - [keyMap.CLOSE_TAB.keys, () => closeTab(activeTab)], - [keyMap.CYCLE_TABS.keys, () => cycleTabs()], - [keyMap.REVERSE_CYCLE_TABS.keys, () => cycleTabs(true)], - ["alt+1", () => selectTab(0)], - ["ctrl+1", () => selectTab(0)], - ["alt+2", () => selectTab(1)], - ["ctrl+2", () => selectTab(1)], - ["alt+3", () => selectTab(2)], - ["ctrl+3", () => selectTab(2)], - ["alt+4", () => selectTab(3)], - ["ctrl+4", () => selectTab(3)], - ["alt+5", () => selectTab(4)], - ["ctrl+5", () => selectTab(4)], - ["alt+6", () => selectTab(5)], - ["ctrl+6", () => selectTab(5)], - ["alt+7", () => selectTab(6)], - ["ctrl+7", () => selectTab(6)], - ["alt+8", () => selectTab(7)], - ["ctrl+8", () => selectTab(7)], - ["alt+9", () => selectTab(tabs.length - 1)], - ["ctrl+9", () => selectTab(tabs.length - 1)], + [keyMap.CLOSE_BOARD_TAB.keys, () => closeTab(activeTab)], + [keyMap.CYCLE_BOARD_TABS.keys, () => cycleTabs()], + [keyMap.REVERSE_CYCLE_BOARD_TABS.keys, () => cycleTabs(true)], + [keyMap.BOARD_TAB_ONE.keys, () => selectTab(0)], + [keyMap.BOARD_TAB_TWO.keys, () => selectTab(1)], + [keyMap.BOARD_TAB_THREE.keys, () => selectTab(2)], + [keyMap.BOARD_TAB_FOUR.keys, () => selectTab(3)], + [keyMap.BOARD_TAB_FIVE.keys, () => selectTab(4)], + [keyMap.BOARD_TAB_SIX.keys, () => selectTab(5)], + [keyMap.BOARD_TAB_SEVEN.keys, () => selectTab(6)], + [keyMap.BOARD_TAB_EIGHT.keys, () => selectTab(7)], + [keyMap.BOARD_TAB_LAST.keys, () => selectTab(tabs.length - 1)], ]); return ( diff --git a/src/routes/__root.tsx b/src/routes/__root.tsx index c7415eed..223317fb 100644 --- a/src/routes/__root.tsx +++ b/src/routes/__root.tsx @@ -131,7 +131,7 @@ function RootLayout() { const [keyMap] = useAtom(keyMapAtom); - useHotkeys(keyMap.NEW_TAB.keys, createNewTab); + useHotkeys(keyMap.NEW_BOARD_TAB.keys, createNewTab); useHotkeys(keyMap.OPEN_FILE.keys, openNewFile); const [opened, setOpened] = useState(false); @@ -143,7 +143,7 @@ function RootLayout() { { label: t("Menu.File.NewTab"), id: "new_tab", - shortcut: keyMap.NEW_TAB.keys, + shortcut: keyMap.NEW_BOARD_TAB.keys, action: createNewTab, }, { diff --git a/src/state/keybinds.ts b/src/state/keybinds.ts index a03a419b..2b6a834f 100644 --- a/src/state/keybinds.ts +++ b/src/state/keybinds.ts @@ -5,10 +5,24 @@ import type { } from "jotai/vanilla/utils/atomWithStorage"; const keys = { - NEW_TAB: { name: "New tab", keys: "mod+t" }, - CLOSE_TAB: { name: "Close tab", keys: "mod+w" }, OPEN_FILE: { name: "Open File", keys: "mod+o" }, SAVE_FILE: { name: "Save File", keys: "mod+s" }, + NEW_BOARD_TAB: { name: "New board tab", keys: "mod+t" }, + CLOSE_BOARD_TAB: { name: "Close board tab", keys: "mod+w" }, + BOARD_TAB_ONE: { name: "Go to board tab one", keys: "mod+1" }, + BOARD_TAB_TWO: { name: "Go to board tab two", keys: "mod+2" }, + BOARD_TAB_THREE: { name: "Go to board tab three", keys: "mod+3" }, + BOARD_TAB_FOUR: { name: "Go to board tab four", keys: "mod+4" }, + BOARD_TAB_FIVE: { name: "Go to board tab five", keys: "mod+5" }, + BOARD_TAB_SIX: { name: "Go to board tab six", keys: "mod+6" }, + BOARD_TAB_SEVEN: { name: "Go to board tab seven", keys: "mod+7" }, + BOARD_TAB_EIGHT: { name: "Go to board tab eight", keys: "mod+8" }, + BOARD_TAB_LAST: { name: "Go to rightmost board tab", keys: "mod+9" }, + CYCLE_BOARD_TABS: { name: "Cycle board tabs", keys: "ctrl+tab" }, + REVERSE_CYCLE_BOARD_TABS: { + name: "Reverse cycle board tabs", + keys: "ctrl+shift+tab", + }, SWAP_ORIENTATION: { name: "Swap orientation", keys: "f" }, CLEAR_SHAPES: { name: "Clear shapes", keys: "mod+l" }, NEXT_MOVE: { name: "Next move", keys: "arrowright" }, @@ -25,8 +39,6 @@ const keys = { keys: "shift+arrowleft", }, DELETE_MOVE: { name: "Delete move", keys: "delete" }, - CYCLE_TABS: { name: "Cycle tabs", keys: "ctrl+tab" }, - REVERSE_CYCLE_TABS: { name: "Reverse cycle tabs", keys: "ctrl+shift+tab" }, TOGGLE_EVAL_BAR: { name: "Toggle Eval Bar and Arrows", keys: "z" }, PRACTICE_TAB: { name: "Go to practice tab", keys: "p" }, ANALYSIS_TAB: { name: "Go to analysis tab", keys: "a" }, From 0cbba1e09faac396f284170000fd9ed12eb6cc0f Mon Sep 17 00:00:00 2001 From: Chris Bilodeau <7334990+chrisbilodeau@users.noreply.github.com> Date: Mon, 6 Jan 2025 11:38:15 -0700 Subject: [PATCH 3/3] feat: add keybind to exit the app Technically for MacOS it should be 'quit' instead of 'exit' but using exit keeps it consistent to the current app and translations. --- src/routes/__root.tsx | 1 + src/state/keybinds.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/src/routes/__root.tsx b/src/routes/__root.tsx index 223317fb..15f90466 100644 --- a/src/routes/__root.tsx +++ b/src/routes/__root.tsx @@ -133,6 +133,7 @@ function RootLayout() { useHotkeys(keyMap.NEW_BOARD_TAB.keys, createNewTab); useHotkeys(keyMap.OPEN_FILE.keys, openNewFile); + useHotkeys(keyMap.EXIT_APP.keys, () => exit(0)); const [opened, setOpened] = useState(false); const menuActions: MenuGroup[] = useMemo( diff --git a/src/state/keybinds.ts b/src/state/keybinds.ts index 2b6a834f..fbdfede7 100644 --- a/src/state/keybinds.ts +++ b/src/state/keybinds.ts @@ -7,6 +7,7 @@ import type { const keys = { OPEN_FILE: { name: "Open File", keys: "mod+o" }, SAVE_FILE: { name: "Save File", keys: "mod+s" }, + EXIT_APP: { name: "Exit En-Croissant", keys: "mod+q" }, NEW_BOARD_TAB: { name: "New board tab", keys: "mod+t" }, CLOSE_BOARD_TAB: { name: "Close board tab", keys: "mod+w" }, BOARD_TAB_ONE: { name: "Go to board tab one", keys: "mod+1" },