text-editing 0.2.3

A simple string with utilities for editing
Documentation

Text Editing Library

A simple string with utilities for editing, specifically designed to work with non-ASCII strings.

Features

  • Provides a TextLine struct that represents an editable text line.
  • Supports efficient insertion, removal, and manipulation of characters, strings, and ranges.
  • Handles non-ASCII characters correctly, taking into account their multi-byte nature.
  • Cursor movement: forward, backward, word-skip, Home/End.
  • Selection support: extend selection by character or word, select all, delete or replace selection.
  • Implements Display, FromStr, and From conversions.

Documentation

API documentation can be found at docs.rs/text-editing.

Example

use text_editing::TextLine;

let mut line = TextLine::from_string("Hello, 🌍!".into());
line.insert(7, 'w');
assert_eq!(line.as_str(), "Hello, w🌍!");

let removed_char = line.remove(7);
assert_eq!(removed_char, 'w');
assert_eq!(line.as_str(), "Hello, 🌍!");

Selection

use text_editing::TextLine;

let mut line = TextLine::from_string("Hello, world!".into());
let mut cursor = 7;
let mut anchor = None;

// Select "world" with Shift+Ctrl+Right
line.select_forward_skip(&mut cursor, &mut anchor);
assert_eq!(line.selected_text(cursor, anchor), Some("world"));

// Replace selection
line.replace_selection(&mut cursor, &mut anchor, "Rust");
assert_eq!(line.as_str(), "Hello, Rust!");