-
Notifications
You must be signed in to change notification settings - Fork 990
feat(desktop/hotkeys): unbound defaults + restore prev/next tab & workspace #3422
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||||||||||||||||||||||||||||||||||||||
| import { useNavigate } from "@tanstack/react-router"; | ||||||||||||||||||||||||||||||||||||||||||
| import { useMatchRoute, useNavigate } from "@tanstack/react-router"; | ||||||||||||||||||||||||||||||||||||||||||
| import { useCallback, useMemo } from "react"; | ||||||||||||||||||||||||||||||||||||||||||
| import { useHotkey } from "renderer/hotkeys"; | ||||||||||||||||||||||||||||||||||||||||||
| import { navigateToV2Workspace } from "renderer/routes/_authenticated/_dashboard/utils/workspace-navigation"; | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -48,5 +48,33 @@ export function useDashboardSidebarShortcuts( | |||||||||||||||||||||||||||||||||||||||||
| useHotkey("JUMP_TO_WORKSPACE_8", () => switchToWorkspace(7)); | ||||||||||||||||||||||||||||||||||||||||||
| useHotkey("JUMP_TO_WORKSPACE_9", () => switchToWorkspace(8)); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| const matchRoute = useMatchRoute(); | ||||||||||||||||||||||||||||||||||||||||||
| const currentWorkspaceMatch = matchRoute({ | ||||||||||||||||||||||||||||||||||||||||||
| to: "/v2-workspace/$workspaceId", | ||||||||||||||||||||||||||||||||||||||||||
| fuzzy: true, | ||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||
| const currentWorkspaceId = | ||||||||||||||||||||||||||||||||||||||||||
| currentWorkspaceMatch !== false ? currentWorkspaceMatch.workspaceId : null; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| useHotkey("PREV_WORKSPACE", () => { | ||||||||||||||||||||||||||||||||||||||||||
| if (!currentWorkspaceId || flattenedWorkspaces.length === 0) return; | ||||||||||||||||||||||||||||||||||||||||||
| const index = flattenedWorkspaces.findIndex( | ||||||||||||||||||||||||||||||||||||||||||
| (w) => w.id === currentWorkspaceId, | ||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||
| if (index === -1) return; | ||||||||||||||||||||||||||||||||||||||||||
| const prevIndex = index <= 0 ? flattenedWorkspaces.length - 1 : index - 1; | ||||||||||||||||||||||||||||||||||||||||||
| navigateToV2Workspace(flattenedWorkspaces[prevIndex].id, navigate); | ||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+59
to
+67
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Consider mirroring the explicit
Suggested change
Alternatively, bail out when |
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| useHotkey("NEXT_WORKSPACE", () => { | ||||||||||||||||||||||||||||||||||||||||||
| if (!currentWorkspaceId || flattenedWorkspaces.length === 0) return; | ||||||||||||||||||||||||||||||||||||||||||
| const index = flattenedWorkspaces.findIndex( | ||||||||||||||||||||||||||||||||||||||||||
| (w) => w.id === currentWorkspaceId, | ||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||
| if (index === -1) return; | ||||||||||||||||||||||||||||||||||||||||||
| const nextIndex = index >= flattenedWorkspaces.length - 1 ? 0 : index + 1; | ||||||||||||||||||||||||||||||||||||||||||
| navigateToV2Workspace(flattenedWorkspaces[nextIndex].id, navigate); | ||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| return workspaceShortcutLabels; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import type { ExternalApp } from "@superset/local-db"; | ||
| import { createFileRoute, notFound } from "@tanstack/react-router"; | ||
| import { createFileRoute, notFound, useNavigate } from "@tanstack/react-router"; | ||
| import { useCallback, useEffect, useMemo, useState } from "react"; | ||
| import { useCopyToClipboard } from "renderer/hooks/useCopyToClipboard"; | ||
| import { useFileOpenMode } from "renderer/hooks/useFileOpenMode"; | ||
|
|
@@ -8,6 +8,7 @@ import { electronTrpc } from "renderer/lib/electron-trpc"; | |
| import { electronTrpcClient as trpcClient } from "renderer/lib/trpc-client"; | ||
| import { usePresets } from "renderer/react-query/presets"; | ||
| import type { WorkspaceSearchParams } from "renderer/routes/_authenticated/_dashboard/utils/workspace-navigation"; | ||
| import { navigateToWorkspace } from "renderer/routes/_authenticated/_dashboard/utils/workspace-navigation"; | ||
| import { usePresetHotkeys } from "renderer/routes/_authenticated/_dashboard/workspace/$workspaceId/hooks/usePresetHotkeys"; | ||
| import { useWorkspaceRunCommand } from "renderer/routes/_authenticated/_dashboard/workspace/$workspaceId/hooks/useWorkspaceRunCommand"; | ||
| import { NotFound } from "renderer/routes/not-found"; | ||
|
|
@@ -90,6 +91,7 @@ function WorkspacePage() { | |
| worktreePath: workspace?.worktreePath, | ||
| enabled: Boolean(workspace?.worktreePath), | ||
| }); | ||
| const navigate = useNavigate(); | ||
| const routeNavigate = Route.useNavigate(); | ||
| const { tabId: searchTabId, paneId: searchPaneId } = Route.useSearch(); | ||
|
|
||
|
|
@@ -224,6 +226,20 @@ function WorkspacePage() { | |
| } | ||
| }); | ||
|
|
||
| useHotkey("PREV_TAB", () => { | ||
| if (!activeTabId || tabs.length === 0) return; | ||
| const index = tabs.findIndex((t) => t.id === activeTabId); | ||
| const prevIndex = index <= 0 ? tabs.length - 1 : index - 1; | ||
| setActiveTab(workspaceId, tabs[prevIndex].id); | ||
| }); | ||
|
|
||
| useHotkey("NEXT_TAB", () => { | ||
| if (!activeTabId || tabs.length === 0) return; | ||
| const index = tabs.findIndex((t) => t.id === activeTabId); | ||
| const nextIndex = index >= tabs.length - 1 || index === -1 ? 0 : index + 1; | ||
| setActiveTab(workspaceId, tabs[nextIndex].id); | ||
| }); | ||
|
|
||
| useHotkey("PREV_TAB_ALT", () => { | ||
| if (!activeTabId || tabs.length === 0) return; | ||
| const index = tabs.findIndex((t) => t.id === activeTabId); | ||
|
|
@@ -393,6 +409,29 @@ function WorkspacePage() { | |
| } | ||
| }); | ||
|
|
||
| const getPreviousWorkspace = | ||
| electronTrpc.workspaces.getPreviousWorkspace.useQuery( | ||
| { id: workspaceId }, | ||
| { enabled: !!workspaceId }, | ||
| ); | ||
| useHotkey("PREV_WORKSPACE", () => { | ||
| const prevWorkspaceId = getPreviousWorkspace.data; | ||
| if (prevWorkspaceId) { | ||
| navigateToWorkspace(prevWorkspaceId, navigate); | ||
| } | ||
| }); | ||
|
|
||
| const getNextWorkspace = electronTrpc.workspaces.getNextWorkspace.useQuery( | ||
| { id: workspaceId }, | ||
| { enabled: !!workspaceId }, | ||
| ); | ||
| useHotkey("NEXT_WORKSPACE", () => { | ||
| const nextWorkspaceId = getNextWorkspace.data; | ||
| if (nextWorkspaceId) { | ||
| navigateToWorkspace(nextWorkspaceId, navigate); | ||
| } | ||
|
Comment on lines
+412
to
+432
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
A minimal improvement is to check Also: |
||
| }); | ||
|
|
||
| return ( | ||
| <div className="flex-1 h-full flex flex-col overflow-hidden"> | ||
| <div className="flex-1 min-h-0 flex overflow-hidden"> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.