public sealed class CodeBufferThe text a CodeEditor is editing: lines, and the four edits.
No guide page documents this yet — the page shows what the code says about itself.
Remarks
A list of lines, not a rope and not a gap buffer. The operations an editor actually performs are "give me line 4 200 to draw it" and "insert a character on the line the caret is on", and a list of strings answers the first in constant time and the second by rebuilding one line. A rope wins on inserting into the middle of a ten-megabyte file, which is not what a shader source or a component script is.
⚠ No undo stack. Undo belongs to the application, because it has to be interleaved with everything else the editor does — a rename that touched three files, a refactor, a move — and an undo stack inside the text control can only ever undo typing. What is here is Changed, which is what such a stack subscribes to. Owed and said out loud rather than half-built.
Fields and properties (5)
public IReadOnlyList<string> LinesThe lines, without their terminators.
public int LineCountHow many there are. Never zero — an empty buffer is one empty line.
public string this[int line]One line.
public string TextThe whole thing, joined with newlines.
public TextPosition EndThe end of the buffer.
Events (1)
public Action<CodeBuffer>? ChangedRaised after any edit.
Methods (13)
public CodeBuffer()Creates an empty buffer.
public CodeBuffer(string text)Creates a buffer holding some text.
public TextPosition Clamp(TextPosition position)Brings a position inside the text.
public string Slice(TextPosition from, TextPosition to)The text between two places.
public TextPosition Insert(TextPosition at, string text)Puts text in.
public TextPosition Delete(TextPosition from, TextPosition to)Takes text out.
public TextPosition Back(TextPosition position)The place one character before a position, stepping onto the previous line.
public TextPosition Forward(TextPosition position)The place one character after a position.
public TextPosition WordStart(TextPosition position)The start of the word a position is in or just after.
public TextPosition WordEnd(TextPosition position)The end of the word a position is in or just before.
public int IndentOf(int line)How many characters of whitespace a line starts with.
public bool IsBlank(int line)Whether a line has nothing but whitespace on it.
public string WordBefore(TextPosition position)The word ending at a position, which is what a completion filters on.
Used by (6)
- CodeBufferTestsVixen.Ui.Controls.Advanced.Tests
- CodeEditorVixen.Ui.Controls.Advanced
- CodeEditorTestsVixen.Ui.Controls.Advanced.Tests
- ResizeTestsVixen.Ui.Controls.Advanced.Tests
- CodeDocumentVixen.Editor.AssetEditors
- CodeDocumentTestsVixen.Editor.AssetEditors.Tests