Skip to content

Conversation

nstrayer
Copy link
Contributor

@nstrayer nstrayer commented Oct 6, 2025

Addresses #9707.

When opening a Positron notebook, the editor was not properly focusing a cell, requiring users to click a cell before keyboard shortcuts like j and k for navigation would work. This PR fixes the issue by replacing the no selection state with a no-cells state in the selection state machine and adding an invariant to ensure at least one cell is always selected when the notebook contains cells.

I took this opportunity to refactor the selection state machine too as it had fallen out of good state-machine form after piecemeal edits for a while. Docs have been added at the top and we now verify transition correctness and throw errors in dev mode to hopefully catch bugs (It already caught one while making this PR.)

Release Notes

New Features

  • N/A

Bug Fixes

QA Notes

@:positron-notebooks

The test suite includes comprehensive coverage of the fix:

  1. Basic focus on open: Open a notebook file (e.g., via Cmd+P) and verify the first cell is automatically selected
  2. Immediate keyboard navigation: Without clicking any cell, press J or K to verify navigation works immediately
  3. Selection persistence: Switch between editors and verify cell selection is maintained when returning to the notebook

To manually test:

  1. Open any notebook file using Cmd+P (or Ctrl+P on Windows/Linux)
  2. Without clicking anywhere, press J or K
  3. Expected: Cell selection moves down/up immediately
  4. Previously: Nothing happened until clicking a cell

@nstrayer nstrayer requested review from seeM, midleman and Copilot October 6, 2025 18:21
Copy link

github-actions bot commented Oct 6, 2025

E2E Tests 🚀
This PR will run tests tagged with: @:critical @:positron-notebooks

readme  valid tags

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an issue where Positron notebooks didn't automatically focus a cell when opened, requiring users to click before keyboard navigation would work. The fix replaces the NoSelection state with a NoCells state in the selection state machine and adds an invariant to ensure at least one cell is always selected when cells exist in the notebook.

Key changes:

  • Refactored the selection state machine with comprehensive documentation and transition validation
  • Added automatic cell selection when notebooks are opened
  • Enhanced test coverage with new focus and selection behavior tests

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

File Description
src/vs/workbench/contrib/positronNotebook/browser/selectionMachine.ts Core fix: refactored state machine with NoCells state and invariant enforcement for automatic selection
test/e2e/tests/notebook/notebook-focus-and-selection.test.ts Added comprehensive tests for initial focus behavior and keyboard navigation without clicks
test/e2e/infra/test-runner/test-tags.ts Added POSITRON_NOTEBOOKS test tag for categorizing Positron-specific notebook tests
Multiple test files Updated test descriptions to include the new POSITRON_NOTEBOOKS tag for proper test organization

@nstrayer nstrayer requested a review from rodrigosf672 October 6, 2025 18:22
midleman
midleman previously approved these changes Oct 6, 2025
Copy link
Contributor

@midleman midleman left a comment

Choose a reason for hiding this comment

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

Looks good from test perspective! As mentioned in a comment, I'm going to do a pass through of all the positron nb e2e test code and will likely make some infra optimizations. But... can you also tag this PR for @:win and re-run? Basically, anytime we add a new test we def want to make sure it passes there as well... because well... Windows. 😆

seeM
seeM previously approved these changes Oct 7, 2025
Copy link
Contributor

@seeM seeM left a comment

Choose a reason for hiding this comment

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

Code changes LGTM! A couple questions about the spec

@nstrayer nstrayer dismissed stale reviews from seeM and midleman via 6dba64c October 7, 2025 15:00
@nstrayer nstrayer requested review from seeM and Copilot October 7, 2025 17:48
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.

@nstrayer
Copy link
Contributor Author

nstrayer commented Oct 7, 2025

Test failure is a data explorer test that seems flakey.

Copy link
Contributor

@seeM seeM left a comment

Choose a reason for hiding this comment

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

I like it!

@nstrayer nstrayer merged commit cb40b1a into main Oct 8, 2025
11 of 12 checks passed
@nstrayer nstrayer deleted the positron-nb-focus-on-open branch October 8, 2025 13:27
@github-actions github-actions bot locked and limited conversation to collaborators Oct 8, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants