Fix workspace shortcut navigation
This commit is contained in:
@@ -1,13 +1,11 @@
|
||||
import { useEffect, useMemo, useRef } from "react";
|
||||
import { usePathname, useRouter } from "expo-router";
|
||||
import { getIsElectronRuntime } from "@/constants/layout";
|
||||
import { useHosts } from "@/runtime/host-runtime";
|
||||
import { useKeyboardShortcutsStore } from "@/stores/keyboard-shortcuts-store";
|
||||
import { setCommandCenterFocusRestoreElement } from "@/utils/command-center-focus-restore";
|
||||
import {
|
||||
buildSettingsRoute,
|
||||
parseHostAgentRouteFromPathname,
|
||||
parseServerIdFromPathname,
|
||||
parseHostWorkspaceRouteFromPathname,
|
||||
} from "@/utils/host-routes";
|
||||
import { navigateToWorkspace } from "@/hooks/use-workspace-navigation";
|
||||
@@ -27,6 +25,9 @@ import { useOpenProjectPicker } from "@/hooks/use-open-project-picker";
|
||||
import { useKeyboardShortcutOverrides } from "@/hooks/use-keyboard-shortcut-overrides";
|
||||
import { isNative } from "@/constants/platform";
|
||||
import { isImeComposingKeyboardEvent } from "@/utils/keyboard-ime";
|
||||
import { getRelativeSidebarShortcutTarget } from "@/utils/sidebar-shortcuts";
|
||||
import { useActiveServerId } from "@/hooks/use-active-server-id";
|
||||
import { getNavigationActiveWorkspaceSelection } from "@/stores/navigation-active-workspace-store";
|
||||
|
||||
export function useKeyboardShortcuts({
|
||||
enabled,
|
||||
@@ -45,7 +46,6 @@ export function useKeyboardShortcuts({
|
||||
}) {
|
||||
const pathname = usePathname();
|
||||
const router = useRouter();
|
||||
const hosts = useHosts();
|
||||
const resetModifiers = useKeyboardShortcutsStore((s) => s.resetModifiers);
|
||||
const { overrides } = useKeyboardShortcutOverrides();
|
||||
const bindings = useMemo(() => buildEffectiveBindings(overrides), [overrides]);
|
||||
@@ -54,11 +54,7 @@ export function useKeyboardShortcuts({
|
||||
step: 0,
|
||||
timeoutId: null,
|
||||
});
|
||||
const activeServerIdFromPath = parseServerIdFromPathname(pathname);
|
||||
const activeServerId =
|
||||
hosts.find((host) => host.serverId === activeServerIdFromPath)?.serverId ??
|
||||
hosts[0]?.serverId ??
|
||||
null;
|
||||
const activeServerId = useActiveServerId();
|
||||
const openProjectPickerAction = useOpenProjectPicker(activeServerId);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -87,31 +83,23 @@ export function useKeyboardShortcuts({
|
||||
};
|
||||
const navigateRelativeWorkspace = (delta: 1 | -1): boolean => {
|
||||
const state = useKeyboardShortcutsStore.getState();
|
||||
const targets = state.visibleWorkspaceTargets;
|
||||
const targets = state.sidebarShortcutWorkspaceTargets;
|
||||
if (targets.length === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const workspaceRoute = parseHostWorkspaceRouteFromPathname(pathname);
|
||||
if (!workspaceRoute) {
|
||||
const fallback = targets[delta > 0 ? 0 : targets.length - 1] ?? null;
|
||||
if (!fallback) {
|
||||
return false;
|
||||
}
|
||||
navigateToWorkspace(fallback.serverId, fallback.workspaceId, {
|
||||
currentPathname: pathname,
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
const currentIndex = targets.findIndex(
|
||||
(target) =>
|
||||
target.serverId === workspaceRoute.serverId &&
|
||||
target.workspaceId === workspaceRoute.workspaceId,
|
||||
);
|
||||
const fromIndex = currentIndex >= 0 ? currentIndex : delta > 0 ? -1 : 0;
|
||||
const nextIndex = (fromIndex + delta + targets.length) % targets.length;
|
||||
const target = targets[nextIndex] ?? null;
|
||||
const workspaceRoute =
|
||||
getNavigationActiveWorkspaceSelection() ?? parseHostWorkspaceRouteFromPathname(pathname);
|
||||
const target = getRelativeSidebarShortcutTarget({
|
||||
targets,
|
||||
currentTarget: workspaceRoute
|
||||
? {
|
||||
serverId: workspaceRoute.serverId,
|
||||
workspaceId: workspaceRoute.workspaceId,
|
||||
}
|
||||
: null,
|
||||
delta,
|
||||
});
|
||||
if (!target) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user