Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/integrations/editor/DiffViewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ export class DiffViewProvider {
// Pre-open the file as a text document to ensure it doesn't open in preview mode
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're now also preserving focus to fix the chat input issue, would it be helpful to update this comment to reflect both purposes? Something like:

// Pre-open the file as a text document to ensure it doesn't open in preview mode
// This fixes issues with files that have custom editor associations (like markdown preview)
// and preserves focus on the chat input during automated editing workflows

// This fixes issues with files that have custom editor associations (like markdown preview)
vscode.window
.showTextDocument(uri, { preview: false, viewColumn: vscode.ViewColumn.Active })
.showTextDocument(uri, { preview: false, viewColumn: vscode.ViewColumn.Active, preserveFocus: true })
Copy link

Copilot AI Jun 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Extract the options object into a named constant (e.g., const showOptions = { preview: false, viewColumn: ..., preserveFocus: true };) to reduce duplication and improve readability.

Suggested change
.showTextDocument(uri, { preview: false, viewColumn: vscode.ViewColumn.Active, preserveFocus: true })
.showTextDocument(uri, showOptions)

Copilot uses AI. Check for mistakes.
.then(() => {
// Execute the diff command after ensuring the file is open as text
return vscode.commands.executeCommand(
Expand Down
4 changes: 2 additions & 2 deletions src/integrations/editor/__tests__/DiffViewProvider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ describe("DiffViewProvider", () => {
// Mock showTextDocument to track when it's called
vi.mocked(vscode.window.showTextDocument).mockImplementation(async (uri, options) => {
callOrder.push("showTextDocument")
expect(options).toEqual({ preview: false, viewColumn: vscode.ViewColumn.Active })
expect(options).toEqual({ preview: false, viewColumn: vscode.ViewColumn.Active, preserveFocus: true })
Copy link

Copilot AI Jun 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This strict equality assertion can be brittle if more options are added in the future. Consider using expect.objectContaining or toMatchObject to only verify the relevant keys.

Suggested change
expect(options).toEqual({ preview: false, viewColumn: vscode.ViewColumn.Active, preserveFocus: true })
expect(options).toEqual(expect.objectContaining({ preview: false, viewColumn: vscode.ViewColumn.Active, preserveFocus: true }))

Copilot uses AI. Check for mistakes.
return mockEditor as any
})

Expand Down Expand Up @@ -211,7 +211,7 @@ describe("DiffViewProvider", () => {
// Verify that showTextDocument was called with preview: false
expect(vscode.window.showTextDocument).toHaveBeenCalledWith(
expect.objectContaining({ fsPath: `${mockCwd}/test.md` }),
{ preview: false, viewColumn: vscode.ViewColumn.Active },
{ preview: false, viewColumn: vscode.ViewColumn.Active, preserveFocus: true },
Copy link

Copilot AI Jun 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Similarly, this exact match could break if additional options are introduced. Using expect.objectContaining for the options object will make the test more resilient.

Suggested change
{ preview: false, viewColumn: vscode.ViewColumn.Active, preserveFocus: true },
expect.objectContaining({ preview: false, viewColumn: vscode.ViewColumn.Active, preserveFocus: true }),

Copilot uses AI. Check for mistakes.
)

// Verify that the diff command was executed
Expand Down