Skip to content

Commit 7340c60

Browse files
committed
Open active file in external app instead of repo directory
1 parent 8a8f837 commit 7340c60

2 files changed

Lines changed: 43 additions & 6 deletions

File tree

apps/code/src/renderer/features/task-detail/components/ExternalAppsOpener.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ChevronDownIcon } from "@radix-ui/react-icons";
44
import { Button, DropdownMenu, Flex, Text } from "@radix-ui/themes";
55
import { SHORTCUTS } from "@renderer/constants/keyboard-shortcuts";
66
import { handleExternalAppAction } from "@utils/handleExternalAppAction";
7-
import { useCallback } from "react";
7+
import { useCallback, useState } from "react";
88
import { useHotkeys } from "react-hotkeys-hook";
99

1010
const THUMBNAIL_ICON_SIZE = 20;
@@ -74,14 +74,26 @@ export function ExternalAppsOpener({
7474
[handleCopyPath],
7575
);
7676

77+
const [dropdownOpen, setDropdownOpen] = useState(false);
78+
7779
if (!targetPath) {
7880
return null;
7981
}
8082

8183
const isReady = !isLoading && detectedApps.length > 0;
8284

8385
return (
84-
<DropdownMenu.Root>
86+
<DropdownMenu.Root open={dropdownOpen} onOpenChange={setDropdownOpen}>
87+
{dropdownOpen && (
88+
<div
89+
className="no-drag"
90+
style={{
91+
position: "fixed",
92+
inset: 0,
93+
zIndex: 1,
94+
}}
95+
/>
96+
)}
8597
<Flex className="no-drag">
8698
<Button
8799
size="1"

apps/code/src/renderer/features/task-detail/components/TaskDetail.tsx

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { FilePicker } from "@features/command/components/FilePicker";
22
import { PanelLayout } from "@features/panels";
3+
import { usePanelLayoutStore } from "@features/panels/store/panelLayoutStore";
4+
import {
5+
getLeafPanel,
6+
parseTabId,
7+
} from "@features/panels/store/panelStoreHelpers";
38
import { useCwd } from "@features/sidebar/hooks/useCwd";
49
import { useTaskData } from "@features/task-detail/hooks/useTaskData";
510
import { useTaskStore } from "@features/tasks/stores/taskStore";
@@ -30,6 +35,28 @@ export function TaskDetail({ task: initialTask }: TaskDetailProps) {
3035

3136
const effectiveRepoPath = useCwd(taskId);
3237

38+
const activeRelativePath = usePanelLayoutStore((state) => {
39+
const layout = state.getLayout(taskId);
40+
if (!layout) return null;
41+
42+
const panelId = layout.focusedPanelId;
43+
if (!panelId) return null;
44+
45+
const panel = getLeafPanel(layout.panelTree, panelId);
46+
if (!panel) return null;
47+
48+
const parsed = parseTabId(panel.content.activeTabId);
49+
if (parsed.type === "file" || parsed.type === "diff") {
50+
return parsed.value;
51+
}
52+
return null;
53+
});
54+
55+
const openTargetPath =
56+
activeRelativePath && effectiveRepoPath
57+
? `${effectiveRepoPath}/${activeRelativePath}`
58+
: effectiveRepoPath;
59+
3360
const [filePickerOpen, setFilePickerOpen] = useState(false);
3461

3562
const { enableScope, disableScope } = useHotkeysContext();
@@ -60,12 +87,10 @@ export function TaskDetail({ task: initialTask }: TaskDetailProps) {
6087
{task.title}
6188
</Text>
6289
</Flex>
63-
{effectiveRepoPath && (
64-
<ExternalAppsOpener targetPath={effectiveRepoPath} />
65-
)}
90+
{openTargetPath && <ExternalAppsOpener targetPath={openTargetPath} />}
6691
</Flex>
6792
),
68-
[task.title, effectiveRepoPath],
93+
[task.title, openTargetPath],
6994
);
7095

7196
useSetHeaderContent(headerContent);

0 commit comments

Comments
 (0)