mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-28 22:14:52 -07:00
Right click to paste in Alternate Buffer mode (#13234)
This commit is contained in:
committed by
GitHub
parent
1d1bdc57ce
commit
8877c85278
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
import type React from 'react';
|
||||
import clipboardy from 'clipboardy';
|
||||
import { useCallback, useEffect, useState, useRef } from 'react';
|
||||
import { Box, Text, getBoundingBox, type DOMElement } from 'ink';
|
||||
import { SuggestionsDisplay, MAX_WIDTH } from './SuggestionsDisplay.js';
|
||||
@@ -315,7 +316,7 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
|
||||
}, [buffer, popAllMessages, inputHistory]);
|
||||
|
||||
// Handle clipboard image pasting with Ctrl+V
|
||||
const handleClipboardImage = useCallback(async () => {
|
||||
const handleClipboardPaste = useCallback(async () => {
|
||||
try {
|
||||
if (await clipboardHasImage()) {
|
||||
const imagePath = await saveClipboardImage(config.getTargetDir());
|
||||
@@ -331,14 +332,7 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
|
||||
// Insert @path reference at cursor position
|
||||
const insertText = `@${relativePath}`;
|
||||
const currentText = buffer.text;
|
||||
const [row, col] = buffer.cursor;
|
||||
|
||||
// Calculate offset from row/col
|
||||
let offset = 0;
|
||||
for (let i = 0; i < row; i++) {
|
||||
offset += buffer.lines[i].length + 1; // +1 for newline
|
||||
}
|
||||
offset += col;
|
||||
const offset = buffer.getOffset();
|
||||
|
||||
// Add spaces around the path if needed
|
||||
let textToInsert = insertText;
|
||||
@@ -355,8 +349,13 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
|
||||
|
||||
// Insert at cursor position
|
||||
buffer.replaceRangeByOffset(offset, offset, textToInsert);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const textToInsert = await clipboardy.read();
|
||||
const offset = buffer.getOffset();
|
||||
buffer.replaceRangeByOffset(offset, offset, textToInsert);
|
||||
} catch (error) {
|
||||
console.error('Error handling clipboard image:', error);
|
||||
}
|
||||
@@ -381,10 +380,12 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
|
||||
buffer.moveToVisualPosition(visualRow, relX);
|
||||
return true;
|
||||
}
|
||||
} else if (event.name === 'right-release') {
|
||||
handleClipboardPaste();
|
||||
}
|
||||
return false;
|
||||
},
|
||||
[buffer],
|
||||
[buffer, handleClipboardPaste],
|
||||
);
|
||||
|
||||
useMouse(handleMouse, { isActive: focus && !isEmbeddedShellFocused });
|
||||
@@ -772,9 +773,9 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
|
||||
return;
|
||||
}
|
||||
|
||||
// Ctrl+V for clipboard image paste
|
||||
if (keyMatchers[Command.PASTE_CLIPBOARD_IMAGE](key)) {
|
||||
handleClipboardImage();
|
||||
// Ctrl+V for clipboard paste
|
||||
if (keyMatchers[Command.PASTE_CLIPBOARD](key)) {
|
||||
handleClipboardPaste();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -805,7 +806,7 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
|
||||
handleSubmit,
|
||||
shellHistory,
|
||||
reverseSearchCompletion,
|
||||
handleClipboardImage,
|
||||
handleClipboardPaste,
|
||||
resetCompletionState,
|
||||
showEscapePrompt,
|
||||
resetEscapeState,
|
||||
|
||||
Reference in New Issue
Block a user