@@ -525,17 +525,17 @@ ${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+ // Prepare common data for single file operation
531532 const diffContents = diffItems . map ( ( item ) => item . content ) . join ( "\n\n" )
532533 const operationMessage = JSON . stringify ( {
533534 ...sharedMessageProps ,
534535 diff : diffContents ,
535536 } satisfies ClineSayTool )
536537
537538 let toolProgressStatus
538-
539539 if ( cline . diffStrategy && cline . diffStrategy . getProgressStatus ) {
540540 toolProgressStatus = cline . diffStrategy . getProgressStatus (
541541 {
@@ -546,40 +546,69 @@ ${errorDetails ? `\nTechnical details:\n${errorDetails}\n` : ""}
546546 )
547547 }
548548
549- // Check if file is write-protected
549+ // Set up diff view
550+ cline . diffViewProvider . editType = "modify"
551+
552+ // Show diff view if focus disruption prevention is disabled
553+ if ( ! isPreventFocusDisruptionEnabled ) {
554+ await cline . diffViewProvider . open ( relPath )
555+ await cline . diffViewProvider . update ( originalContent ! , true )
556+ cline . diffViewProvider . scrollToFirstDiff ( )
557+ } else {
558+ // For direct save, we still need to set originalContent
559+ cline . diffViewProvider . originalContent = await fs . readFile ( absolutePath , "utf-8" )
560+ }
561+
562+ // Ask for approval (same for both flows)
550563 const isWriteProtected = cline . rooProtectedController ?. isWriteProtected ( relPath ) || false
551564 didApprove = await askApproval ( "tool" , operationMessage , toolProgressStatus , isWriteProtected )
552- }
553565
554- if ( ! didApprove ) {
555- if ( ! isPreventFocusDisruptionEnabled ) {
556- await cline . diffViewProvider . revertChanges ( )
566+ if ( ! didApprove ) {
567+ // Revert changes if diff view was shown
568+ if ( ! isPreventFocusDisruptionEnabled ) {
569+ await cline . diffViewProvider . revertChanges ( )
570+ }
571+ results . push ( `Changes to ${ relPath } were not approved by user` )
572+ continue
557573 }
558- results . push ( `Changes to ${ relPath } were not approved by user` )
559- continue
560- }
561574
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- )
575+ // Save the changes
576+ if ( isPreventFocusDisruptionEnabled ) {
577+ // Direct file write without diff view or opening the file
578+ await cline . diffViewProvider . saveDirectly (
579+ relPath ,
580+ originalContent ! ,
581+ false ,
582+ diagnosticsEnabled ,
583+ writeDelayMs ,
584+ )
585+ } else {
586+ // Call saveChanges to update the DiffViewProvider properties
587+ await cline . diffViewProvider . saveChanges ( diagnosticsEnabled , writeDelayMs )
588+ }
573589 } 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 )
590+ // Batch operations - already approved above
591+ if ( isPreventFocusDisruptionEnabled ) {
592+ // Direct file write without diff view or opening the file
593+ cline . diffViewProvider . editType = "modify"
594+ cline . diffViewProvider . originalContent = await fs . readFile ( absolutePath , "utf-8" )
595+ await cline . diffViewProvider . saveDirectly (
596+ relPath ,
597+ originalContent ! ,
598+ false ,
599+ diagnosticsEnabled ,
600+ writeDelayMs ,
601+ )
602+ } else {
603+ // Original behavior with diff view
604+ cline . diffViewProvider . editType = "modify"
605+ await cline . diffViewProvider . open ( relPath )
606+ await cline . diffViewProvider . update ( originalContent ! , true )
607+ cline . diffViewProvider . scrollToFirstDiff ( )
608+
609+ // Call saveChanges to update the DiffViewProvider properties
610+ await cline . diffViewProvider . saveChanges ( diagnosticsEnabled , writeDelayMs )
611+ }
583612 }
584613
585614 // Track file edit operation
0 commit comments