Hopefully fixed BeforeEdit, needs a refactor though

This commit is contained in:
Krzosa Karol
2024-06-29 10:49:07 +02:00
parent 7e68e09b22
commit c8ad9222fd
3 changed files with 50 additions and 31 deletions

View File

@@ -199,29 +199,6 @@ 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);
*/
@@ -258,6 +235,21 @@ struct Slice {
// @copy_paste array slice
bool contains(T item) {
for (int64_t i = 0; i < len; i += 1) {
if (data[i] == item) return true;
}
return false;
}
T get_or_default(int64_t i, T default_value = {}) {
T result = default_value;
if (i >= 0 && i < len) {
result = data[i];
}
return result;
}
T pop() {
Assert(len > 0);
return data[--len];
@@ -531,6 +523,13 @@ struct Array {
// @copy_paste array slice
bool contains(T item) {
for (int64_t i = 0; i < len; i += 1) {
if (data[i] == item) return true;
}
return false;
}
T get_or_default(int64_t i, T default_value = {}) {
T result = default_value;
if (i >= 0 && i < len) {