@@ -36,6 +36,7 @@ import {
3636 cleanupOldClipboardImages ,
3737} from '../utils/clipboardUtils.js' ;
3838import * as path from 'node:path' ;
39+ import * as fs from 'node:fs' ;
3940import { SCREEN_READER_USER_PREFIX } from '../textConstants.js' ;
4041import { useShellFocusState } from '../contexts/ShellFocusContext.js' ;
4142import { useUIState } from '../contexts/UIStateContext.js' ;
@@ -322,15 +323,21 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
322323
323324 // Handle clipboard image pasting with Ctrl+V
324325 const handleClipboardPaste = useCallback ( async ( ) => {
326+ const debugLog = ( msg : string ) => {
327+ const logPath = path . join ( config . getTargetDir ( ) , '.gemini-debug.log' ) ;
328+ const timestamp = new Date ( ) . toISOString ( ) ;
329+ fs . appendFileSync ( logPath , `${ timestamp } ${ msg } \n` ) ;
330+ } ;
331+
325332 try {
326- console . log ( '[DEBUG] Ctrl+V pressed - checking for clipboard image...' ) ;
333+ debugLog ( '[DEBUG] Ctrl+V pressed - checking for clipboard image...' ) ;
327334 const hasImage = await clipboardHasImage ( ) ;
328- console . log ( ' [DEBUG] Clipboard has image:' , hasImage ) ;
335+ debugLog ( ` [DEBUG] Clipboard has image: ${ hasImage } ` ) ;
329336
330337 if ( hasImage ) {
331- console . log ( '[DEBUG] Attempting to save clipboard image...' ) ;
338+ debugLog ( '[DEBUG] Attempting to save clipboard image...' ) ;
332339 const imagePath = await saveClipboardImage ( config . getTargetDir ( ) ) ;
333- console . log ( ' [DEBUG] Image saved to:' , imagePath ) ;
340+ debugLog ( ` [DEBUG] Image saved to: ${ imagePath } ` ) ;
334341
335342 if ( imagePath ) {
336343 // Clean up old images
@@ -340,7 +347,7 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
340347
341348 // Get relative path from current directory
342349 const relativePath = path . relative ( config . getTargetDir ( ) , imagePath ) ;
343- console . log ( ' [DEBUG] Relative path:' , relativePath ) ;
350+ debugLog ( ` [DEBUG] Relative path: ${ relativePath } ` ) ;
344351
345352 // Insert @path reference at cursor position
346353 const insertText = `@${ relativePath } ` ;
@@ -360,27 +367,26 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
360367 textToInsert = textToInsert + ' ' ;
361368 }
362369
363- console . log ( ' [DEBUG] Inserting text:' , textToInsert ) ;
370+ debugLog ( ` [DEBUG] Inserting text: ${ textToInsert } ` ) ;
364371 // Insert at cursor position
365372 buffer . replaceRangeByOffset ( offset , offset , textToInsert ) ;
366- console . log ( '[DEBUG] Image path inserted successfully!' ) ;
373+ debugLog ( '[DEBUG] Image path inserted successfully!' ) ;
367374 return ;
368375 } else {
369- console . log ( '[DEBUG] Failed to save clipboard image' ) ;
376+ debugLog ( '[DEBUG] Failed to save clipboard image' ) ;
370377 }
371378 } else {
372- console . log ( '[DEBUG] No image in clipboard, pasting text instead...' ) ;
379+ debugLog ( '[DEBUG] No image in clipboard, pasting text instead...' ) ;
373380 }
374381
375382 const textToInsert = await clipboardy . read ( ) ;
376- console . log ( '[DEBUG] Pasting text from clipboard' ) ;
383+ debugLog ( '[DEBUG] Pasting text from clipboard' ) ;
377384 const offset = buffer . getOffset ( ) ;
378385 buffer . replaceRangeByOffset ( offset , offset , textToInsert ) ;
379386 } catch ( error ) {
380- console . error ( '[ERROR] Error handling clipboard paste:' , error ) ;
381- console . error (
382- '[ERROR] Stack trace:' ,
383- error instanceof Error ? error . stack : 'No stack trace' ,
387+ debugLog ( `[ERROR] Error handling clipboard paste: ${ error } ` ) ;
388+ debugLog (
389+ `[ERROR] Stack trace: ${ error instanceof Error ? error . stack : 'No stack trace' } ` ,
384390 ) ;
385391 }
386392 } , [ buffer , config ] ) ;
0 commit comments