GGUI::TextEditState class

A caret and selection over a TextBuffer, and the edits made at them. See the file description.

Public static functions

static auto NextCharacter(const TextBuffer& buffer, TextPos position) -> TextPos
The end of the grapheme at position.
static auto PrevCharacter(const TextBuffer& buffer, TextPos position) -> TextPos
The start of the grapheme before position.

Constructors, destructors, conversion operators

TextEditState() defaulted
Attached to nothing.
TextEditState(TextBuffer& buffer) explicit
Attached to buffer, with the caret at its end.
~TextEditState()
Detaches, releasing its anchors in the buffer.
TextEditState(const TextEditState&) deleted

Public functions

auto operator=(const TextEditState&) -> TextEditState& deleted
void Attach(TextBuffer* buffer)
Edit buffer; null detaches. The caret starts at the end of the buffer.
auto Buffer() const -> TextBuffer*
The buffer it edits; null if detached.
void SetRules(const TextEditRules& rules)
What edits it allows from now on.
auto GetRules() const -> const TextEditRules&
What edits it allows.
auto Caret() const -> TextPos
Where the caret is.
auto SelectionAnchor() const -> TextPos
Where the selection started. Equals Caret() when nothing is selected.
auto SelectionStart() const -> TextPos
The selection's start: the earlier of the caret and the anchor.
auto SelectionEnd() const -> TextPos
The selection's end: the later of the caret and the anchor.
auto HasSelection() const -> bool
Whether anything is selected.
auto SelectedText() const -> std::string
The selected text; empty if nothing is selected.
void SetCaret(TextPos position, bool bExtend = false)
Put the caret at position, snapped to a grapheme boundary. bExtend keeps the selection anchor where it is.
void Move(TextMove move, bool bExtend = false)
Move the caret; bExtend keeps the selection anchor where it is.
void SelectAll()
Select all the text.
void SelectWordAt(TextPos position)
Select the word, or the run of spaces or punctuation, at position.
void SelectLineAt(TextPos position)
Select the buffer line at position.
auto Type(std::string_view text) -> bool
Replace the selection with text. Consecutive typing merges into one undo step.
auto Paste(std::string_view text) -> bool
Insert text as a single undo step (paste, drop).
auto Backspace(bool bWord = false) -> bool
Remove the selection, or the grapheme (with bWord, the word) before the caret.
auto Delete(bool bWord = false) -> bool
Remove the selection, or the grapheme (with bWord, the word) after the caret.
auto Cut(std::string& out) -> bool
Remove the selection into out. False, with out empty, if nothing is selected.
auto Undo() -> bool
Undo the buffer's last edit, wherever it was made.
auto Redo() -> bool
Redo the edit last undone.
void SetComposition(std::string_view text, int32_t cursor)
Show the IME's composition text at the caret, with its cursor cursor characters in. Empty text ends the composition without committing.
void CommitComposition(std::string_view text)
End the composition and insert text (empty: nothing).
void CancelComposition()
End the composition, inserting nothing.
auto IsComposing() const -> bool
Whether a composition is shown.
auto CompositionStart() const -> TextPos
Where the composition starts in the buffer; 0 if none.
auto CompositionEnd() const -> TextPos
Where the composition ends in the buffer; 0 if none.
auto Changed() const -> const GGRevision&
Bumped when the caret, selection, or composition changes. Text changes are the buffer's Revision.