fix out of bounds on text delete

rust-rewrite
Patrick Cleavelin 2024-02-10 16:07:26 -06:00
parent f602c3a493
commit f2a0c006f3
2 changed files with 12 additions and 3 deletions

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
bin/
**/target
**/*.xcodeproj
**/*.DS_Store

View File

@ -902,14 +902,21 @@ delete_content :: proc(buffer: ^FileBuffer, amount: int) {
if len(content_slice_ptr^) == 1 {
// move cursor to previous content_slice so we can delete the current one
iterate_file_buffer_reverse(&it);
runtime.ordered_remove(&buffer.content_slices, it.cursor.index.slice_index+1);
} else {
if it.hit_end {
runtime.ordered_remove(&buffer.content_slices, it.cursor.index.slice_index);
} else {
runtime.ordered_remove(&buffer.content_slices, it.cursor.index.slice_index+1);
}
} else if !it.hit_end {
iterate_file_buffer_reverse(&it);
content_slice_ptr^ = content_slice_ptr^[:len(content_slice_ptr^)-1];
}
}
iterate_file_buffer(&it);
if !it.hit_end {
iterate_file_buffer(&it);
}
buffer.cursor = it.cursor;
}
}