Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d0cc725
feat(cli): paste copied Windows files
Jul 28, 2026
5d8031d
fix(cli): address Windows clipboard paste review
Jul 29, 2026
0173db4
test(cli): harden clipboard paste coverage
Jul 29, 2026
a45914f
Merge branch 'main' into agent/fix-qwen-2605
yiliang114 Jul 30, 2026
baa3648
fix(cli): preserve Windows file paste references
Jul 30, 2026
626af9b
test(cli): cover UNC clipboard file references
Jul 30, 2026
28729e2
fix(cli): normalize clipboard file references
Jul 30, 2026
a5a0739
fix(cli): unescape clipboard image references
Jul 30, 2026
7e47a6a
fix(cli): unwrap quoted image references
Jul 31, 2026
c4a5ff6
chore: merge origin/main into agent/fix-qwen-2605
qwen-code-dev-bot Aug 1, 2026
87b0e57
fix(cli): avoid double-unescaping pasted image paths
Aug 1, 2026
ccab11d
Merge branch 'main' into agent/fix-qwen-2605
wenshao Aug 1, 2026
de3e823
fix(cli): tighten copied-file paste handling
Aug 2, 2026
390227a
Merge remote-tracking branch 'origin/main' into agent/fix-qwen-2605
Aug 2, 2026
9eacd6a
fix(cli): isolate clipboard file paste events
Aug 2, 2026
acec515
chore: merge main into clipboard paste branch
Sep 5, 2026
4908b46
test(cli): initialize clipboard file mock for all prompt tests
Sep 5, 2026
5b293c2
Merge branch 'main' into agent/fix-qwen-2605
wenshao Sep 5, 2026
934d3ba
fix(cli): preserve pasted paths and pending image files
Sep 6, 2026
17916b9
Merge origin/main into agent/fix-qwen-2605
Sep 6, 2026
c420b05
fix(cli): preserve clipboard owners and Unicode file references
Sep 6, 2026
0f0ce10
chore(cli): merge origin/main into agent/fix-qwen-2605
qwen-code-dev-bot Sep 23, 2026
6bb19a9
chore: merge origin/main into agent/fix-qwen-2605
qwen-code-dev-bot Oct 3, 2026
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
2 changes: 1 addition & 1 deletion docs/users/reference/keyboard-shortcuts.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ This document lists the available keyboard shortcuts in Qwen Code.
| `Ctrl+Y` | Retry the last failed request. |
| `Ctrl+Right Arrow` / `Meta+Right Arrow` / `Meta+F` | Move the cursor one word to the right. |
| `Ctrl+U` | Delete from the cursor to the beginning of the line. |
| `Ctrl+V` (Windows: `Alt+V`) | Paste clipboard content. If the clipboard contains an image, it will be saved and a reference to it will be inserted in the prompt. |
| `Ctrl+V` (Windows: `Alt+V`) | Paste clipboard content. Images become attachments. On Windows, files copied in Explorer paste as image attachments or their paths. |
| `Ctrl+W` / `Meta+Backspace` / `Ctrl+Backspace` | Delete the word to the left of the cursor. |
| `Ctrl+X` | Open the current input in an external editor. |

