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
RenderLib
required
The render library instance.
Pointer
required
Pointer to the native buffer.
Static Methods
create
Creates a new TextBuffer instance.WidthMethod
required
The width calculation method for character rendering.
TextBuffer
A new TextBuffer instance.
Properties
length
number
The character length of the text in the buffer.
byteSize
number
The byte size of the text in the buffer.
ptr
Pointer
The native pointer to the buffer.
Text Operations
setText
Sets the entire text content of the buffer.string
required
The text content to set.
append
Appends text to the end of the buffer.string
required
The text to append.
loadFile
Loads text content from a file.string
required
The file path to load.
setStyledText
Sets styled text with formatting.StyledText
required
Styled text with formatting chunks.
getPlainText
Retrieves the plain text content without styling.string
The plain text content.
getTextRange
Retrieves a range of text by character offsets.number
required
The starting character offset.
number
required
The ending character offset.
string
The text in the specified range.
getLineCount
Gets the number of lines in the buffer.number
The number of lines.
Styling
setDefaultFg
Sets the default foreground color.RGBA | null
required
The foreground color or null to clear.
setDefaultBg
Sets the default background color.RGBA | null
required
The background color or null to clear.
setDefaultAttributes
Sets default text attributes (bold, italic, etc.).number | null
required
Bitfield of text attributes or null to clear.
resetDefaults
Resets all default styling to original values.Syntax Highlighting
setSyntaxStyle
Sets the syntax highlighting style.SyntaxStyle | null
required
The syntax style or null to disable.
getSyntaxStyle
Gets the current syntax highlighting style.SyntaxStyle | null
The current syntax style or null if none is set.
Highlights
addHighlight
Adds a highlight to a specific line by column positions.number
required
The line index (0-based).
Highlight
required
The highlight definition with start/end columns.
addHighlightByCharRange
Adds a highlight using absolute character offsets.Highlight
required
The highlight definition with start/end character offsets.
removeHighlightsByRef
Removes all highlights with a specific reference ID.number
required
The highlight reference ID.
clearLineHighlights
Clears all highlights on a specific line.number
required
The line index (0-based).
clearAllHighlights
Removes all highlights from the buffer.getLineHighlights
Retrieves all highlights for a specific line.number
required
The line index (0-based).
Array<Highlight>
Array of highlights on the line.
getHighlightCount
Gets the total number of highlights in the buffer.number
The total highlight count.
Configuration
setTabWidth
Sets the display width of tab characters.number
required
The tab width in columns.
getTabWidth
Gets the current tab width setting.number
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
string
required
The text content of the chunk.
RGBA
Foreground color for the chunk.
RGBA
Background color for the chunk.
number
Text attributes bitfield (bold, italic, etc.).
{ url: string }
Optional hyperlink URL.