From 9e57dd652abe1b00694d434c02fa6e3507a1d8f2 Mon Sep 17 00:00:00 2001 From: Roo Code Date: Sat, 15 Nov 2025 16:29:01 +0000 Subject: [PATCH] fix: improve scroll position restoration timing - Close diff views before showing text document to avoid interference - Add 50ms delay after showing document to ensure editor is initialized - This fixes the issue where scroll position was jumping to start despite being captured - Applies to both saveChanges() and revertChanges() methods --- src/integrations/editor/DiffViewProvider.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/integrations/editor/DiffViewProvider.ts b/src/integrations/editor/DiffViewProvider.ts index 4557bfb8ef..859f8a1584 100644 --- a/src/integrations/editor/DiffViewProvider.ts +++ b/src/integrations/editor/DiffViewProvider.ts @@ -214,11 +214,17 @@ export class DiffViewProvider { await updatedDocument.save() } + // Close diff views first to avoid interference with the text editor + await this.closeAllDiffViews() + + // Show the text document const editor = await vscode.window.showTextDocument(vscode.Uri.file(absolutePath), { preview: false, preserveFocus: true, }) - await this.closeAllDiffViews() + + // Add a small delay to ensure the editor is fully initialized before restoring scroll position + await new Promise((resolve) => setTimeout(resolve, 50)) // Restore the cursor position and scroll position from the diff view // First set the selection to where the cursor was @@ -437,12 +443,19 @@ export class DiffViewProvider { await vscode.workspace.applyEdit(edit) await updatedDocument.save() + // Close diff views first to avoid interference with the text editor + await this.closeAllDiffViews() + if (this.documentWasOpen) { + // Show the text document const editor = await vscode.window.showTextDocument(vscode.Uri.file(absolutePath), { preview: false, preserveFocus: true, }) + // Add a small delay to ensure the editor is fully initialized before restoring scroll position + await new Promise((resolve) => setTimeout(resolve, 50)) + // Restore the cursor position and scroll position from the diff view // First set the selection to where the cursor was editor.selection = selection @@ -462,8 +475,6 @@ export class DiffViewProvider { editor.revealRange(new vscode.Range(midPoint, 0, midPoint, 0), vscode.TextEditorRevealType.InCenter) } } - - await this.closeAllDiffViews() } // Edit is done.