Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion src/integrations/editor/DiffViewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,9 @@ 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)
const showOptions = { preview: false, viewColumn: vscode.ViewColumn.Active, preserveFocus: true }
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I noticed that preserveFocus: true is consistently used in other showTextDocument calls within this file (lines 199, 374, 441), which is great. However, there are other places in the codebase that might benefit from this pattern:

  • src/services/marketplace/MarketplaceManager.ts:129
  • src/integrations/misc/export-markdown.ts:40

Is it intentional that these other locations don't preserve focus? If they could also cause focus issues during automated workflows, would it make sense to apply the same pattern there for consistency?

vscode.window
.showTextDocument(uri, { preview: false, viewColumn: vscode.ViewColumn.Active })
.showTextDocument(uri, showOptions)
.then(() => {
// Execute the diff command after ensuring the file is open as text
return vscode.commands.executeCommand(
Expand Down
10 changes: 8 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,13 @@ 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(
expect.objectContaining({
preview: false,
viewColumn: vscode.ViewColumn.Active,
preserveFocus: true,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

While the tests correctly verify that preserveFocus: true is passed to the API, they don't test the actual focus behavior. Have you considered adding an integration test that verifies the chat input maintains focus during file operations?

I understand this might be challenging in a unit test environment, but it could be valuable for preventing regressions of this specific bug. Perhaps this could be added to the E2E test suite if it's not feasible here?

}),
)
return mockEditor as any
})

Expand Down Expand Up @@ -211,7 +217,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 },
expect.objectContaining({ preview: false, viewColumn: vscode.ViewColumn.Active, preserveFocus: true }),
)

// Verify that the diff command was executed
Expand Down
Loading