weirdnet-text 0.1.1

Toolkit-independent editing rules for one-line and multiline text fields: grapheme-aware caret movement, selection, deletion, inline completions, input-method composition and UTF-16 offsets.
Documentation
  • Coverage
  • 37.5%
    12 out of 32 items documented1 out of 32 items with examples
  • Size
  • Source code size: 18.3 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 129.7 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 2s Average build duration of successful builds.
  • all releases: 2s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • WeirdBrains/weirdnet-text
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • m3talsmith

weirdnet-text

Toolkit-independent editing rules for text fields, so the behaviour can be tested without a UI and shared by every Weirdnet app's text inputs (Morph's address bar, Bragi's prompt).

TextField holds the text, the selection (and which end of it moves) and any text an input method has marked while composing. It handles typing and pasting at the caret, Backspace and Delete by whole grapheme clusters, Left/Right/Home/End with and without Shift, select-all, inline completions (append_selected: the suggestion is selected, so typing replaces it, Backspace removes it and Right accepts it), input-method composition (replace_and_mark) and UTF-8 ↔ UTF-16 offset conversion for platform input APIs. One-line fields turn line breaks into spaces; TextField::multiline() keeps them (normalising \r\n and \r to \n).

use weirdnet_text::TextField;

let mut field = TextField::new();
for ch in "git".chars() {
    field.replace(None, &ch.to_string());
}
field.append_selected("hub.com"); // inline completion, selected
field.right();                    // Right accepts it
assert_eq!((field.text(), field.cursor()), ("github.com", 10));

field.select_left();
field.backspace();
assert_eq!(field.text(), "github.co");

The widget that draws a field and feeds it keys and input-method events stays in each app's toolkit layer (GPUI in Morph and Bragi); only these rules are shared.

Status

0.1.0, extracted unchanged from Morph's morph-ui text module. License: BSD-3-Clause.