Skip to content
gpdoc
Playground

Drop cursor

Draw an insertion indicator while dragging over the editor.

Drag the quote by its handle and move it above “Draft the outline”. The insertion line marks where the quote will land.

Terminal window
cargo add gpdoc-plugin-drop-cursor
use gpdoc_plugin_drop_cursor::{drop_cursor, paint_drop_cursor};
use gpdoc_plugin_paragraph::paragraph;
let config = gpdoc::EditorConfig::builder()
.plugin(paragraph())
.plugin(drop_cursor().with_view(paint_drop_cursor))
.build()
.expect("configure editor");

To draw a blue line with rounded ends, pass your own paint function to with_view. The editor supplies the marker bounds in window coordinates. A block drop above or below another block gets a horizontal line. A side drop that creates a column gets a vertical line. A text drop gets a caret at the insertion point. See Columns.

use gpdoc_plugin_drop_cursor::drop_cursor;
use gpui::{App, Bounds, Pixels, Window, fill, px, rgb};
fn paint_blue_cursor(bounds: Bounds<Pixels>, window: &mut Window, _: &mut App) {
let line = fill(bounds, rgb(0x4263eb)).corner_radii(px(1.));
window.paint_quad(line);
}
let cursor = drop_cursor().with_view(paint_blue_cursor);

Register cursor with .plugin(cursor). To drag blocks by a grip as in the live example, also register the Drag handle plugin.

Drag a file over the editor to see the colored indicator follow a valid drop position. To import files at that position, register the File handler with your app’s import callback.

drop-cursor/src/lib.rs