From f7ecddf912df6f384a42a7c64ce65016f15b5072 Mon Sep 17 00:00:00 2001 From: Roo Code Date: Thu, 2 Oct 2025 21:20:40 +0000 Subject: [PATCH] fix: preserve word wrap setting when opening documents after editing - Save word wrap configuration before opening documents - Restore word wrap configuration after showing documents - Add helper methods to save and restore word wrap settings - Update tests to mock workspace.getConfiguration Fixes #8475 --- src/integrations/editor/DiffViewProvider.ts | 42 +++++++++++++++++++ .../editor/__tests__/DiffViewProvider.spec.ts | 9 ++++ 2 files changed, 51 insertions(+) diff --git a/src/integrations/editor/DiffViewProvider.ts b/src/integrations/editor/DiffViewProvider.ts index 5acf09ea78..716d305586 100644 --- a/src/integrations/editor/DiffViewProvider.ts +++ b/src/integrations/editor/DiffViewProvider.ts @@ -37,6 +37,7 @@ export class DiffViewProvider { private streamedLines: string[] = [] private preDiagnostics: [vscode.Uri, vscode.Diagnostic[]][] = [] private taskRef: WeakRef + private savedWordWrapConfig: string | undefined constructor( private cwd: string, @@ -45,12 +46,38 @@ export class DiffViewProvider { this.taskRef = new WeakRef(task) } + /** + * Saves the current word wrap configuration + */ + private async saveWordWrapConfig(): Promise { + const config = vscode.workspace.getConfiguration("editor") + this.savedWordWrapConfig = config.get("wordWrap") + } + + /** + * Restores the saved word wrap configuration if it was changed + */ + private async restoreWordWrapConfig(): Promise { + if (this.savedWordWrapConfig !== undefined) { + const config = vscode.workspace.getConfiguration("editor") + const currentWordWrap = config.get("wordWrap") + + // Only restore if it was changed + if (currentWordWrap !== this.savedWordWrapConfig) { + await config.update("wordWrap", this.savedWordWrapConfig, vscode.ConfigurationTarget.Global) + } + } + } + async open(relPath: string): Promise { this.relPath = relPath const fileExists = this.editType === "modify" const absolutePath = path.resolve(this.cwd, relPath) this.isEditing = true + // Save the current word wrap configuration before any operations + await this.saveWordWrapConfig() + // If the file is already open, ensure it's not dirty before getting its // contents. if (fileExists) { @@ -208,6 +235,10 @@ export class DiffViewProvider { } await vscode.window.showTextDocument(vscode.Uri.file(absolutePath), { preview: false, preserveFocus: true }) + + // Restore word wrap configuration after showing the document + await this.restoreWordWrapConfig() + await this.closeAllDiffViews() // Getting diagnostics before and after the file edit is a better approach than @@ -409,6 +440,9 @@ export class DiffViewProvider { preview: false, preserveFocus: true, }) + + // Restore word wrap configuration after showing the document + await this.restoreWordWrapConfig() } await this.closeAllDiffViews() @@ -617,6 +651,10 @@ export class DiffViewProvider { async reset(): Promise { await this.closeAllDiffViews() + + // Restore word wrap configuration on reset + await this.restoreWordWrapConfig() + this.editType = undefined this.isEditing = false this.originalContent = undefined @@ -627,6 +665,7 @@ export class DiffViewProvider { this.activeLineController = undefined this.streamedLines = [] this.preDiagnostics = [] + this.savedWordWrapConfig = undefined } /** @@ -666,6 +705,9 @@ export class DiffViewProvider { preview: false, preserveFocus: true, }) + + // Restore word wrap configuration after showing the document + await this.restoreWordWrapConfig() } else { // Just open the document in memory to trigger diagnostics without showing it const doc = await vscode.workspace.openTextDocument(vscode.Uri.file(absolutePath)) diff --git a/src/integrations/editor/__tests__/DiffViewProvider.spec.ts b/src/integrations/editor/__tests__/DiffViewProvider.spec.ts index 0737b143cd..1fd0cedec2 100644 --- a/src/integrations/editor/__tests__/DiffViewProvider.spec.ts +++ b/src/integrations/editor/__tests__/DiffViewProvider.spec.ts @@ -38,6 +38,15 @@ vi.mock("vscode", () => ({ fs: { stat: vi.fn(), }, + getConfiguration: vi.fn(() => ({ + get: vi.fn().mockReturnValue("off"), + update: vi.fn().mockResolvedValue(undefined), + })), + }, + ConfigurationTarget: { + Global: 1, + Workspace: 2, + WorkspaceFolder: 3, }, window: { createTextEditorDecorationType: vi.fn(),