Skip to content

Editor

The Editor widget provides a multi-line text editor with cursor navigation, line numbers, text selection, and full undo/redo support.

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.

The full text content. Setting this replaces all lines and moves the cursor to the end.

editor.Text = "Line 1\nLine 2\nLine 3";

The individual lines of text, read-only.

int lineCount = editor.Lines.Count;

The current cursor line (0-based).

editor.CursorLine = 0;

The current cursor column (0-based).

editor.CursorColumn = 0;

Whether to display line numbers in the gutter.

editor.ShowLineNumbers = true;

Whether to enable word wrapping.

editor.WordWrap = false;

The color used for the line-number gutter.

editor.LineNumberColor = ColorHelper.FromRgb(100, 100, 100);

The start position of the current text selection, or null if no selection is active.

The end position of the current text selection, or null if no selection is active.

Inserts text at the current cursor position. Multi-line strings (containing \n) are handled.

editor.InsertText("Hello");

Deletes the character at the cursor, or the selection if one is active.

Deletes the character before the cursor, or the selection if one is active.

Deletes the current selection.

Moves the cursor to the specified position.

editor.MoveCursor(0, 0);

Selects the entire text content.

Returns the text of a specific line.

Replaces the text of a specific line.

Undoes the last edit. Up to 50 operations are retained.

Redoes the last undone edit.

Raised whenever the text content changes.

editor.TextChanged += (newText) =>
{
Console.WriteLine($"Text now has {newText.Length} characters.");
};

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}";
};

Raised when a specific line is modified. The handler receives the line index.

editor.LineChanged += (lineIndex) =>
{
// Line lineIndex was edited
};
  • 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
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}";
};
  • 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