Blocks: right-click context menu with Cut/Copy/Paste/Delete

Blocks: right-click context menu with Cut/Copy/Paste/Delete

#9 in Riparion/riparion-editor — merged 2026-06-04

What

Right-clicking a rendered block now opens a context menu (dx catalog context_menu) with Cut / Copy / Paste / Delete, wired in the markdown example through the system clipboard.

How

The library stays widget-free (per the Cargo.toml stance):

  • src/lib.rs — new optional wrap_block: Option<Callback<BlockChrome, Element>> prop on BlockEditor. The host receives a BlockChrome (block index, markdown source, the rendered child to wrap, and delete / insert_after callbacks) for each inactive block, in both arrange and editing modes — never the active textarea. None (default) is fully back-compatible.
  • Structural ops delete_block / insert_block_after mirror add_block's frozen-vs-resplit duality (mutate the frozen snapshot while a block is active; re-split + rejoin_normalized when idle), with active-index adjustment. Pure cores delete_and_normalize / insert_after_and_normalize are unit-tested (4 new tests, 24 total).
  • examples/markdown/ — vendors context_menu via dx components add --module-path examples/markdown/components context_menu (upstream demo-only trigger styles stripped; css_module path rewritten for the example location). Cut/Copy write the block's markdown to the OS clipboard and Paste reads it back via document::eval + navigator.clipboard (best-effort, console-warn on denial). Multi-paragraph pastes re-split into proper blocks.

Verified

Headless-browser run against dx serve --example markdown --features web:

  • menu opens at the pointer with the four items; Copy/Cut land on the real OS clipboard; Paste inserts below the right-clicked block; Delete removes it
  • left-click-to-edit, Esc, and drag-handle reorder all unaffected
  • deleting every block leaves an empty, still-usable editor ("+ New block")
  • cargo test, cargo check (default / --features web / example on host + wasm32-unknown-unknown), clippy all green

🤖 Generated with Claude Code

Last updated 2026-06-05