Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,17 @@ export const Terminal = ({ paneId, tabId, workspaceId }: TerminalProps) => {
const handleDrop = (event: React.DragEvent) => {
event.preventDefault();
const files = Array.from(event.dataTransfer.files);
if (files.length === 0) return;
const paths = files.map((file) => window.webUtils.getPathForFile(file));
const text = shellEscapePaths(paths);
let text: string;
if (files.length > 0) {
// Native file drop (from Finder, etc.)
const paths = files.map((file) => window.webUtils.getPathForFile(file));
text = shellEscapePaths(paths);
} else {
// Internal drag (from file tree) - path is in text/plain
const plainText = event.dataTransfer.getData("text/plain");
if (!plainText) return;
text = shellEscapePaths([plainText]);
}
if (!isExitedRef.current) {
writeRef.current({ paneId, data: text });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
} from "react-icons/lu";
import type { ChangeCategory, ChangedFile } from "shared/changes-types";
import { createFileKey, useScrollContext } from "../../../../ChangesContent";
import { usePathActions } from "../../hooks";
import { useFileDrag, usePathActions } from "../../hooks";
import { getStatusColor, getStatusIndicator } from "../../utils";

interface FileItemProps {
Expand Down Expand Up @@ -106,6 +106,8 @@ export function FileItem({
cwd: worktreePath,
});

const fileDragProps = useFileDrag({ absolutePath });

const handleClick = useCallback(() => {
if (clickTimeoutRef.current) {
clearTimeout(clickTimeoutRef.current);
Expand Down Expand Up @@ -161,6 +163,7 @@ export function FileItem({

const fileContent = (
<div
{...fileDragProps}
className={cn(
"group w-full flex items-stretch gap-1 px-1.5 text-left rounded-sm",
"hover:bg-accent/50 cursor-pointer transition-colors overflow-hidden",
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { useFileDrag } from "./useFileDrag";
export { usePathActions } from "./usePathActions";
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { useCallback } from "react";

interface UseFileDragProps {
absolutePath: string | null;
}

export function useFileDrag({ absolutePath }: UseFileDragProps) {
const handleDragStart = useCallback(
(e: React.DragEvent) => {
if (!absolutePath) {
e.preventDefault();
return;
}
e.dataTransfer.setData("text/plain", absolutePath);
e.dataTransfer.effectAllowed = "copy";
},
[absolutePath],
);

return {
draggable: Boolean(absolutePath),
onDragStart: handleDragStart,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
LuTrash2,
} from "react-icons/lu";
import type { DirectoryEntry } from "shared/file-tree-types";
import { usePathActions } from "../../../ChangesView/hooks";
import { useFileDrag, usePathActions } from "../../../ChangesView/hooks";
import { SEARCH_RESULT_ROW_HEIGHT } from "../../constants";
import { getFileIcon } from "../../utils";

Expand Down Expand Up @@ -83,6 +83,8 @@ export function FileSearchResultItem({
cwd: worktreePath,
});

const fileDragProps = useFileDrag({ absolutePath: entry.path });

const handleClick = () => {
if (!entry.isDirectory) {
onActivate(entry);
Expand All @@ -104,6 +106,7 @@ export function FileSearchResultItem({

const itemContent = (
<div
{...fileDragProps}
role="treeitem"
tabIndex={0}
style={{ height: SEARCH_RESULT_ROW_HEIGHT }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
LuTrash2,
} from "react-icons/lu";
import type { DirectoryEntry } from "shared/file-tree-types";
import { usePathActions } from "../../../ChangesView/hooks";
import { useFileDrag, usePathActions } from "../../../ChangesView/hooks";
import { getFileIcon } from "../../utils";

interface FileTreeItemProps {
Expand Down Expand Up @@ -66,6 +66,8 @@ export function FileTreeItem({
cwd: worktreePath,
});

const fileDragProps = useFileDrag({ absolutePath: entry.path });

const handleClick = (e: React.MouseEvent) => {
e.stopPropagation();
if (isFolder) {
Expand Down Expand Up @@ -102,6 +104,7 @@ export function FileTreeItem({
const itemContent = (
<div
{...item.getProps()}
{...fileDragProps}
data-item-id={item.getId()}
style={{
height: rowHeight,
Expand Down
2 changes: 1 addition & 1 deletion bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading