Skip to content

Conversation

@nstrayer
Copy link
Contributor

Addresses #3014.

This PR implements Jupyter-style keyboard shortcuts for cell-level undo, redo, copy, cut, and paste operations in Positron Notebooks. These shortcuts match standard Jupyter behavior and work when in command mode (notebook focused but not editing a cell).

Followup to #2357.

Implemented shortcuts:

  • Z - Undo last cell operation
  • Shift+Z - Redo cell operation
  • C - Copy selected cell(s)
  • X - Cut selected cell(s)
  • V - Paste cell(s) below
  • Shift+V - Paste cell(s) above

These shortcuts only activate when the notebook container is focused but no cell editor is focused (command mode), ensuring they don't interfere with normal text editing.

Release Notes

New Features

  • N/A

Bug Fixes

  • N/A

QA Notes

@:notebooks

  1. Open a notebook in Positron
  2. Add several cells with content
  3. Press Esc to enter command mode (cell should have blue border, not green)
  4. Test each shortcut:
    • Select a cell and press C to copy
    • Press V to paste below, or Shift+V to paste above
    • Press X to cut a cell
    • Press Z to undo the operation
    • Press Shift+Z to redo
  5. Verify shortcuts only work in command mode (when no cell editor is focused)
  6. Press Enter to enter edit mode and verify C, X, V, Z work as normal text editing keys

@nstrayer nstrayer requested a review from Copilot October 21, 2025 20:13
@github-actions
Copy link

github-actions bot commented Oct 21, 2025

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

readme  valid tags

Copy link
Contributor

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 adds Jupyter-style keyboard shortcuts for notebook cell operations, replacing traditional OS-specific shortcuts (Cmd/Ctrl+C/X/V/Z) with single-key shortcuts (C/X/V/Z) that only work in command mode when no cell editor is focused.

Key Changes

  • Adds single-key shortcuts (Z, Shift+Z, C, X, V, Shift+V) for undo/redo and cell copy/cut/paste operations
  • Implements command mode detection using POSITRON_NOTEBOOK_EDITOR_CONTAINER_FOCUSED and negated POSITRON_NOTEBOOK_CELL_EDITOR_FOCUSED context keys
  • Removes OS-specific keybinding modifiers (CtrlCmd) from cell operation commands

@nstrayer nstrayer requested a review from Copilot October 22, 2025 14:43
Copy link
Contributor

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 3 out of 3 changed files in this pull request and generated 3 comments.

@nstrayer nstrayer force-pushed the positron-nb-jupyter-keymaps-pt2 branch from b3fe926 to 641e023 Compare October 22, 2025 15:14
dhruvisompura
dhruvisompura previously approved these changes Oct 22, 2025
Copy link
Contributor

@dhruvisompura dhruvisompura left a comment

Choose a reason for hiding this comment

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

These changes worked well for me! Looks good once the conflict is resolved.

I did want to ask about this comment in the PR description:

Press Esc to enter command mode (cell should have blue border, not green)

I don't see a green border around the cells at any point, is that supposed to be the case?

One thing I did notice while testing these keybindings is that its a bit annoying to do a sequence of actions like copy + paste because of how we automatically enter edit mode when we add a new cell to the notebook. The sequence to copy and paste a cell ends up being C, Escape, V.

I'm wondering if we should revisit that notion? Doesn't have to be in this PR!

seeM
seeM previously approved these changes Oct 23, 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.

Looks great! I agree with @dhruvisompura it shouldn't enter edit mode when new cells are added. Jupyter Lab behaves the way we're suggesting as well

@nstrayer nstrayer dismissed stale reviews from seeM and dhruvisompura via 18cb0d7 October 23, 2025 15:20
@nstrayer nstrayer force-pushed the positron-nb-jupyter-keymaps-pt2 branch from 641e023 to 18cb0d7 Compare October 23, 2025 15:20
@nstrayer nstrayer merged commit 3ef7d1d into main Oct 23, 2025
11 of 12 checks passed
@nstrayer nstrayer deleted the positron-nb-jupyter-keymaps-pt2 branch October 23, 2025 17:48
@github-actions github-actions bot locked and limited conversation to collaborators Oct 23, 2025
@nstrayer
Copy link
Contributor Author

@seeM and @dhruvisompura Re: the entering-edit-mode annoyance #10120

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