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

This commit is contained in:
Loïc Guilloux 2023-09-13 22:59:34 +02:00 committed by GitHub
parent fca62c245f
commit b4ff06b6ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 6 deletions

View File

@ -247,14 +247,21 @@ void Textbuf::DeleteText(uint16_t from, uint16_t to, bool update)
this->bytes -= to - from;
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();