Skip to content

data_table: Extend a cell range with Shift and the arrow keys - #4183

Merged
huacnlee merged 3 commits into
mainfrom
agent/T-12878-data-table-keyboard-range
Dec 3, 2026
Merged

huacnlee merged 3 commits into
mainfrom
agent/T-12878-data-table-keyboard-range

Conversation

@huacnlee

@huacnlee huacnlee commented Dec 3, 2026

Copy link
Copy Markdown
Member

Closes #4176

Description

With cellSelectable and cellRangeSelectable, a cell range could only be made with the pointer (drag or Shift-press). Shift with the arrow keys was not bound, so a keyboard user could not make or change a range.

Shift with the arrows, Page Up, Page Down, Home and End now moves the range's end and keeps its start and active cell, the same model a Shift-press already uses (and the one spreadsheets use):

  • A single selected cell starts a range at itself; a range whose end comes back to its start becomes that cell again.
  • The end moves in displayed column order (moved and fixed columns included) and skips non-selectable columns, as the plain arrows do.
  • The end stops at the table's edges; loopSelection does not make a range jump to the other side.
  • The moving end is scrolled into view.
  • Without a cell or range selected (nothing, a row, a column), Shift with a key moves as the key alone does.
  • The bindings are only registered with cellRangeSelectable; tables without it see no change.

GPUI Kit's table has no cell ranges, so there is no Kit interaction to match; the behavior follows the existing Shift-press path in this component.

#4177 (Copy on a range copies only the active cell) was already fixed on main by #3955, after 0.8.0. The new tests here also cover it from the keyboard: a range grown with Shift+arrow, including a reversed one and one crossing a fixed-right column, copies its cells as TSV from the top-left cell in display order.

Known gap: Edit > Copy from the menu bar (macOS)

Cmd+C reaches the table: NSH's key monitor matches the table's mod+c binding before AppKit's menu key equivalents. Choosing Edit > Copy with the mouse does not: the item's copy: goes to the root view, which only copies text selections (nsh-platform-macos/src/view.rs → text::copy), so with a table focused it copies nothing while the item stays enabled. Routing a menu role to the focused component is a cross-platform change of its own and is not part of this PR.

Screenshot

macOS, real window (nsh test --target macos, the gallery fixture after Shift+Down, Shift+Right ×2, Shift+Up ×2: sel=1,1>0,3). The Mac this ran on was locked, so the picture is drawn in process and does not show the range highlight; the test asserts the selection and the clipboard text on the real platform.

macOS key range

Public API

None. Behavior change only: Shift + arrow / Page Up / Page Down / Home / End with cellRangeSelectable on.

How to Test

cargo test -p nsh-base --lib data_table::selection
cargo test -p nsh-base --test base data_table::
cargo build -p nsh-cli
./target/debug/nsh test examples/gallery/tests/data-table-interactions.test.tsx
./target/debug/nsh test examples/gallery/tests/data-table-interactions.test.tsx --target macos --filter "shift and the arrows"
  • 3 new unit tests for the range step (Nav::extend): growing, reversing, Home/End/Page, keeping an app-given active cell, edges without wrap, shrinking back to the cell, and the plain fallback.
  • 2 new headless Rust tests and 1 gallery test. Both Rust tests fail on main (Chosen range 0,1 to 1,1 / Chosen range 2,2 to 1,1 never shows) and pass with this change; all 32 DataTable Rust tests pass.
  • The gallery test passes headless and in a real macOS window. On the full gallery file, the headless run's only failure was the screenshot step that was later removed from the test.

Checklist

  • I have read the CONTRIBUTING document and followed the guidelines.

🤖 Generated with Claude Code

🤖 Noop (rust-maintainer) · Opus 5.5 acting for @huacnlee

With `cellRangeSelectable`, Shift with the arrows, Page Up, Page Down,
Home and End now moves the end of the cell range and keeps its start
and active cell, as a Shift-press already does. A single cell starts a
range at itself, a range whose end comes back to its start is the cell
again, and the end stops at the table's edges instead of wrapping. The
moving end is kept in view.

Closes #4176

Agent: rust-maintainer
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@huacnlee

huacnlee commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

The two failing checks are not from this change (it only touches DataTable):

🤖 Noop (rust-maintainer) · AI agent acting for @huacnlee

@huacnlee

huacnlee commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

✅ LGTM: Shift+Arrow/Page/Home/End extend the cell range like Shift-click, bound only with cellRangeSelectable, no public API.

  • data_table/selection.rs Nav::extend clamps at edges, ignores loopSelection, skips non-selectable columns, collapses back to a single cell; matches spreadsheet behavior.
  • data_table/controller.rs registers bindings only with cellRangeSelectable.
  • Tests fail on main and pass here; TSV copy covered for reversed and fixed-right ranges.
  • Nit: the screenshot does not show the highlight (Mac was locked); replace with an unlocked capture.

Reviewed head 8d77090 (read-only diff review).

🤖 Noop (reviewer) · AI agent acting for @huacnlee

@huacnlee

huacnlee commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

Merged main to pick up the dead-code fixes behind the clippy failures (insert_transient on web, hosted_content_loading/busy on macOS). No conflicts.

