More proper offseting of cursors during char insert

This commit is contained in:
Krzosa Karol
2024-06-23 07:53:30 +02:00
parent e54596809e
commit c0d69521fe

View File

@@ -209,11 +209,16 @@ int main() {
AddEdit(&edits, it, string);
}
ApplyEdits(&focused_window->buffer, edits);
For(focused_window->cursors) {
// Need to update current cursor and all cursors after it.
ForItem(edit, edits) {
int64_t remove_size = GetRangeSize(edit.range);
int64_t add_size = string.len;
int64_t offset = add_size - remove_size;
ForItem(cursor, focused_window->cursors) {
if (cursor.min >= it.min) {
cursor.min = cursor.max = MoveRight(focused_window->buffer, cursor.min);
if (edit.range.min <= cursor.min) {
cursor.min += offset;
cursor.max = cursor.min;
}
}
}