Fix BeforeEdit cursor removal, add multicursor deletion

This commit is contained in:
Krzosa Karol
2024-06-29 10:27:16 +02:00
parent e3150f8203
commit 7e68e09b22
3 changed files with 90 additions and 22 deletions

View File

@@ -183,16 +183,47 @@ for (int i = 0; i < array.len; i += 1) {
}
}
// Simple delete
IterRemove(arr) {
IterRemovePrepare(arr);
remove_item = true;
}
//
// Deleting backwards
//
For(arr.reverse_iter()) {
defer{ arr.unordered_remove(it); };
}
//
// When double looping and deleting
//
Array<Cursor *> deleted_cursors = {scratch};
ForItem(cursor, window->cursors) {
For(deleted_cursors) if (it == &cursor) goto end_of_cursor_loop;
For(window->cursors) {
if (&it == &cursor) break;
bool a = cursor.range.max >= it.range.min && cursor.range.max <= it.range.max;
bool b = cursor.range.min >= it.range.min && cursor.range.min <= it.range.max;
if (a || b) {
deleted_cursors.add(&it);
cursor.range.max = Max(cursor.range.max, it.range.max);
cursor.range.min = Min(cursor.range.min, it.range.min);
break;
}
}
end_of_cursor_loop:;
}
For(deleted_cursors) window->cursors.ordered_remove(*it);
*/
#define IterRemove(a) for (int i = 0; i < (a).len; i += 1)
#define IterRemovePrepare(a) \