Overview
TheTextBuffer class provides efficient text storage with support for styled text, syntax highlighting, and grapheme-aware operations. It handles text rendering with Unicode support and manages highlights for code or text display.
Constructor
The render library instance.
Pointer to the native buffer.
Static Methods
create
Creates a new TextBuffer instance.The width calculation method for character rendering.
A new TextBuffer instance.
Properties
length
The character length of the text in the buffer.
byteSize
The byte size of the text in the buffer.
ptr
The native pointer to the buffer.
Text Operations
setText
Sets the entire text content of the buffer.The text content to set.
append
Appends text to the end of the buffer.The text to append.
loadFile
Loads text content from a file.The file path to load.
setStyledText
Sets styled text with formatting.Styled text with formatting chunks.
getPlainText
Retrieves the plain text content without styling.The plain text content.
getTextRange
Retrieves a range of text by character offsets.The starting character offset.
The ending character offset.
The text in the specified range.
getLineCount
Gets the number of lines in the buffer.The number of lines.
Styling
setDefaultFg
Sets the default foreground color.The foreground color or null to clear.
setDefaultBg
Sets the default background color.The background color or null to clear.
setDefaultAttributes
Sets default text attributes (bold, italic, etc.).Bitfield of text attributes or null to clear.
resetDefaults
Resets all default styling to original values.Syntax Highlighting
setSyntaxStyle
Sets the syntax highlighting style.The syntax style or null to disable.
getSyntaxStyle
Gets the current syntax highlighting style.The current syntax style or null if none is set.
Highlights
addHighlight
Adds a highlight to a specific line by column positions.The line index (0-based).
The highlight definition with start/end columns.
addHighlightByCharRange
Adds a highlight using absolute character offsets.The highlight definition with start/end character offsets.
removeHighlightsByRef
Removes all highlights with a specific reference ID.The highlight reference ID.
clearLineHighlights
Clears all highlights on a specific line.The line index (0-based).
clearAllHighlights
Removes all highlights from the buffer.getLineHighlights
Retrieves all highlights for a specific line.The line index (0-based).
Array of highlights on the line.
getHighlightCount
Gets the total number of highlights in the buffer.The total highlight count.
Configuration
setTabWidth
Sets the display width of tab characters.The tab width in columns.
getTabWidth
Gets the current tab width setting.The tab width in columns.
Memory Management
clear
Clears the buffer content but preserves internal state.reset
Resets the buffer to initial state, clearing all content and state.destroy
Destroys the buffer and frees native resources.Types
TextChunk
The text content of the chunk.
Foreground color for the chunk.
Background color for the chunk.
Text attributes bitfield (bold, italic, etc.).
Optional hyperlink URL.