* Insert a character to a textbuffer. If maxwidth of the Textbuf is zero, * we don't care about the visual-length but only about the physical * length of the string * @param key Character to be inserted * @return Return true on successful change of Textbuf, or false otherwise */
| 126 | * @return Return true on successful change of Textbuf, or false otherwise |
| 127 | */ |
| 128 | bool Textbuf::InsertChar(char32_t key) |
| 129 | { |
| 130 | auto [src, len] = EncodeUtf8(key); |
| 131 | if (this->buf.size() + len < this->max_bytes && this->chars + 1 <= this->max_chars) { |
| 132 | /* Make space in the string, then overwrite it with the Utf8 encoded character. */ |
| 133 | this->buf.insert(this->caretpos, src, len); |
| 134 | this->chars++; |
| 135 | this->caretpos += len; |
| 136 | |
| 137 | this->UpdateStringIter(); |
| 138 | this->UpdateWidth(); |
| 139 | this->UpdateCaretPosition(); |
| 140 | this->UpdateMarkedText(); |
| 141 | return true; |
| 142 | } |
| 143 | return false; |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Insert a string into the text buffer. If maxwidth of the Textbuf is zero, |
no test coverage detected