text-document 0.0.8

Rich text document editing library
Documentation

text-document

A rich text document model for Rust.

Provides a [TextDocument] as the main entry point and [TextCursor] for cursor-based editing, inspired by Qt's QTextDocument/QTextCursor API.

use text_document::{TextDocument, MoveMode, MoveOperation};

let doc = TextDocument::new();
doc.set_plain_text("Hello world").unwrap();

let cursor = doc.cursor();
cursor.move_position(MoveOperation::EndOfWord, MoveMode::KeepAnchor, 1);
cursor.insert_text("Goodbye").unwrap(); // replaces "Hello"

// Multiple cursors on the same document
let c1 = doc.cursor();
let c2 = doc.cursor_at(5);
c1.insert_text("A").unwrap();
// c2's position is automatically adjusted

doc.undo().unwrap();