-
Notifications
You must be signed in to change notification settings - Fork 911
hotkey pane #108
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
Merged
Merged
hotkey pane #108
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c5fdefe
add shortcut hooks
Kitenite 05d65d1
fix stores
Kitenite bd7604d
fix hotkeys store
Kitenite 81b25e7
fix hotkeys
Kitenite e4181bd
update store
Kitenite 7dc1834
main compat
Kitenite ac1f52e
merge main
Kitenite File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| import { useEffect, useMemo } from "react"; | ||
| import { createShortcutHandler } from "../lib/keyboard-shortcuts"; | ||
| import { | ||
| createSplitPaneShortcuts, | ||
| createTabShortcuts, | ||
| createWorkspaceShortcuts, | ||
| } from "../lib/shortcuts"; | ||
| import { useSidebarStore } from "../stores/sidebar-state"; | ||
| import { | ||
| useActiveTabIds, | ||
| useAddTab, | ||
| useRemoveTab, | ||
| useSetActiveTab, | ||
| useSplitTabHorizontal, | ||
| useSplitTabVertical, | ||
| useTabs, | ||
| } from "../stores/tabs"; | ||
| import { useWorkspacesStore } from "../stores/workspaces"; | ||
|
|
||
| function findWorkspaceIndex( | ||
| workspaces: Array<{ id: string }>, | ||
| id: string | null, | ||
| ) { | ||
| if (!id) return -1; | ||
| return workspaces.findIndex((w) => w.id === id); | ||
| } | ||
|
|
||
| function findTabIndex(tabs: Array<{ id: string }>, id: string | null) { | ||
| if (!id) return -1; | ||
| return tabs.findIndex((t) => t.id === id); | ||
| } | ||
|
|
||
| export function useGlobalShortcuts() { | ||
| const { workspaces, activeWorkspaceId, setActiveWorkspace } = | ||
| useWorkspacesStore(); | ||
| const { toggleSidebar } = useSidebarStore(); | ||
| const tabs = useTabs(); | ||
| const activeTabIds = useActiveTabIds(); | ||
| const setActiveTab = useSetActiveTab(); | ||
| const addTab = useAddTab(); | ||
| const removeTab = useRemoveTab(); | ||
| const splitTabVertical = useSplitTabVertical(); | ||
| const splitTabHorizontal = useSplitTabHorizontal(); | ||
|
|
||
| const workspaceTabs = useMemo(() => { | ||
| if (!activeWorkspaceId) return []; | ||
| return tabs.filter( | ||
| (t) => t.workspaceId === activeWorkspaceId && !t.parentId, | ||
| ); | ||
| }, [tabs, activeWorkspaceId]); | ||
|
|
||
| const activeTabId = activeWorkspaceId | ||
| ? activeTabIds[activeWorkspaceId] | ||
| : null; | ||
|
|
||
| useEffect(() => { | ||
| const workspaceHandlers = { | ||
| switchToPrevWorkspace: () => { | ||
| if (!activeWorkspaceId) return; | ||
| const index = findWorkspaceIndex(workspaces, activeWorkspaceId); | ||
| if (index > 0) { | ||
| setActiveWorkspace(workspaces[index - 1].id); | ||
| } | ||
| }, | ||
| switchToNextWorkspace: () => { | ||
| if (!activeWorkspaceId) return; | ||
| const index = findWorkspaceIndex(workspaces, activeWorkspaceId); | ||
| if (index < workspaces.length - 1) { | ||
| setActiveWorkspace(workspaces[index + 1].id); | ||
| } | ||
| }, | ||
| toggleSidebar, | ||
| splitVertical: () => { | ||
| if (activeWorkspaceId) { | ||
| splitTabVertical(activeWorkspaceId); | ||
| } | ||
| }, | ||
| splitHorizontal: () => { | ||
| if (activeWorkspaceId) { | ||
| splitTabHorizontal(activeWorkspaceId); | ||
| } | ||
| }, | ||
| }; | ||
|
|
||
| const tabHandlers = { | ||
| switchToPrevTab: () => { | ||
| if (!activeWorkspaceId || !activeTabId) return; | ||
| const index = findTabIndex(workspaceTabs, activeTabId); | ||
| if (index > 0) { | ||
| setActiveTab(activeWorkspaceId, workspaceTabs[index - 1].id); | ||
| } | ||
| }, | ||
| switchToNextTab: () => { | ||
| if (!activeWorkspaceId || !activeTabId) return; | ||
| const index = findTabIndex(workspaceTabs, activeTabId); | ||
| if (index < workspaceTabs.length - 1) { | ||
| setActiveTab(activeWorkspaceId, workspaceTabs[index + 1].id); | ||
| } | ||
| }, | ||
| newTab: () => { | ||
| if (activeWorkspaceId) { | ||
| addTab(activeWorkspaceId); | ||
| } | ||
| }, | ||
| closeTab: () => { | ||
| if (activeTabId) { | ||
| removeTab(activeTabId); | ||
| } | ||
| }, | ||
| reopenClosedTab: () => { | ||
| console.log("Reopen closed tab"); | ||
| }, | ||
| jumpToTab: (index: number) => { | ||
| if (!activeWorkspaceId) return; | ||
| const targetTab = workspaceTabs[index - 1]; | ||
| if (targetTab) { | ||
| setActiveTab(activeWorkspaceId, targetTab.id); | ||
| } | ||
| }, | ||
| }; | ||
|
|
||
| const splitPaneHandlers = { | ||
| focusPaneLeft: () => console.log("Focus pane left"), | ||
| focusPaneRight: () => console.log("Focus pane right"), | ||
| focusPaneUp: () => console.log("Focus pane up"), | ||
| focusPaneDown: () => console.log("Focus pane down"), | ||
| }; | ||
|
|
||
| const workspaceShortcuts = createWorkspaceShortcuts(workspaceHandlers); | ||
| const tabShortcuts = createTabShortcuts(tabHandlers); | ||
| const splitPaneShortcuts = createSplitPaneShortcuts(splitPaneHandlers); | ||
|
|
||
| const allShortcuts = [ | ||
| ...workspaceShortcuts.shortcuts, | ||
| ...tabShortcuts.shortcuts, | ||
| ...splitPaneShortcuts.shortcuts, | ||
| ]; | ||
|
|
||
| const handleKeyDown = createShortcutHandler(allShortcuts); | ||
| window.addEventListener("keydown", handleKeyDown); | ||
|
|
||
| return () => { | ||
| window.removeEventListener("keydown", handleKeyDown); | ||
| }; | ||
| }, [ | ||
| workspaces, | ||
| activeWorkspaceId, | ||
| workspaceTabs, | ||
| activeTabId, | ||
| setActiveWorkspace, | ||
| toggleSidebar, | ||
| setActiveTab, | ||
| addTab, | ||
| removeTab, | ||
| splitTabVertical, | ||
| splitTabHorizontal, | ||
| ]); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical: Shortcut key conflicts with workspace and tab navigation.
The pane navigation shortcuts conflict with existing shortcuts:
When all shortcuts are registered together in
useGlobalShortcuts, only the first matching shortcut will fire, making either workspace/tab navigation or pane navigation inaccessible.Consider using different modifiers for pane navigation, such as:
Apply this diff for Option 1:
export function createSplitPaneShortcuts( handlers: Pick< ShortcutHandlers, "focusPaneLeft" | "focusPaneRight" | "focusPaneUp" | "focusPaneDown" >, ): KeyboardShortcutGroup { return { name: "Split Pane Navigation", shortcuts: [ { key: "ArrowLeft", - modifiers: ["meta", "alt"], + modifiers: ["meta", "alt", "ctrl"], description: "Focus left pane", handler: (event) => { event.preventDefault(); handlers.focusPaneLeft(); return false; }, }, { key: "ArrowRight", - modifiers: ["meta", "alt"], + modifiers: ["meta", "alt", "ctrl"], description: "Focus right pane", handler: (event) => { event.preventDefault(); handlers.focusPaneRight(); return false; }, }, { key: "ArrowUp", - modifiers: ["meta", "alt"], + modifiers: ["meta", "alt", "ctrl"], description: "Focus upper pane", handler: (event) => { event.preventDefault(); handlers.focusPaneUp(); return false; }, }, { key: "ArrowDown", - modifiers: ["meta", "alt"], + modifiers: ["meta", "alt", "ctrl"], description: "Focus lower pane", handler: (event) => { event.preventDefault(); handlers.focusPaneDown(); return false; }, }, ], }; }📝 Committable suggestion
🤖 Prompt for AI Agents