🤖 Noop (rust-maintainer) · AI agent acting for @huacnlee

huacnlee added a commit that referenced this pull request Dec 3, 2026
Follow-up to #4177 / #4183.

## Problem

On macOS, Cmd+C reaches a focused DataTable's `mod+c` binding (the
keymap monitor matches before menu key equivalents), but choosing **Edit
> Copy** with the mouse sends `copy:` to the root view, which only runs
`text::copy` (selected text). With a table focused nothing is copied,
and the item is still enabled.

Platform check:

| Platform | Menu Copy before | After |
| --- | --- | --- |
| macOS | `copy:` on the root → selected text only | bindings of Cmd+C
first, then selected text |
| Linux | `clipboard.copy` action on the GTK focus widget; NSH views
other than text / selectable views have none → nothing | bindings of
Ctrl+C first, then the widget's action |
| Windows | already replays Ctrl+C through `input::key` → `keymap::key`
| unchanged |

## Change

The Edit menu's commands run the bindings their standard key has where
the focus is, exactly as pressing the key does, then fall back to the
default.

- **macOS** (`view.rs`, `keymap.rs`)
- `copy:` / `selectAll:` on NSH's root view try the Cmd+C / Cmd+A
bindings first (`keymap::command`, sharing the focus rules of
`keymap::pressed` via a new private `focus_in`).
- New `cut:` / `paste:` on the root run the Cmd+X / Cmd+V bindings (e.g.
an editor's); there was no handler before, so with no binding they stay
disabled as today.
- `validateMenuItem:` enables Copy only when a binding or selected text
takes it, and Cut / Paste only when a binding does (AppKit's native
"nothing to copy" state).
- When a key-down is in flight, the menu action skips the bindings: the
keyboard monitor already ran them, so a pass-through binding is not
reported twice.
- **Linux** (`chrome.rs`, `keymap.rs`): the edit roles run the Ctrl+key
bindings (`keymap::press`, no longer dev-only) before activating
`clipboard.*` / `selection.select-all` on the focus widget. Edit roles
register no accelerators on Linux, so this path only runs for a menu
click or `Menu.perform`.

**Public API:** none. No new public items in `nsh-core` or the platform
crates; this only changes what the platform-built Edit menu (and
`Menu.perform`) does, matching the keyboard.

## Tests

- New native check `tests/native/menu_copy.rs`
(`NSH_MENU_COPY_CHECK_ONLY=1 cargo test -p nsh-platform-macos --test
native -- --ignored`): with `mod+c` / `mod+v` bound, the root enables
Copy / Paste and disables Cut; sending `copy:` / `paste:` fires the
bindings once; with an `NSTextView` focused, Copy stays the field's and
the binding is not offered. Fails on `main` (the root has no
`validateMenuItem:`), passes here.
- Unit tests (macOS and Linux `keymap.rs`): the menu keystroke of Copy /
Cut / Paste / Select All equals `Keystroke::parse("mod+c" …)`, the form
bindings use.
- `NSH_KEYBOARD_CHECK_ONLY=1` native check passes; `cargo clippy -p
nsh-platform-macos --tests` clean for the changed files.

Not verified locally: Linux (the crate only builds on Linux; CI covers
compile + unit tests), and a real menu-bar click in an unlocked session.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

🤖 [Noop](https://huacnlee.github.io/noop) (rust-maintainer) · AI agent
acting for @huacnlee

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@huacnlee

huacnlee commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

The check (macos-15) and web Clippy failures here are not from this PR: main fails them too (unused hosted_content_loading/busy without dev from #4151, unused insert_transient on wasm32 from #4152). Fix: #4212. All other checks that finished pass.

🤖 Noop (rust-maintainer) · AI agent acting for @huacnlee

@huacnlee
huacnlee merged commit 8376951 into main Dec 3, 2026
10 of 28 checks passed
@huacnlee
huacnlee deleted the agent/T-12878-data-table-keyboard-range branch December 3, 2026 12:29
huacnlee added a commit that referenced this pull request Dec 3, 2026
)

Main currently fails two Clippy jobs on every PR (seen on #4183 and
#4194):

- `check (macos-15)` (`cargo clippy -p nsh-macos-app
--no-default-features --features js`): `hosted_content_loading`,
`WebHost::busy` and the `loading` field are never used. They only serve
`Surface::animating`, which is `#[cfg(feature = "dev")]` (added in
#4151).
- `web` (`cargo clippy ... --target wasm32-unknown-unknown`):
`MemoryCache::insert_transient` is never used. Its only caller is the
decoder, which the web target does not build (added in #4152).

Changes:

- Build `hosted_content_loading` and `WebHost::busy` only with `dev`,
and allow the `loading` field (still written by the navigation delegate)
to go unread without `dev`.
- Allow `insert_transient` to be unused on wasm32, as `access.rs`
already does for its web-only dead code.

No behavior or public API change.

Verification: CI on this PR (the two failing jobs above). A local
single-core Clippy run did not finish in time on a loaded host.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

🤖 [Noop](https://huacnlee.github.io/noop) (rust-maintainer) · AI agent
acting for @huacnlee

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

DataTable: Shift+arrow does not extend a cell range

1 participant