Donner 0.5.1
Embeddable browser-grade SVG2 engine
Loading...
Searching...
No Matches
donner::editor::TextBuffer Class Reference

Manages a collection of lines (the raw text) plus related text operations like insert, delete, and substring extraction. More...

#include "donner/editor/TextBuffer.h"

Public Types

using Lines = std::vector<Line>

Public Member Functions

 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 LinegetLineGlyphs (int line) const
 Get the text in a given line.
LinegetLineGlyphsMutable (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).
LineinsertLine (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.

Detailed Description

Manages a collection of lines (the raw text) plus related text operations like insert, delete, and substring extraction.

Member Function Documentation

◆ deleteRange()

void donner::editor::TextBuffer::deleteRange ( const Coordinates & start,
const Coordinates & end )
inline

Remove text in [start, end).

Merges lines if needed.

Example:

Line0
Line1
Line2

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
startThe start of the range to remove (inclusive).
endThe 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
lineThe line number to get.

◆ getLineGlyphsMutable()

Line & donner::editor::TextBuffer::getLineGlyphsMutable ( int line)
inline

Get the text in a given line.

Parameters
lineThe 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
whereCoordinates where the text should be inserted.
textThe text to insert (can include newlines).
indentWhether 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
textThe new text to load into the buffer.

The documentation for this class was generated from the following file: