@@ -525,61 +525,109 @@ ${errorDetails ? `\nTechnical details:\n${errorDetails}\n` : ""}
525525 isProtected : isWriteProtected ,
526526 }
527527
528- // If single file, ask for approval
528+ // If single file, handle based on PREVENT_FOCUS_DISRUPTION setting
529529 let didApprove = true
530530 if ( operationsToApprove . length === 1 ) {
531- const diffContents = diffItems . map ( ( item ) => item . content ) . join ( "\n\n" )
532- const operationMessage = JSON . stringify ( {
533- ...sharedMessageProps ,
534- diff : diffContents ,
535- } satisfies ClineSayTool )
536-
537- let toolProgressStatus
538-
539- if ( cline . diffStrategy && cline . diffStrategy . getProgressStatus ) {
540- toolProgressStatus = cline . diffStrategy . getProgressStatus (
541- {
542- ...block ,
543- params : { ...block . params , diff : diffContents } ,
544- } ,
545- { success : true } ,
531+ if ( isPreventFocusDisruptionEnabled ) {
532+ // Direct approval without showing diff view
533+ const diffContents = diffItems . map ( ( item ) => item . content ) . join ( "\n\n" )
534+ const operationMessage = JSON . stringify ( {
535+ ...sharedMessageProps ,
536+ diff : diffContents ,
537+ } satisfies ClineSayTool )
538+
539+ let toolProgressStatus
540+
541+ if ( cline . diffStrategy && cline . diffStrategy . getProgressStatus ) {
542+ toolProgressStatus = cline . diffStrategy . getProgressStatus (
543+ {
544+ ...block ,
545+ params : { ...block . params , diff : diffContents } ,
546+ } ,
547+ { success : true } ,
548+ )
549+ }
550+
551+ // Check if file is write-protected
552+ const isWriteProtected = cline . rooProtectedController ?. isWriteProtected ( relPath ) || false
553+ didApprove = await askApproval ( "tool" , operationMessage , toolProgressStatus , isWriteProtected )
554+
555+ if ( ! didApprove ) {
556+ results . push ( `Changes to ${ relPath } were not approved by user` )
557+ continue
558+ }
559+
560+ // Direct file write without diff view or opening the file
561+ cline . diffViewProvider . editType = "modify"
562+ cline . diffViewProvider . originalContent = await fs . readFile ( absolutePath , "utf-8" )
563+ await cline . diffViewProvider . saveDirectly (
564+ relPath ,
565+ originalContent ! ,
566+ false ,
567+ diagnosticsEnabled ,
568+ writeDelayMs ,
546569 )
547- }
570+ } else {
571+ // Show diff view BEFORE asking for approval
572+ cline . diffViewProvider . editType = "modify"
573+ await cline . diffViewProvider . open ( relPath )
574+ await cline . diffViewProvider . update ( originalContent ! , true )
575+ cline . diffViewProvider . scrollToFirstDiff ( )
576+
577+ const diffContents = diffItems . map ( ( item ) => item . content ) . join ( "\n\n" )
578+ const operationMessage = JSON . stringify ( {
579+ ...sharedMessageProps ,
580+ diff : diffContents ,
581+ } satisfies ClineSayTool )
582+
583+ let toolProgressStatus
584+
585+ if ( cline . diffStrategy && cline . diffStrategy . getProgressStatus ) {
586+ toolProgressStatus = cline . diffStrategy . getProgressStatus (
587+ {
588+ ...block ,
589+ params : { ...block . params , diff : diffContents } ,
590+ } ,
591+ { success : true } ,
592+ )
593+ }
548594
549- // Check if file is write-protected
550- const isWriteProtected = cline . rooProtectedController ?. isWriteProtected ( relPath ) || false
551- didApprove = await askApproval ( "tool" , operationMessage , toolProgressStatus , isWriteProtected )
552- }
595+ // Check if file is write-protected
596+ const isWriteProtected = cline . rooProtectedController ?. isWriteProtected ( relPath ) || false
597+ didApprove = await askApproval ( "tool" , operationMessage , toolProgressStatus , isWriteProtected )
553598
554- if ( ! didApprove ) {
555- if ( ! isPreventFocusDisruptionEnabled ) {
556- await cline . diffViewProvider . revertChanges ( )
557- }
558- results . push ( `Changes to ${ relPath } were not approved by user` )
559- continue
560- }
599+ if ( ! didApprove ) {
600+ await cline . diffViewProvider . revertChanges ( )
601+ results . push ( `Changes to ${ relPath } were not approved by user` )
602+ continue
603+ }
561604
562- if ( isPreventFocusDisruptionEnabled ) {
563- // Direct file write without diff view or opening the file
564- cline . diffViewProvider . editType = "modify"
565- cline . diffViewProvider . originalContent = await fs . readFile ( absolutePath , "utf-8" )
566- await cline . diffViewProvider . saveDirectly (
567- relPath ,
568- originalContent ! ,
569- false ,
570- diagnosticsEnabled ,
571- writeDelayMs ,
572- )
605+ // Call saveChanges to update the DiffViewProvider properties
606+ await cline . diffViewProvider . saveChanges ( diagnosticsEnabled , writeDelayMs )
607+ }
573608 } else {
574- // Original behavior with diff view
575- // Show diff view before asking for approval (only for single file or after batch approval)
576- cline . diffViewProvider . editType = "modify"
577- await cline . diffViewProvider . open ( relPath )
578- await cline . diffViewProvider . update ( originalContent ! , true )
579- cline . diffViewProvider . scrollToFirstDiff ( )
580-
581- // Call saveChanges to update the DiffViewProvider properties
582- await cline . diffViewProvider . saveChanges ( diagnosticsEnabled , writeDelayMs )
609+ // Batch operations - already approved above
610+ if ( isPreventFocusDisruptionEnabled ) {
611+ // Direct file write without diff view or opening the file
612+ cline . diffViewProvider . editType = "modify"
613+ cline . diffViewProvider . originalContent = await fs . readFile ( absolutePath , "utf-8" )
614+ await cline . diffViewProvider . saveDirectly (
615+ relPath ,
616+ originalContent ! ,
617+ false ,
618+ diagnosticsEnabled ,
619+ writeDelayMs ,
620+ )
621+ } else {
622+ // Original behavior with diff view
623+ cline . diffViewProvider . editType = "modify"
624+ await cline . diffViewProvider . open ( relPath )
625+ await cline . diffViewProvider . update ( originalContent ! , true )
626+ cline . diffViewProvider . scrollToFirstDiff ( )
627+
628+ // Call saveChanges to update the DiffViewProvider properties
629+ await cline . diffViewProvider . saveChanges ( diagnosticsEnabled , writeDelayMs )
630+ }
583631 }
584632
585633 // Track file edit operation
0 commit comments