9 #include "fcitx-utils/macros.h" 18 unsigned int anchor_ = 0, cursor_ = 0;
20 size_t utf8Length_ = 0;
25 SurroundingText::SurroundingText()
26 : d_ptr(std::make_unique<SurroundingTextPrivate>()) {}
40 d->text_ = std::string();
44 const std::string &SurroundingText::text()
const {
59 std::string SurroundingText::selectedText()
const {
61 auto start = std::min(anchor(), cursor());
62 auto end = std::max(anchor(), cursor());
63 auto len = end - start;
70 return std::string(startIter, endIter);
74 unsigned int anchor) {
91 if (d->utf8Length_ < cursor || d->utf8Length_ < anchor) {
112 int cursor_pos = d->cursor_ + offset;
114 if (cursor_pos >= 0 && len >= size + cursor_pos) {
117 d->text_.erase(start, end);
118 d->cursor_ = cursor_pos;
128 d->anchor_ = d->cursor_;
133 log <<
"SurroundingText(text=";
134 log << surroundingText.text();
135 log <<
",anchor=" << surroundingText.
anchor();
136 log <<
",cursor=" << surroundingText.
cursor();
void setText(const std::string &text, unsigned int cursor, unsigned int anchor)
Set current of surrounding text.
unsigned int anchor() const
offset of anchor in character.
size_t length(Iter start, Iter end)
Return the number UTF-8 characters in the string iterator range.
C++ Utility functions for handling utf8 strings.
unsigned int cursor() const
offset of anchor in character.
Local cache for surrounding text.
Iter nextNChar(Iter iter, size_t n)
Move iter over next n character.
void setCursor(unsigned int cursor, unsigned int anchor)
Set current cursor and anchor of surrounding text.
Class represents the current state of surrounding text of an input context.
size_t lengthValidated(Iter start, Iter end)
Validate and return the number UTF-8 characters in the string iterator range.
constexpr size_t INVALID_LENGTH
Possible return value of lengthValidated if the string is not valid.
void invalidate()
Reset surrounding text to invalid state.
void deleteText(int offset, unsigned int size)
Delete surrounding text with offset and size.