Closes #53587 Follow-up to #50595. [#50595](https://github.com/zed-industries/zed/pull/50595) added display-only checkboxes when `[x]` / `[X]` / `[ ]` appears as the sole content of a markdown table cell. That PR called out interactivity as a later step — this PR delivers it. https://github.com/user-attachments/assets/c666ee4c-7e31-4450-ab33-c07c82949818 ## What this does When a consumer of `MarkdownElement` supplies an `on_checkbox_toggle` callback, table-cell checkboxes now invoke it on click with the source range of the `[x]` / `[ ]` marker and the new checked state. This mirrors the existing list-item checkbox path. For markdown preview (`markdown_preview_view.rs`) the callback is already wired to edit the source buffer, so clicking a checkbox in a previewed `.md` file now flips `[x]` to `[ ]` and back in the file, the same as it already did for list checkboxes. ## How it works `replace_pending_checkbox` previously took the cell's outer source range and always built a visualization-only checkbox. It now takes the optional toggle callback instead, and reconstructs the marker's exact source range from `pending_line.source_mappings` — pulldown-cmark emits `[x]` in a table cell as three separate `Text` events, so the per-chunk mappings are needed to recover the 3-character range to rewrite. If a callback was supplied, the checkbox attaches an `on_click` that invokes it with that range and `!checked`; otherwise it falls back to the prior visualization-only rendering. Two free helpers (`source_range_for_rendered` / `source_index_for_rendered`) were extracted so the mapping logic is unit-testable. ## Scope One file: `crates/markdown/src/markdown.rs`. No changes to `markdown_preview` — since #52008 it renders through the shared `MarkdownElement`, so its existing `on_checkbox_toggle` wiring picks up table checkboxes for free. ## Relation to #53587 [#53587](https://github.com/zed-industries/zed/issues/53587) reports that markdown checkboxes in the **agent panel** can't be clicked. This PR is a necessary piece of that fix — without it, even if the agent panel wired `on_checkbox_toggle`, its table checkboxes would stay inert. It does not fully close #53587 on its own: the agent panel's `MarkdownElement` instances in `conversation_view.rs` / `thread_view.rs` don't currently wire `on_checkbox_toggle`, and wiring it there requires deciding how clicks should mutate the in-memory agent response (no source file to edit into). That's a follow-up. ## Test plan **Unit tests** (2 new, both in `crates/markdown/src/markdown.rs`): - `test_table_checkbox_marker_source_range` — walks parser events for a table with checkboxes, replays what the builder accumulates, and asserts the reconstructed source range slices to exactly `[x]` / `[ ]` in the original markdown (including a padded-whitespace case). - `test_source_range_for_rendered_handles_split_chunks` — pins the mapping helper against the three-chunk layout pulldown-cmark produces. **Automated**: - [x] `cargo test -p markdown` — 46 tests pass (44 existing + 2 new) - [x] `cargo test -p markdown_preview` — 3 tests pass - [x] `./script/clippy -p markdown` — clean **Manual** (against a preview of a markdown file with checkbox tables): - [x] Click a checked `[x]` table cell — it becomes `[ ]` in the source and rerenders as unchecked - [x] Click an unchecked `[ ]` — becomes `[x]` - [x] Uppercase `[X]` toggles on click (replacement writes `[x]` / `[ ]`, matching the list-item behaviour) - [x] Padded-whitespace cells still target just the three marker characters - [x] Multiple checkbox columns in one table all independently clickable - [x] Alignment variants (left/center/right) behave the same - [x] Non-checkbox table text unaffected - [x] List-item checkboxes continue to work (regression) Release Notes: - Made table-cell markdown checkboxes clickable in markdown preview, matching list-item checkbox behavior Co-authored-by: Lukas Wirth <lukas@zed.dev>
Zed
Welcome to Zed, a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Installation
On macOS, Linux, and Windows you can download Zed directly or install Zed via your local package manager (macOS/Linux/Windows).
Other platforms are not yet available:
- Web (tracking issue)
Developing Zed
Contributing
See CONTRIBUTING.md for ways you can contribute to Zed.
Also... we're hiring! Check out our jobs page for open roles.
Licensing
License information for third party dependencies must be correctly provided for CI to pass.
We use cargo-about to automatically comply with open source licenses. If CI is failing, check the following:
- Is it showing a
no license specifiederror for a crate you've created? If so, addpublish = falseunder[package]in your crate's Cargo.toml. - Is the error
failed to satisfy license requirementsfor a dependency? If so, first determine what license the project has and whether this system is sufficient to comply with this license's requirements. If you're unsure, ask a lawyer. Once you've verified that this system is acceptable add the license's SPDX identifier to theacceptedarray inscript/licenses/zed-licenses.toml. - Is
cargo-aboutunable to find the license for a dependency? If so, add a clarification field at the end ofscript/licenses/zed-licenses.toml, as specified in the cargo-about book.
Sponsorship
Zed is developed by Zed Industries, Inc., a for-profit company.
If you’d like to financially support the project, you can do so via GitHub Sponsors. Sponsorships go directly to Zed Industries and are used as general company revenue. There are no perks or entitlements associated with sponsorship.