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
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 @@ -70,6 +70,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): string => webUtils.getPathForFile(file),
saveTextFile: (fileName: string, content: string) => ipcRenderer.invoke("save-text-file", fileName, content),
setIsActive: () => ipcRenderer.invoke("set-is-active"),
});
Expand Down
4 changes: 4 additions & 0 deletions frontend/app/view/term/termutil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,7 @@ export function bufferLinesToText(buffer: TermTypes.IBuffer, startIndex: number,

return lines;
}

export function quoteForPosixShell(filePath: string): string {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Shell quoting only handles POSIX shells - won't work on Windows (cmd.exe/PowerShell)

This function uses single-quote escaping which is POSIX-specific. Files dragged onto the terminal on Windows will not be properly quoted, causing issues with paths containing spaces or special characters.

return "'" + filePath.replace(/'/g, "'\\''") + "'";
}
41 changes: 40 additions & 1 deletion frontend/app/view/term/termwrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { RpcApi } from "@/app/store/wshclientapi";
import { TabRpcClient } from "@/app/store/wshrpcutil";
import {
fetchWaveFile,
getApi,
getOverrideConfigAtom,
getSettingsKeyAtom,
globalStore,
Expand Down Expand Up @@ -35,7 +36,13 @@ import {
isClaudeCodeCommand,
type ShellIntegrationStatus,
} from "./osc-handlers";
import { bufferLinesToText, createTempFileFromBlob, extractAllClipboardData, normalizeCursorStyle } from "./termutil";
import {
bufferLinesToText,
createTempFileFromBlob,
extractAllClipboardData,
normalizeCursorStyle,
quoteForPosixShell,
} from "./termutil";

const dlog = debug("wave:termwrap");

Expand Down Expand Up @@ -274,6 +281,38 @@ export class TermWrap {
this.heldData = [];
this.handleResize_debounced = debounce(50, this.handleResize.bind(this));
this.terminal.open(this.connectElem);

const dragoverHandler = (e: DragEvent) => {
e.preventDefault();
if (e.dataTransfer) {
e.dataTransfer.dropEffect = "copy";
}
};
const dropHandler = (e: DragEvent) => {
e.preventDefault();
if (!e.dataTransfer || e.dataTransfer.files.length === 0) {
return;
}
const paths: string[] = [];
for (let i = 0; i < e.dataTransfer.files.length; i++) {
const file = e.dataTransfer.files[i];
const filePath = getApi().getPathForFile(file);
if (filePath) {
paths.push(quoteForPosixShell(filePath));
}
}
if (paths.length > 0) {
this.terminal.paste(paths.join(" ") + " ");
}
};
this.connectElem.addEventListener("dragover", dragoverHandler);
this.connectElem.addEventListener("drop", dropHandler);
this.toDispose.push({
dispose: () => {
this.connectElem.removeEventListener("dragover", dragoverHandler);
this.connectElem.removeEventListener("drop", dropHandler);
},
});
this.handleResize();
const pasteHandler = this.pasteHandler.bind(this);
this.connectElem.addEventListener("paste", pasteHandler, true);
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 @@ -133,6 +133,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; // webUtils.getPathForFile
saveTextFile: (fileName: string, content: string) => Promise<boolean>; // save-text-file
setIsActive: () => Promise<void>; // set-is-active
};
Expand Down