5#ifndef MALENA_RICHTEXTBUFFER_H
6#define MALENA_RICHTEXTBUFFER_H
78 [[nodiscard]]
const std::string&
getText()
const;
81 [[nodiscard]] std::size_t
size()
const;
84 [[nodiscard]]
bool empty()
const;
229 unsigned int defaultSize,
253 std::vector<TextAttribute> _attributes;
255 std::size_t _cursor = 0;
256 std::size_t _selStart = 0;
257 std::size_t _selEnd = 0;
258 bool _hasSelection =
false;
262 bool _hasPending =
false;
264 void deleteRange(std::size_t start, std::size_t end);
265 void shiftAttributesAfterInsert(std::size_t pos, std::size_t count);
266 void shiftAttributesAfterDelete(std::size_t start, std::size_t count);
267 void splitAttributeAt(std::size_t pos);
268 void mergeAdjacentAttributes();
269 void normalizeAttributes();
271 std::size_t findWordBoundary(std::size_t pos,
int direction)
const;
272 std::size_t findLineStart(std::size_t pos)
const;
273 std::size_t findLineEnd(std::size_t pos)
const;
void moveCursorToLineStart(bool extendSelection=false)
Move the cursor to the start of the current line.
void setCursor(std::size_t pos)
Set the cursor position clamped to [0, size()]. Clears the selection.
void backspace()
Delete the character immediately before the cursor (backspace). If a selection is active,...
const std::vector< TextAttribute > & getAttributes() const
Return all attribute ranges.
void setText(const std::string &text)
Replace the entire buffer content. Cursor moves to end. Clears all attributes.
std::size_t size() const
Return the number of characters in the buffer.
void moveCursor(int delta, bool extendSelection=false)
Move the cursor by delta characters, clamped to buffer bounds.
void moveCursorToLineEnd(bool extendSelection=false)
Move the cursor to the end of the current line.
std::size_t getCursor() const
Return the current cursor position (char index).
void setSelection(std::size_t start, std::size_t end)
Set an explicit selection range. Cursor moves to end.
void insert(const std::string &text)
Insert text at the cursor position.
void pasteFromClipboard()
Insert the system clipboard contents at the cursor.
void insertChar(char32_t unicode)
Insert a single unicode character at the cursor position.
void clearSelection()
Clear the selection without moving the cursor.
bool empty() const
Return true if the buffer contains no characters.
void selectAll()
Select all text.
void deleteForward()
Delete the character immediately after the cursor (delete key). If a selection is active,...
std::size_t getSelectionStart() const
Return the selection start (always <= selectionEnd).
void copyToClipboard() const
Copy the current selection to the system clipboard. Has no effect if nothing is selected.
bool hasSelection() const
Return true if a selection is active.
std::string getSelectedText() const
Return the currently selected text. Empty if no selection.
void applyAttribute(TextAttribute attr)
Apply an attribute to the current selection.
void moveCursorByWord(int direction, bool extendSelection=false)
Move the cursor to the start of the previous or next word.
TextAttribute getAttributeAt(std::size_t index, const sf::Font *defaultFont, unsigned int defaultSize, sf::Color defaultColor) const
Return the effective TextAttribute at a given character index.
const std::string & getText() const
Return the full text content as a UTF-8 string.
std::size_t getSelectionEnd() const
Return the selection end (always >= selectionStart).
void cutToClipboard()
Cut the current selection to the system clipboard. Has no effect if nothing is selected.
void clear()
Delete all text in the buffer.
A styled attribute range applied to a span of characters.
std::optional< bool > bold
nullopt = inherit
std::size_t end
Last character index (exclusive).
std::optional< sf::Color > color
nullopt = inherit default color
std::size_t start
First character index (inclusive).
std::optional< unsigned int > charSize
nullopt = inherit default size
const sf::Font * font
nullptr = inherit default font
std::optional< bool > italic
nullopt = inherit
std::optional< bool > underline
nullopt = inherit