Skip to content
Open
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
3 changes: 2 additions & 1 deletion emain/preload.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2025, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0

import { contextBridge, ipcRenderer, Rectangle, WebviewTag } from "electron";
import { contextBridge, ipcRenderer, Rectangle, webUtils, WebviewTag } from "electron";

// update type in custom.d.ts (ElectronApi type)
contextBridge.exposeInMainWorld("api", {
Expand Down Expand Up @@ -68,6 +68,7 @@ contextBridge.exposeInMainWorld("api", {
openBuilder: (appId?: string) => ipcRenderer.send("open-builder", appId),
setBuilderWindowAppId: (appId: string) => ipcRenderer.send("set-builder-window-appid", appId),
doRefresh: () => ipcRenderer.send("do-refresh"),
getPathForFile: (file: File) => webUtils.getPathForFile(file),
});

// Custom event for "new-window"
Expand Down
66 changes: 64 additions & 2 deletions frontend/app/view/term/term.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { waveEventSubscribe } from "@/app/store/wps";
import { RpcApi } from "@/app/store/wshclientapi";
import { TabRpcClient } from "@/app/store/wshrpcutil";
import type { TermViewModel } from "@/app/view/term/term-model";
import { atoms, getOverrideConfigAtom, getSettingsPrefixAtom, globalStore, WOS } from "@/store/global";
import { atoms, getApi, getOverrideConfigAtom, getSettingsPrefixAtom, globalStore, WOS } from "@/store/global";
import { fireAndForget, useAtomValueSafe } from "@/util/util";
import { computeBgStyleFromMeta } from "@/util/waveutil";
import { ISearchOptions } from "@xterm/addon-search";
Expand Down Expand Up @@ -349,8 +349,70 @@ const TerminalView = ({ blockId, model }: ViewComponentProps<TermViewModel>) =>

const termBg = computeBgStyleFromMeta(blockData?.meta);

// Handle drag and drop
// Helper to check if drag event contains files
const isFileDrop = (e: React.DragEvent): boolean => {
return e.dataTransfer?.types?.includes("Files") ?? false;
};

const handleDragOver = React.useCallback((e: React.DragEvent) => {
if (!isFileDrop(e)) return;
e.preventDefault();
e.stopPropagation();
e.dataTransfer.dropEffect = "copy";
}, []);

const handleDrop = React.useCallback((e: React.DragEvent) => {
if (!isFileDrop(e)) return;
e.preventDefault();
e.stopPropagation();

const files = Array.from(e.dataTransfer.files);
if (files.length === 0) return;

// Get file paths using Electron API
const paths = files.map((file: File) => {
try {
const fullPath = getApi().getPathForFile(file);
// Quote paths with spaces or special shell characters
if (/[\s'"]/.test(fullPath)) {
return `"${fullPath}"`;
}
return fullPath;
} catch (err) {
console.error("Could not get path for file:", file.name, err);
return file.name;
}
});

// Send space-separated paths to terminal
const pathString = paths.join(" ");
if (model.termRef.current && pathString) {
model.sendDataToController(pathString);
}
}, [model]);

const handleDragEnter = React.useCallback((e: React.DragEvent) => {
if (!isFileDrop(e)) return;
e.preventDefault();
e.stopPropagation();
}, []);

const handleDragLeave = React.useCallback((e: React.DragEvent) => {
if (!isFileDrop(e)) return;
e.preventDefault();
e.stopPropagation();
}, []);

return (
<div className={clsx("view-term", "term-mode-" + termMode)} ref={viewRef}>
<div
className={clsx("view-term", "term-mode-" + termMode)}
ref={viewRef}
onDragOver={handleDragOver}
onDrop={handleDrop}
onDragEnter={handleDragEnter}
onDragLeave={handleDragLeave}
>
{termBg && <div className="absolute inset-0 z-0 pointer-events-none" style={termBg} />}
<TermResyncHandler blockId={blockId} model={model} />
<TermThemeUpdater blockId={blockId} model={model} termRef={model.termRef} />
Expand Down
1 change: 1 addition & 0 deletions frontend/types/custom.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ declare global {
openBuilder: (appId?: string) => void; // open-builder
setBuilderWindowAppId: (appId: string) => void; // set-builder-window-appid
doRefresh: () => void; // do-refresh
getPathForFile: (file: File) => string; // get-path-for-file
};

type ElectronContextMenuItem = {
Expand Down