fix: add progress indicator for background editing in all file edit tools

When the preventFocusDisruption (Background Editing) experiment is enabled,
file writing operations now display a progress indicator (spinner) in the
chat UI before file operations begin.

This addresses Issue #10504 where users would see no visual feedback while
Roo was preparing and writing files in the background, causing confusion
about whether the app had frozen.

Files updated:
- WriteToFileTool.ts
- ApplyDiffTool.ts
- MultiApplyDiffTool.ts
- SearchAndReplaceTool.ts
- SearchReplaceTool.ts
- EditFileTool.ts
This commit is contained in:
Roo Code 2026-01-07 01:52:23 +00:00
parent 7f2978abad
commit 18b05ffb53
6 changed files with 30 additions and 0 deletions

View file

@ -152,6 +152,10 @@ export class ApplyDiffTool extends BaseTool<"apply_diff"> {
}
if (isPreventFocusDisruptionEnabled) {
// Show progress indicator in UI while preparing the file
const partialMessage = JSON.stringify(sharedMessageProps)
await task.ask("tool", partialMessage, true).catch(() => {})
// Direct file write without diff view
const completeMessage = JSON.stringify({
...sharedMessageProps,

View file

@ -276,6 +276,12 @@ export class EditFileTool extends BaseTool<"edit_file"> {
diffStats,
} satisfies ClineSayTool)
// Show progress indicator in UI while preparing the file when background editing is enabled
if (isPreventFocusDisruptionEnabled) {
const partialMessage = JSON.stringify(sharedMessageProps)
await task.ask("tool", partialMessage, true).catch(() => {})
}
// Show diff view if focus disruption prevention is disabled
if (!isPreventFocusDisruptionEnabled) {
await task.diffViewProvider.open(relPath)

View file

@ -631,6 +631,10 @@ ${errorDetails ? `\nTechnical details:\n${errorDetails}\n` : ""}
await cline.diffViewProvider.update(originalContent!, true)
cline.diffViewProvider.scrollToFirstDiff()
} else {
// Show progress indicator in UI while preparing the file
const partialMessage = JSON.stringify(sharedMessageProps)
await cline.ask("tool", partialMessage, true).catch(() => {})
// For direct save, we still need to set originalContent
cline.diffViewProvider.originalContent = await fs.readFile(absolutePath, "utf-8")
}

View file

@ -211,6 +211,12 @@ export class SearchAndReplaceTool extends BaseTool<"search_and_replace"> {
diffStats,
} satisfies ClineSayTool)
// Show progress indicator in UI while preparing the file when background editing is enabled
if (isPreventFocusDisruptionEnabled) {
const partialMessage = JSON.stringify(sharedMessageProps)
await task.ask("tool", partialMessage, true).catch(() => {})
}
// Show diff view if focus disruption prevention is disabled
if (!isPreventFocusDisruptionEnabled) {
await task.diffViewProvider.open(relPath)

View file

@ -198,6 +198,12 @@ export class SearchReplaceTool extends BaseTool<"search_replace"> {
diffStats,
} satisfies ClineSayTool)
// Show progress indicator in UI while preparing the file when background editing is enabled
if (isPreventFocusDisruptionEnabled) {
const partialMessage = JSON.stringify(sharedMessageProps)
await task.ask("tool", partialMessage, true).catch(() => {})
}
// Show diff view if focus disruption prevention is disabled
if (!isPreventFocusDisruptionEnabled) {
await task.diffViewProvider.open(relPath)

View file

@ -116,6 +116,10 @@ export class WriteToFileTool extends BaseTool<"write_to_file"> {
)
if (isPreventFocusDisruptionEnabled) {
// Show progress indicator in UI while preparing the file
const partialMessage = JSON.stringify(sharedMessageProps)
await task.ask("tool", partialMessage, true).catch(() => {})
task.diffViewProvider.editType = fileExists ? "modify" : "create"
if (fileExists) {
const absolutePath = path.resolve(task.cwd, relPath)