Fix: marked text was not updated during text deletion (#11293)

(cherry picked from commit b4ff06b6ef)
This commit is contained in:
Loïc Guilloux 2023-09-13 22:59:34 +02:00 committed by Jonathan G Rennison
parent 4c4fe8cf64
commit cb5a132b0c

View File

@ -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();