mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-09 12:51:09 -07:00
feat: support multi-file drag and drop of images (#14832)
This commit is contained in:
@@ -637,6 +637,46 @@ describe('useTextBuffer', () => {
|
||||
act(() => result.current.insert(shortText, { paste: true }));
|
||||
expect(getBufferState(result).text).toBe(shortText);
|
||||
});
|
||||
|
||||
it('should prepend @ to multiple valid file paths on insert', () => {
|
||||
// Use Set to model reality: individual paths exist, combined string doesn't
|
||||
const validPaths = new Set(['/path/to/file1.txt', '/path/to/file2.txt']);
|
||||
const { result } = renderHook(() =>
|
||||
useTextBuffer({ viewport, isValidPath: (p) => validPaths.has(p) }),
|
||||
);
|
||||
const filePaths = '/path/to/file1.txt /path/to/file2.txt';
|
||||
act(() => result.current.insert(filePaths, { paste: true }));
|
||||
expect(getBufferState(result).text).toBe(
|
||||
'@/path/to/file1.txt @/path/to/file2.txt ',
|
||||
);
|
||||
});
|
||||
|
||||
it('should handle multiple paths with escaped spaces', () => {
|
||||
// Use Set to model reality: individual paths exist, combined string doesn't
|
||||
const validPaths = new Set(['/path/to/my file.txt', '/other/path.txt']);
|
||||
const { result } = renderHook(() =>
|
||||
useTextBuffer({ viewport, isValidPath: (p) => validPaths.has(p) }),
|
||||
);
|
||||
const filePaths = '/path/to/my\\ file.txt /other/path.txt';
|
||||
act(() => result.current.insert(filePaths, { paste: true }));
|
||||
expect(getBufferState(result).text).toBe(
|
||||
'@/path/to/my\\ file.txt @/other/path.txt ',
|
||||
);
|
||||
});
|
||||
|
||||
it('should only prepend @ to valid paths in multi-path paste', () => {
|
||||
const { result } = renderHook(() =>
|
||||
useTextBuffer({
|
||||
viewport,
|
||||
isValidPath: (p) => p.endsWith('.txt'),
|
||||
}),
|
||||
);
|
||||
const filePaths = '/valid/file.txt /invalid/file.jpg';
|
||||
act(() => result.current.insert(filePaths, { paste: true }));
|
||||
expect(getBufferState(result).text).toBe(
|
||||
'@/valid/file.txt /invalid/file.jpg ',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Shell Mode Behavior', () => {
|
||||
|
||||
@@ -9,7 +9,7 @@ import fs from 'node:fs';
|
||||
import os from 'node:os';
|
||||
import pathMod from 'node:path';
|
||||
import { useState, useCallback, useEffect, useMemo, useReducer } from 'react';
|
||||
import { unescapePath, coreEvents, CoreEvent } from '@google/gemini-cli-core';
|
||||
import { coreEvents, CoreEvent } from '@google/gemini-cli-core';
|
||||
import {
|
||||
toCodePoints,
|
||||
cpLen,
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
stripUnsafeCharacters,
|
||||
getCachedStringWidth,
|
||||
} from '../../utils/textUtils.js';
|
||||
import { parsePastedPaths } from '../../utils/clipboardUtils.js';
|
||||
import type { Key } from '../../contexts/KeypressContext.js';
|
||||
import type { VimAction } from './vim-buffer-actions.js';
|
||||
import { handleVimAction } from './vim-buffer-actions.js';
|
||||
@@ -1675,8 +1676,10 @@ export function useTextBuffer({
|
||||
}
|
||||
|
||||
potentialPath = potentialPath.trim();
|
||||
if (isValidPath(unescapePath(potentialPath))) {
|
||||
ch = `@${potentialPath} `;
|
||||
|
||||
const processed = parsePastedPaths(potentialPath, isValidPath);
|
||||
if (processed) {
|
||||
ch = processed;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user