Skip to content

[AIR #1074] vscode: align backlog issue-preview placement with count-then-pick (remove focus side-effect)#1076

Merged
amrmelsayed merged 4 commits into
mainfrom
builder/air-1074
Jun 18, 2026
Merged

[AIR #1074] vscode: align backlog issue-preview placement with count-then-pick (remove focus side-effect)#1076
amrmelsayed merged 4 commits into
mainfrom
builder/air-1074

Conversation

@amrmelsayed

Copy link
Copy Markdown
Collaborator

Summary

Aligns the backlog issue-preview placement with the count-then-pick pattern the builder/shell terminals already use (Bugfix #804), removing the focus side-effect that view-issue.ts previously relied on.

The old code (view-issue.ts:173-174) did a two-step dance:

await vscode.commands.executeCommand('workbench.action.focusFirstEditorGroup');
await vscode.commands.executeCommand('markdown.showPreviewToSide', uri);

It worked only because focusing group 1 first pinned Beside to group 2. That stole focus from wherever the user was sitting and, if any caller skipped the focus step, chained previews into groups 3/4/5.

Key decision: corrected API path

The issue proposed markdown.showPreview(uri, viewColumn, preserveFocus). I verified against the bundled VS Code 1.124.2 markdown extension that this command does not accept an explicit viewColumn and has no preserveFocus parameter — ShowPreviewCommand.execute(mainUri, allUris, {locked}) hardcodes sideBySide: false and always opens in the active editor group. I surfaced this to the architect rather than coding against the wrong signature.

The architect directed the corrected approach: open the built-in preview's custom-editor viewType via vscode.openWith, which does accept an explicit ViewColumn + TextDocumentShowOptions:

const viewColumn = pickIssuePreviewColumn(vscode.window.tabGroups.all.length);
await vscode.commands.executeCommand(
  'vscode.openWith', uri, 'vscode.markdown.preview.editor', { viewColumn, preserveFocus: true },
);

Changes

  • commands/view-issue.ts: drop focusFirstEditorGroup; add the pure helper pickIssuePreviewColumn(groupCount) (group 2 when >= 2, else group 1 — if/else, mirroring terminal-manager.ts); call vscode.openWith with an explicit column + preserveFocus: true.
  • src/__tests__/view-issue-column.test.ts: unit test for the column decision logic (mocked tabGroups.all.length → 1/2/3/5/0), following the diff-nav.test.ts minimal-vscode-mock pattern.
  • Cache / refresh / close-cleanup (IssueContentProvider, OverviewCache.onDidChange, onDidCloseTextDocument) untouched.

Acceptance criteria

  • No more workbench.action.focusFirstEditorGroup.
  • Explicit viewColumn derived from vscode.window.tabGroups.all.length.
  • Group 2 when a second group exists; group 1 otherwise.
  • Focus preserved on the click origin (preserveFocus: true).
  • No group-chaining / Beside fragility (explicit column, not Beside).
  • Unit test for the viewColumn decision logic.
  • No regression to cache / refresh / close-cleanup.

Note: the criterion as literally worded named markdown.showPreview, but that command cannot take an explicit column (verified, see above). The architect approved vscode.openWith + the built-in preview viewType as the correct way to satisfy the intent of every criterion.

Test plan

  • pnpm check-types — clean
  • eslint src/commands/view-issue.ts src/__tests__/view-issue-column.test.ts — clean
  • pnpm test:unit (full vitest run) — 35 files / 446 tests pass (incl. 4 new)
  • Manual (recommended at review): click a backlog row with a 2nd editor group open → preview lands in group 2, focus stays on the sidebar; repeat-click → reuses the same group (no 3/4/5 chaining); with a single group → preview lands in group 1.

Closes #1074.

…pattern

Replace the focusFirstEditorGroup + markdown.showPreviewToSide dance in
view-issue.ts with an explicit count-then-pick that opens the built-in
markdown preview via vscode.openWith.

The built-in markdown.showPreview / showPreviewToSide commands anchor the
preview to the active editor group and ignore any column argument, so the
old code force-focused group 1 to make Beside resolve to group 2 - a focus
side-effect that stole focus from the click origin and chained previews into
groups 3/4/5 if any caller skipped the focus step.

vscode.openWith with viewType vscode.markdown.preview.editor (VS Code's
built-in preview custom editor, distinct from Codev's codev.markdownPreview
canvas - so no overlap with #1068) accepts an explicit ViewColumn plus
{ preserveFocus: true }. Placement is now deterministic (group 2 when a
second group exists, else group 1), focus stays on the backlog row, and
there is no Beside-chaining or group-1-closed fragility.

Adds pickIssuePreviewColumn(groupCount) + a unit test for the decision logic.
Cache / refresh / close-cleanup behavior is untouched.
@amrmelsayed amrmelsayed merged commit 856bc5e into main Jun 18, 2026
6 checks passed
amrmelsayed added a commit that referenced this pull request Jun 18, 2026
CHANGELOG.md: Bug fixes (focus-stealing + group-chaining fix).
UNRELEASED.md: Polish bullet (small consistency item, AIR-sized).
Both clarify the placement change does not migrate off the built-in
markdown preview - that's a separate decision in #1068.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vscode: align backlog issue-preview placement with builder-terminal count-then-pick pattern (remove focus side-effect)

1 participant