Box selection
Drag a rectangle from the margin outside a block to select whole blocks.
Try it
Section titled “Try it”Press in the left margin beside “Draft the outline”. Hold the mouse button and drag diagonally across “Review the draft”. Both paragraphs highlight as the rectangle crosses them. Release to keep the blocks selected.
Start the drag outside all blocks. Inside a paragraph, even the blank space after the last character uses normal text selection. The box selects whole top-level blocks, including an entire list or table when it intersects one.
Install
Section titled “Install”cargo add gpdoc-plugin-box-selectionExample
Section titled “Example”use gpdoc_plugin_box_selection::{box_selection, selection_box};use gpdoc_plugin_paragraph::paragraph;
let config = gpdoc::EditorConfig::builder() .plugin(paragraph()) .plugin(box_selection().with_view(selection_box)) .build() .expect("configure editor");Use EditorSurface::layout to leave space between the editable document and the edge of the surface. A drag starting in this space can select blocks. The page layout example centers the document and leaves a gutter on both sides.
For keyboard-based block selection, also register Node range.
Compose the selection rectangle
Section titled “Compose the selection rectangle”Anatomy
Section titled “Anatomy”box_selection().with_view(...) Tracks the drag and selects intersecting blocks└── bounds Position and size of the rectangle in the window └── selection_box(...) Fills the rectangle with the default overlayAdd a label to the rectangle
Section titled “Add a label to the rectangle”Replace selection_box in the example with this renderer. It keeps the default rectangle and adds a label while the drag is in progress.
use gpui::{App, Bounds, Div, Pixels, Window, prelude::*};
fn labeled_box(bounds: Bounds<Pixels>, window: &mut Window, cx: &mut App) -> Div { selection_box(bounds, window, cx).child("Select blocks")}Release the mouse to hide the rectangle and keep the intersecting blocks selected.