using System.Collections.Concurrent;
///
/// Editor actions delivered from the SDL main loop. All non-printable input is
/// expressed as one of these; printable characters arrive via OnChar.
///
public enum EditorAction
{
Left, Right, Up, Down,
Home, End, PageUp, PageDown,
Backspace, Delete, Enter,
Save, Undo, CutLine, PasteLine, Quit
}
internal enum EditorOpType
{
InsertChar, DeleteChar,
InsertLine, DeleteLine,
SplitLine, JoinLine,
ReplaceLine
}
internal readonly record struct EditorOp(EditorOpType Type, int Row, int Col, char Ch, string? Line);
///
/// Full-screen text editor for Micronona. Runs on its own thread, blocks on an
/// event queue fed by the SDL main loop. Renders directly into the text-mode
/// framebuffer via ConsoleHelper; the hardware cursor is positioned through
/// REG_CURSOR_COL/ROW so the existing inverting render handles cursor display.
///
/// Layout (40×18):
/// row 0 title bar (filename + [modified])
/// rows 1..16 content (16 visible rows, horizontal scrolling)
/// row 17 shortcut bar / quit-confirm prompt
///
public sealed class TextEditor
{
private const int TitleRow = 0;
private const int ContentTop = 1;
private const int ShortcutRow = MemoryModel.TextRows - 1; // 17
private const int ContentRows = ShortcutRow - ContentTop; // 16
private const int Cols = MemoryModel.TextCols; // 40
private const byte ContentFg = ConsoleHelper.DefaultFg;
private const byte ContentBg = ConsoleHelper.DefaultBg;
private const byte BarFg = ConsoleHelper.DefaultBg; // inverted bars
private const byte BarBg = ConsoleHelper.DefaultFg;
private readonly ConsoleHelper _con;
private readonly List _lines = new();
private readonly Stack _undo = new();
private readonly BlockingCollection