From cb5a132b0cd8155a396e8ce99d91ff5101cd5747 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Guilloux?= Date: Wed, 13 Sep 2023 22:59:34 +0200 Subject: [PATCH] Fix: marked text was not updated during text deletion (#11293) (cherry picked from commit b4ff06b6ef54e98ac2430bef29c895fb3f99fc10) --- src/textbuf.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/textbuf.cpp b/src/textbuf.cpp index a8d02920df..23fb0f4ed2 100644 --- a/src/textbuf.cpp +++ b/src/textbuf.cpp @@ -250,14 +250,21 @@ void Textbuf::DeleteText(uint16 from, uint16 to, bool update) if (this->markend >= this->bytes) this->markpos = this->markend = 0; this->chars -= c; - /* Fixup caret if needed. */ - if (this->caretpos > from) { - if (this->caretpos <= to) { - this->caretpos = from; + auto fixup = [&](uint16_t &pos) { + if (pos <= from) return; + if (pos <= to) { + pos = from; } else { - this->caretpos -= to - from; + pos -= to - from; } - } + }; + + /* Fixup caret if needed. */ + fixup(this->caretpos); + + /* Fixup marked text if needed. */ + fixup(this->markpos); + fixup(this->markend); if (update) { this->UpdateStringIter();