diff --git a/src/commands/select.ts b/src/commands/select.ts index 25f21f1..cff4d3e 100644 --- a/src/commands/select.ts +++ b/src/commands/select.ts @@ -30,7 +30,16 @@ function closeOldDocument(oldUri: vscode.Uri) { tab.input.uri.toString() === oldUri.toString() ); if (oldTab) { - await vscode.window.tabGroups.close(oldTab); + if (oldTab.isDirty) { + // Use the revert and close command to avoid save prompts for dirty tabs + await vscode.window.showTextDocument(oldUri); + await vscode.commands.executeCommand( + "workbench.action.revertAndCloseActiveEditor" + ); + } else { + // For clean tabs, just close normally + await vscode.window.tabGroups.close(oldTab); + } } } catch (error) { // Fallback method if tab API fails diff --git a/src/test/extension.test.ts b/src/test/extension.test.ts index d3fea45..73dd5b1 100644 --- a/src/test/extension.test.ts +++ b/src/test/extension.test.ts @@ -366,7 +366,7 @@ suite("oil.code", () => { editor.selection = new vscode.Selection(position3, position3); await vscode.commands.executeCommand("oil-code.select"); - await sleep(200); + await sleep(300); const editor3 = vscode.window.activeTextEditor; assert.ok(editor3, "No active editor3"); @@ -374,10 +374,11 @@ suite("oil.code", () => { editBuilder.insert(new vscode.Position(0, 8), newline); editBuilder.insert(new vscode.Position(1, 0), `/002 oil-file.md`); }); + await waitForDocumentText(["/000 ../", "/002 oil-file.md"]); await saveFile(); - await sleep(100); + await sleep(200); await waitForDocumentText(["/000 ../", "/003 oil-file.md"]); @@ -477,7 +478,7 @@ suite("oil.code", () => { await sleep(100); editor.selection = new vscode.Selection(1, 5, 1, 5); await vscode.commands.executeCommand("oil-code.select"); - await sleep(300); + await sleep(500); const editor2 = vscode.window.activeTextEditor; assert.ok(editor2, "No active editor"); diff --git a/src/test/utils/waitFor.ts b/src/test/utils/waitFor.ts index 0d3a49c..edd5230 100644 --- a/src/test/utils/waitFor.ts +++ b/src/test/utils/waitFor.ts @@ -1,6 +1,5 @@ import * as assert from "assert"; import { tryCatch } from "../../tryCatch"; -import { error } from "console"; export async function waitFor( assertion: () => void, @@ -12,7 +11,7 @@ export async function waitFor( } ): Promise { const startTime = Date.now(); - const timeout = options?.timeout || 3000; + const timeout = options?.timeout || 4000; const interval = options?.interval || 100; const endTime = startTime + timeout; while (true) {