MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / DeleteText

Method DeleteText

src/textbuf.cpp:237–266  ·  view source on GitHub ↗

* Delete a part of the text. * @param from Start of the text to delete. * @param to End of the text to delete. * @param update Set to true if the internal state should be updated. */

Source from the content-addressed store, hash-verified

235 * @param update Set to true if the internal state should be updated.
236 */
237void Textbuf::DeleteText(uint16_t from, uint16_t to, bool update)
238{
239 assert(from <= to);
240
241 /* Strip marked characters from buffer. */
242 this->chars -= static_cast<uint16_t>(Utf8StringLength(std::string_view(this->buf).substr(from, to - from)));
243 this->buf.erase(from, to - from);
244
245 auto fixup = [&](uint16_t &pos) {
246 if (pos <= from) return;
247 if (pos <= to) {
248 pos = from;
249 } else {
250 pos -= to - from;
251 }
252 };
253
254 /* Fixup caret if needed. */
255 fixup(this->caretpos);
256
257 /* Fixup marked text if needed. */
258 fixup(this->markpos);
259 fixup(this->markend);
260
261 if (update) {
262 this->UpdateStringIter();
263 this->UpdateCaretPosition();
264 this->UpdateMarkedText();
265 }
266}
267
268/**
269 * Discard any marked text.

Callers 2

InsertStringMethod · 0.95
DiscardMarkedTextMethod · 0.95

Calls 6

UpdateStringIterMethod · 0.95
UpdateCaretPositionMethod · 0.95
UpdateMarkedTextMethod · 0.95
Utf8StringLengthFunction · 0.85
substrMethod · 0.80
eraseMethod · 0.45

Tested by

no test coverage detected