Manages a collection of lines (the raw text) plus related text operations like insert, delete, and substring extraction.
More...
#include "donner/editor/TextBuffer.h"
|
|
using | Lines = std::vector<Line> |
|
|
| TextBuffer () |
| | Create an empty text buffer.
|
| void | setText (std::string_view text) |
| | Replace the entire buffer with new text.
|
|
std::string | getText () const |
| | Get the entire text buffer as a single string, joined by newlines.
|
|
std::string | getText (const Coordinates &start, const Coordinates &end) const |
| | Get the text in [start, end), inclusive of start and exclusive of end, or adapt as needed for your coordinate conventions.
|
| const Line & | getLineGlyphs (int line) const |
| | Get the text in a given line.
|
| Line & | getLineGlyphsMutable (int line) |
| | Get the text in a given line.
|
| int | insertTextAt (Coordinates &where, std::string_view text, bool indent=false) |
| | Insert text at a given position.
|
| void | deleteRange (const Coordinates &start, const Coordinates &end) |
| | Remove text in [start, end).
|
| Line & | insertLine (int index, int column=0) |
| | Insert an empty line at index, or optionally split at a column in an existing line.
|
|
void | removeLine (int index) |
| | Remove a single line at the given index if valid.
|
|
void | removeLine (int start, int end) |
| | Remove lines in the range [start, end).
|
| int | getLineMaxColumn (int line) const |
| | Query the max column index of a given line (i.e.
|
|
int | getLineCharacterCount (int line) const |
| | Query how many characters (glyphs) are on a given line.
|
|
int | getCharacterIndex (const Coordinates &coords) const |
| | Convert (line, column) to the internal character index within its line.
|
| int | getCharacterColumn (int line, int index) const |
| | Given a line and character index within that line, return the 'visual' column.
|
|
int | getTotalLines () const |
| | The total number of lines in the buffer.
|
Manages a collection of lines (the raw text) plus related text operations like insert, delete, and substring extraction.
◆ deleteRange()
Remove text in [start, end).
Merges lines if needed.
Example:
If you remove 'Line0' entirely, you'd pass start.column=0 and end.column=5. If you want to remove multi-line, for example removing 0Lin, pass start (0,4) and end (1,3).
- Parameters
-
| start | The start of the range to remove (inclusive). |
| end | The end of the range to remove (exclusive). |
◆ getCharacterColumn()
| int donner::editor::TextBuffer::getCharacterColumn |
( |
int | line, |
|
|
int | index ) const |
|
inline |
Given a line and character index within that line, return the 'visual' column.
If your editor expands tabs, you could calculate offset. Placeholder here.
◆ getLineGlyphs()
| const Line & donner::editor::TextBuffer::getLineGlyphs |
( |
int | line | ) |
const |
|
inline |
Get the text in a given line.
- Parameters
-
| line | The line number to get. |
◆ getLineGlyphsMutable()
| Line & donner::editor::TextBuffer::getLineGlyphsMutable |
( |
int | line | ) |
|
|
inline |
Get the text in a given line.
- Parameters
-
| line | The line number to get. |
◆ getLineMaxColumn()
| int donner::editor::TextBuffer::getLineMaxColumn |
( |
int | line | ) |
const |
|
inline |
Query the max column index of a given line (i.e.
length of that line).
◆ insertLine()
| Line & donner::editor::TextBuffer::insertLine |
( |
int | index, |
|
|
int | column = 0 ) |
|
inline |
Insert an empty line at index, or optionally split at a column in an existing line.
Returns a reference to the newly inserted line.
◆ insertTextAt()
| int donner::editor::TextBuffer::insertTextAt |
( |
Coordinates & | where, |
|
|
std::string_view | text, |
|
|
bool | indent = false ) |
|
inline |
Insert text at a given position.
Splits lines, handles newlines, etc.
- Parameters
-
| where | Coordinates where the text should be inserted. |
| text | The text to insert (can include newlines). |
| indent | Whether to apply special indentation logic if desired. |
- Returns
- The number of lines inserted (not counting the original partial line).
◆ setText()
| void donner::editor::TextBuffer::setText |
( |
std::string_view | text | ) |
|
|
inline |
Replace the entire buffer with new text.
- Parameters
-
| text | The new text to load into the buffer. |
The documentation for this class was generated from the following file: