Skip to content

Add output-focused state to Positron notebooks for context-dependent Cmd+C #12434

@nstrayer

Description

@nstrayer

Currently Positron notebooks have no concept of "output focused" as a distinct focus state. The selection state machine tracks cell-level states (NoCells, SingleSelection, MultiSelection, EditingSelection) but nothing for outputs. Output DOM elements have no tabIndex and focusNotebookCell('output') is a no-op stub.

This means there's no way to bind keyboard shortcuts like Cmd+C to copy an image only when the user has explicitly focused the output area. Without this, Cmd+C either always copies cell source (current behavior after #12331) or always copies the image when one exists (which overrides the more common copy-source operation).

Proposed behavior

  • Add tabIndex={0} to the output section so users can Tab or click into it
  • Add a positronNotebookOutputFocused context key that tracks when the output area has DOM focus
  • When output is focused and the cell has image output, Cmd+C copies the image to clipboard
  • When the cell container is focused (command mode), Cmd+C copies cell source as usual
  • Visual focus indicator on the output area so the user knows which region is active

Context

  • Upstream VSCode notebooks have NOTEBOOK_OUTPUT_FOCUSED (notebookContextKeys.ts) and CellFocusMode.Output for this purpose
  • There's already a focus trap div between the editor and outputs (CellEditorMonacoWidget.tsx) that could serve as a natural entry point to output focus
  • Feat/notebook copy output image #12331 adds the "Copy Image" action to the ellipsis menu and browser right-click as an interim solution

References

  • PR Feat/notebook copy output image #12331 -- Copy image action for notebook cell outputs
  • selectionMachine.ts -- Would need a new state or sub-state for output focus
  • ContextKeysManager.ts -- Where the new context key would be defined
  • NotebookCodeCell.tsx -- Output section DOM needs focusable elements
  • CellEditorMonacoWidget.tsx:73-88 -- Existing focus trap between editor and outputs

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions