Editor
The Editor widget provides a multi-line text editor with cursor navigation, line numbers, text selection, and full undo/redo support.
Overview
Section titled “Overview”Editor is the base editing widget for multi-line text in Elaris.UI. It handles the core editing primitives (insert, delete, select, move) and the rendering of text with optional line numbers. For syntax-highlighted code editing, use CodeEditor, which derives from Editor.
Properties
Section titled “Properties”Text (string)
Section titled “Text (string)”The full text content. Setting this replaces all lines and moves the cursor to the end.
editor.Text = "Line 1\nLine 2\nLine 3";Lines (IReadOnlyList<string>)
Section titled “Lines (IReadOnlyList<string>)”The individual lines of text, read-only.
int lineCount = editor.Lines.Count;CursorLine (int)
Section titled “CursorLine (int)”The current cursor line (0-based).
editor.CursorLine = 0;CursorColumn (int)
Section titled “CursorColumn (int)”The current cursor column (0-based).
editor.CursorColumn = 0;ShowLineNumbers (bool)
Section titled “ShowLineNumbers (bool)”Whether to display line numbers in the gutter.
editor.ShowLineNumbers = true;WordWrap (bool)
Section titled “WordWrap (bool)”Whether to enable word wrapping.
editor.WordWrap = false;LineNumberColor (Color)
Section titled “LineNumberColor (Color)”The color used for the line-number gutter.
editor.LineNumberColor = ColorHelper.FromRgb(100, 100, 100);SelectionStart (Point?)
Section titled “SelectionStart (Point?)”The start position of the current text selection, or null if no selection is active.
SelectionEnd (Point?)
Section titled “SelectionEnd (Point?)”The end position of the current text selection, or null if no selection is active.
Methods
Section titled “Methods”InsertText(string text)
Section titled “InsertText(string text)”Inserts text at the current cursor position. Multi-line strings (containing \n) are handled.
editor.InsertText("Hello");DeleteChar()
Section titled “DeleteChar()”Deletes the character at the cursor, or the selection if one is active.
DeleteBackspace()
Section titled “DeleteBackspace()”Deletes the character before the cursor, or the selection if one is active.
DeleteSelection()
Section titled “DeleteSelection()”Deletes the current selection.
MoveCursor(int line, int column)
Section titled “MoveCursor(int line, int column)”Moves the cursor to the specified position.
editor.MoveCursor(0, 0);SelectAll()
Section titled “SelectAll()”Selects the entire text content.
GetLine(int lineIndex)
Section titled “GetLine(int lineIndex)”Returns the text of a specific line.
SetLine(int lineIndex, string text)
Section titled “SetLine(int lineIndex, string text)”Replaces the text of a specific line.
Undo()
Section titled “Undo()”Undoes the last edit. Up to 50 operations are retained.
Redo()
Section titled “Redo()”Redoes the last undone edit.
Events
Section titled “Events”TextChanged
Section titled “TextChanged”Raised whenever the text content changes.
editor.TextChanged += (newText) =>{ Console.WriteLine($"Text now has {newText.Length} characters.");};CursorMoved
Section titled “CursorMoved”Raised when the cursor position changes. The handler receives the new line and column.
editor.CursorMoved += (line, column) =>{ statusBar.RightText = $"Line {line + 1}, Col {column + 1}";};LineChanged
Section titled “LineChanged”Raised when a specific line is modified. The handler receives the line index.
editor.LineChanged += (lineIndex) =>{ // Line lineIndex was edited};Keyboard Navigation
Section titled “Keyboard Navigation”- Left/Right Arrow: Move cursor by one character (wraps between lines)
- Up/Down Arrow: Move cursor between lines
- Home/End: Move to start or end of the current line
- Ctrl+Home/Ctrl+End: Move to start or end of the document
- Page Up/Page Down: Scroll one page
- Enter: Insert newline
- Backspace/Delete: Delete character before/after cursor
- Tab: Insert four spaces
- Ctrl+Z: Undo
- Ctrl+Y: Redo
- Ctrl+A: Select all
Usage Example
Section titled “Usage Example”var editor = new Editor{ X = 2, Y = 2, Width = 60, Height = 20, ShowLineNumbers = true, ForegroundColor = Color.White, BackgroundColor = Color.Black, LineNumberColor = ColorHelper.FromRgb(100, 100, 100), Text = "Welcome to Elaris.UI!\n\nStart typing to edit..."};
editor.CursorMoved += (line, col) =>{ statusBar.RightText = $"Line {line + 1}, Col {col + 1}";};Related Widgets
Section titled “Related Widgets”- CodeEditor — Editor with syntax highlighting, bracket matching, and auto-indent
- TextField — Single-line text input
- TextView — Read-only multi-line text display
- Base Widget — Base class documentation