Expand Down
30 changes: 30 additions & 0 deletions packages/cli/src/ui/components/InputPrompt.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1424,6 +1424,7 @@ describe('InputPrompt', () => {
const isWindows = process.platform === 'win32';

beforeEach(() => {
vi.mocked(clipboardUtils.readClipboardFiles).mockResolvedValue([]);
vi.mocked(clipboardUtils.clipboardHasImage).mockResolvedValue(false);
vi.mocked(clipboardUtils.saveClipboardImage).mockResolvedValue(null);
vi.mocked(clipboardUtils.cleanupOldClipboardImages).mockResolvedValue(
Expand Down Expand Up @@ -1481,6 +1482,27 @@ describe('InputPrompt', () => {
unmount();
});

it('inserts copied non-image file paths on the clipboard shortcut', async () => {
vi.mocked(clipboardUtils.readClipboardFiles).mockResolvedValue([
'C:\\Users\\mochi\\notes.txt',
]);

const { stdin, unmount } = renderWithProviders(
<InputPrompt {...props} />,
);
await wait();

stdin.write(isWindows ? '\x1Bv' : '\x16');
await wait();

expect(mockBuffer.insert).toHaveBeenCalledWith(
'C:\\Users\\mochi\\notes.txt',
{ paste: false },
);
expect(clipboardUtils.clipboardHasImage).not.toHaveBeenCalled();
unmount();
});

it('keeps generated attachment references out of submitted provenance', async () => {
const imagePath = path.join(
'test',
Expand Down Expand Up @@ -5697,6 +5719,14 @@ function clean(str: string | undefined): string {
}

describe('classifyPastedImagePaths', () => {
it('recognizes a Windows image path read from the file clipboard', () => {
const imagePath = 'C:\\Users\\mochi\\image.png';
expect(classifyPastedImagePaths(imagePath)).toEqual({
imagePaths: [imagePath],
allImages: true,
});
});

it('treats a lone @-prefixed image path (terminal Cmd+V injection) as all-image', () => {
const result = classifyPastedImagePaths(
'@/var/folders/12/T/clipboard-2026-06-24-124142-18EC6DC9.png',
Expand Down
27 changes: 25 additions & 2 deletions packages/cli/src/ui/components/InputPrompt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
clipboardHasImage,
saveClipboardImage,
cleanupOldClipboardImages,
readClipboardFiles,
} from '../utils/clipboardUtils.js';
import * as path from 'node:path';
import * as fs from 'node:fs/promises';
Expand Down Expand Up @@ -821,6 +822,27 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
[config, buffer],
);

const handleClipboardPaste = useCallback(async () => {
const clipboardFiles = await readClipboardFiles(reportClipboardUnavailable);
if (clipboardFiles.length === 0) {
await handleClipboardImage();
return;
}

const pasted = clipboardFiles.join('\n');
const pastedImagePaths = classifyPastedImagePaths(pasted);
if (pastedImagePaths.allImages) {
await promotePastedImagePaths(pastedImagePaths.imagePaths, pasted);
} else {
buffer.insert(pasted, { paste: false });
}
}, [
buffer,
handleClipboardImage,
promotePastedImagePaths,
reportClipboardUnavailable,
]);

// Handle deletion of an attachment from the list
const handleAttachmentDelete = useCallback((index: number) => {
setAttachments((prev) => {
Expand Down Expand Up @@ -1715,9 +1737,9 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
return true;
}

// Ctrl+V for clipboard image paste
// Clipboard shortcut for copied files or image data
if (keyMatchers[Command.PASTE_CLIPBOARD_IMAGE](key)) {
handleClipboardImage();
void handleClipboardPaste();
return true;
}

Expand Down Expand Up @@ -1824,6 +1846,7 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
shellHistory,
reverseSearchCompletion,
handleClipboardImage,
handleClipboardPaste,
reportClipboardUnavailable,
promotePastedImagePaths,
resetCompletionState,
Expand Down
30 changes: 29 additions & 1 deletion packages/cli/src/ui/contexts/KeypressContext.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ import {
import { useStdin } from 'ink';
import { EventEmitter } from 'node:events';

const mockClipboardHasImage = vi.hoisted(() => vi.fn());
const { mockClipboardHasImage, mockReadClipboardFiles } = vi.hoisted(() => ({
mockClipboardHasImage: vi.fn(),
mockReadClipboardFiles: vi.fn(),
}));

vi.mock('../utils/clipboardUtils.js', () => ({
clipboardHasImage: mockClipboardHasImage,
readClipboardFiles: mockReadClipboardFiles,
}));

// Mock the 'ink' module to control stdin
Expand Down Expand Up @@ -90,6 +94,7 @@ describe('KeypressContext - Kitty Protocol', () => {
beforeEach(() => {
vi.clearAllMocks();
mockClipboardHasImage.mockResolvedValue(false);
mockReadClipboardFiles.mockResolvedValue([]);
stdin = new MockStdin();
(useStdin as Mock).mockReturnValue({
stdin,
Expand Down Expand Up @@ -885,6 +890,29 @@ describe('KeypressContext - Kitty Protocol', () => {
});
});

it('turns copied Windows files into pasted paths', async () => {
const keyHandler = vi.fn();
mockReadClipboardFiles.mockResolvedValue([
'C:\\Users\\mochi\\image.png',
'C:\\Users\\mochi\\notes.txt',
]);
const { result } = renderHook(() => useKeypressContext(), { wrapper });
act(() => result.current.subscribe(keyHandler));

act(() => stdin.sendPaste(''));

await waitFor(() => {
expect(keyHandler).toHaveBeenCalledWith(
expect.objectContaining({
paste: true,
sequence:
'C:\\Users\\mochi\\image.png\nC:\\Users\\mochi\\notes.txt',
}),
);
});
expect(mockClipboardHasImage).not.toHaveBeenCalled();
});

describe('paste mode markers', () => {
// These tests use pasteWorkaround=true to force passthrough mode for raw keypress testing

Expand Down
27 changes: 20 additions & 7 deletions packages/cli/src/ui/contexts/KeypressContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ import {
MODIFIER_ALT_BIT,
MODIFIER_CTRL_BIT,
} from '../utils/platformConstants.js';
import { clipboardHasImage } from '../utils/clipboardUtils.js';
import {
clipboardHasImage,
readClipboardFiles,
} from '../utils/clipboardUtils.js';

import { FOCUS_IN, FOCUS_OUT } from '../hooks/useFocus.js';

Expand Down Expand Up @@ -907,9 +910,14 @@ export function KeypressProvider({
});
} else {
let clipboardImageUnavailable = false;
const hasImage = await clipboardHasImage(() => {
const onUnavailable = () => {
clipboardImageUnavailable = true;
});
};
const clipboardFiles = await readClipboardFiles(onUnavailable);
const hasImage =
clipboardFiles.length === 0 && !clipboardImageUnavailable
? await clipboardHasImage(onUnavailable)
: false;
broadcast({
name: '',
ctrl: false,
Expand All @@ -918,7 +926,7 @@ export function KeypressProvider({
paste: true,
pasteImage: hasImage,
clipboardImageUnavailable,
sequence: buffered,
sequence: clipboardFiles.join('\n'),
});
}
return;
Expand Down Expand Up @@ -1386,9 +1394,14 @@ export function KeypressProvider({
// Mirror the keypress-level paste-end path: surface whether the
// native clipboard module was unavailable.
let clipboardImageUnavailable = false;
void clipboardHasImage(() => {
const onUnavailable = () => {
clipboardImageUnavailable = true;
}).then((hasImage) => {
};
void readClipboardFiles(onUnavailable).then(async (clipboardFiles) => {
const hasImage =
clipboardFiles.length === 0 && !clipboardImageUnavailable
? await clipboardHasImage(onUnavailable)
: false;
broadcast({
name: '',
ctrl: false,
Expand All @@ -1397,7 +1410,7 @@ export function KeypressProvider({
paste: true,
pasteImage: hasImage,
clipboardImageUnavailable,
sequence: '',
sequence: clipboardFiles.join('\n'),
});
});
}
Expand Down
41 changes: 38 additions & 3 deletions packages/cli/src/ui/utils/clipboardUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import { EventEmitter } from 'node:events';
const { mockSpawn, mockExecSync, clipboardMockState } = vi.hoisted(() => ({
mockSpawn: vi.fn(),
mockExecSync: vi.fn(),
clipboardMockState: { failLoad: false, loadDelayMs: 0 },
clipboardMockState: {
failLoad: false,
loadDelayMs: 0,
files: [] as string[],
},
}));

// Mock @teddyzhu/clipboard
Expand All @@ -27,12 +31,24 @@ vi.mock('@teddyzhu/clipboard', async () => {
return {
default: {
ClipboardManager: vi.fn().mockImplementation(() => ({
hasFormat: vi.fn().mockReturnValue(false),
hasFormat: vi
.fn()
.mockImplementation(
(format: string) =>
format === 'files' && clipboardMockState.files.length > 0,
),
getFiles: vi.fn().mockImplementation(() => clipboardMockState.files),
getImageData: vi.fn().mockReturnValue({ data: null }),
})),
},
ClipboardManager: vi.fn().mockImplementation(() => ({
hasFormat: vi.fn().mockReturnValue(false),
hasFormat: vi
.fn()
.mockImplementation(
(format: string) =>
format === 'files' && clipboardMockState.files.length > 0,
),
getFiles: vi.fn().mockImplementation(() => clipboardMockState.files),
getImageData: vi.fn().mockReturnValue({ data: null }),
})),
};
Expand Down Expand Up @@ -150,6 +166,7 @@ const originalPlatform = process.platform;

describe('clipboardUtils', () => {
let clipboardHasImage: () => Promise<boolean>;
let readClipboardFiles: () => Promise<string[]>;
let saveClipboardImage: (dir?: string) => Promise<string | null>;
let cleanupOldClipboardImages: (dir?: string) => Promise<void>;
let writeOsc52: (text: string) => boolean;
Expand All @@ -166,13 +183,15 @@ describe('clipboardUtils', () => {

clipboardMockState.failLoad = false;
clipboardMockState.loadDelayMs = 0;
clipboardMockState.files = [];
vi.resetModules();
vi.clearAllMocks();

// Dynamic import after resetModules gives a fresh module instance.
// Top-level import would be stale after resetModules.
const mod = await import('./clipboardUtils.js');
clipboardHasImage = mod.clipboardHasImage;
readClipboardFiles = mod.readClipboardFiles;
saveClipboardImage = mod.saveClipboardImage;
cleanupOldClipboardImages = mod.cleanupOldClipboardImages;
writeOsc52 = mod.writeOsc52;
Expand Down Expand Up @@ -611,6 +630,22 @@ describe('clipboardUtils', () => {
writable: true,
});
});

it('returns copied file paths on Windows', async () => {
Object.defineProperty(process, 'platform', {
value: 'win32',
configurable: true,
writable: true,
});
clipboardMockState.files = [
'C:\\Users\\mochi\\image.png',
'C:\\Users\\mochi\\notes.txt',
];

await expect(readClipboardFiles()).resolves.toEqual(
clipboardMockState.files,
);
});
});

describe('cache behavior', () => {
Expand Down
28 changes: 28 additions & 0 deletions packages/cli/src/ui/utils/clipboardUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,34 @@ export async function clipboardHasImage(
}
}

/**
* Reads file paths copied from Windows Explorer.
* @param onUnavailable Called when the native clipboard module cannot load.
*/
export async function readClipboardFiles(
onUnavailable?: () => void,
): Promise<string[]> {
if (process.platform !== 'win32') {
return [];
}

try {
const mod = await getClipboardModule();
if (!mod) {
onUnavailable?.();
return [];
}
const clipboard = new mod.ClipboardManager();
if (!clipboard.hasFormat('files')) {
return [];
}
return clipboard.getFiles();
} catch (error) {
debugLogger.error('Error reading clipboard files:', error);
return [];
}
}

/**
* Get the available image MIME types from wl-paste.
* Uses cached result if available to avoid redundant calls.
Expand Down
Loading