Skip to main content

Module text

Module text 

Source
Expand description

Text storage and editing with styled segments.

This module provides rope-backed text buffers for efficient editing of large documents.

§Grapheme Pool Policy

This module’s public API uses &str for text content, keeping grapheme pool details internal. Multi-codepoint grapheme clusters (emoji, ZWJ sequences) are handled transparently during rendering using crate::GraphemeId::placeholder for width-aware layout without pool allocation. Users needing direct grapheme pool access should use crate::GraphemePool and crate::GraphemeId from the crate root.

Key types:

  • TextBuffer: Styled text storage with syntax highlighting support
  • EditBuffer: Editable buffer with cursor movement and undo/redo
  • EditorView: Visual rendering with line numbers and selection
  • TextBufferView: Viewport configuration with wrapping modes

§Examples

§Basic Text Buffer

use opentui_rust::TextBuffer;

let buffer = TextBuffer::with_text("Hello, world!");
assert_eq!(buffer.len_chars(), 13);
assert_eq!(buffer.len_lines(), 1);

§Editable Buffer with Undo

use opentui_rust::EditBuffer;

let mut editor = EditBuffer::new();
editor.insert("Hello");
editor.commit(); // Create undo checkpoint
editor.insert(" World");
editor.commit();
assert_eq!(editor.text(), "Hello World");

// Undo the last insert
editor.undo();
assert_eq!(editor.text(), "Hello");

// Redo brings it back
editor.redo();
assert_eq!(editor.text(), "Hello World");

Structs§

EditBuffer
Text buffer with editing operations, cursor, and undo/redo.
EditorView
Editor view wrapping an EditBuffer with visual rendering.
LineInfo
Cached line layout information for wrapped text.
LocalSelection
Local (viewport) selection based on screen coordinates.
RopeWrapper
Wrapper around ropey::Rope with convenience methods.
Selection
Selection range.
StyledSegment
A segment of text with associated style.
TextBuffer
Text buffer with styled segments and highlights.
TextBufferView
View into a text buffer with viewport and rendering options.
TextMeasure
Measurement result for a given viewport size.
Viewport
Viewport configuration.
VisualCursor
Visual cursor information in wrapped view.

Enums§

WrapMode
Text wrapping mode.