Overview
TheEditBuffer class extends EventEmitter and provides a complete text editing solution with cursor management, undo/redo history, and grapheme-aware text operations. It’s designed for building text editors and interactive text input components.
Constructor
The render library instance.
Pointer to the native buffer.
Static Methods
create
Creates a new EditBuffer instance.The width calculation method for character rendering.
A new EditBuffer instance.
Properties
id
Unique identifier for this buffer instance.
ptr
The native pointer to the buffer.
Text Operations
setText
Sets text and completely resets the buffer state (clears history).The text content to set.
setTextOwned
Sets text using owned memory and resets buffer state. Native code takes ownership.The text content to set.
replaceText
Replaces text while preserving undo history (creates an undo point).The replacement text content.
replaceTextOwned
Replaces text using owned memory while preserving undo history.The replacement text content.
getText
Retrieves the current text content.The current 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.
getTextRangeByCoords
Retrieves a range of text by line/column coordinates.The starting row (0-based).
The starting column (0-based).
The ending row (0-based).
The ending column (0-based).
The text in the specified range.
getLineCount
Gets the number of lines in the buffer.The number of lines.
Editing Operations
insertChar
Inserts a character at the current cursor position.The character to insert.
insertText
Inserts text at the current cursor position.The text to insert.
deleteChar
Deletes the character at the cursor position (forward delete).deleteCharBackward
Deletes the character before the cursor position (backspace).deleteRange
Deletes a range of text by coordinates.The starting line (0-based).
The starting column (0-based).
The ending line (0-based).
The ending column (0-based).
newLine
Inserts a new line at the cursor position.deleteLine
Deletes the current line.Cursor Operations
getCursorPosition
Gets the current cursor position.Object containing row, col, and offset properties.
setCursor
Sets the cursor to a specific line and column.The line number (0-based).
The column number (0-based).
setCursorToLineCol
Sets the cursor to a specific line and column.The line number (0-based).
The column number (0-based).
setCursorByOffset
Sets the cursor by character offset.The character offset (0-based).
moveCursorLeft
Moves the cursor one grapheme left.moveCursorRight
Moves the cursor one grapheme right.moveCursorUp
Moves the cursor one line up.moveCursorDown
Moves the cursor one line down.gotoLine
Moves the cursor to the start of a specific line.The line number (0-based).
getNextWordBoundary
Finds the next word boundary from the cursor.The position of the next word boundary.
getPrevWordBoundary
Finds the previous word boundary from the cursor.The position of the previous word boundary.
getEOL
Gets the end-of-line position for the current line.The end-of-line position.
Position Conversion
offsetToPosition
Converts a character offset to a line/column position.The character offset.
The row/column position or null if invalid offset.
positionToOffset
Converts a line/column position to a character offset.The row number (0-based).
The column number (0-based).
The character offset.
getLineStartOffset
Gets the character offset of the start of a line.The row number (0-based).
The character offset of the line start.
Undo/Redo
undo
Undoes the last edit operation.Metadata about the undo operation or null if nothing to undo.
redo
Redoes the last undone operation.Metadata about the redo operation or null if nothing to redo.
canUndo
Checks if there are operations available to undo.True if undo is available.
canRedo
Checks if there are operations available to redo.True if redo is available.
clearHistory
Clears the entire undo/redo history.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.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.
Memory Management
clear
Clears the buffer content.destroy
Destroys the buffer and frees native resources.debugLogRope
Logs the internal rope data structure for debugging.Types
LogicalCursor
The row position (0-based).
The column position (0-based).
The character offset from start of buffer.
Events
EditBuffer extends EventEmitter and emits native events. Events are prefixed witheb_ internally but exposed without the prefix.