fix crash on text deletion
parent
722f05be61
commit
d170e7d63c
|
@ -1081,7 +1081,9 @@ delete_content_from_buffer_cursor :: proc(buffer: ^FileBuffer, amount: int) {
|
||||||
iterate_file_buffer_reverse(&it);
|
iterate_file_buffer_reverse(&it);
|
||||||
|
|
||||||
if it.hit_end {
|
if it.hit_end {
|
||||||
runtime.ordered_remove(&buffer.content_slices, it.cursor.index.slice_index);
|
if len(buffer.content_slices) > 1 {
|
||||||
|
runtime.ordered_remove(&buffer.content_slices, it.cursor.index.slice_index);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
runtime.ordered_remove(&buffer.content_slices, it.cursor.index.slice_index+1);
|
runtime.ordered_remove(&buffer.content_slices, it.cursor.index.slice_index+1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,12 @@
|
||||||
use std::{
|
use std::{
|
||||||
error::Error,
|
error::Error,
|
||||||
ffi::{CStr, CString, OsString},
|
ffi::CStr,
|
||||||
path::Path,
|
|
||||||
str::FromStr,
|
|
||||||
sync::mpsc::{Receiver, Sender},
|
|
||||||
thread,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use grep::{
|
use grep::{
|
||||||
regex::RegexMatcherBuilder,
|
regex::RegexMatcherBuilder,
|
||||||
searcher::{BinaryDetection, SearcherBuilder, Sink, SinkError},
|
searcher::{BinaryDetection, SearcherBuilder, Sink, SinkError},
|
||||||
};
|
};
|
||||||
use std::sync::mpsc::channel;
|
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
|
@ -246,6 +246,39 @@ insert_before_slice :: proc(t: ^testing.T) {
|
||||||
testing.expectf(t, contents == expected_text, "got '%v', expected '%v'", contents, expected_text)
|
testing.expectf(t, contents == expected_text, "got '%v', expected '%v'", contents, expected_text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
delete_last_content_slice_beginning_of_file :: proc(t: ^testing.T) {
|
||||||
|
e := new_test_editor()
|
||||||
|
setup_empty_buffer(&e)
|
||||||
|
|
||||||
|
buffer := &e.buffers[0]
|
||||||
|
|
||||||
|
run_text_insertion(&e, "Hello, world!")
|
||||||
|
|
||||||
|
// Delete just the text
|
||||||
|
run_input_multiple(&e, press_key(.I), 1)
|
||||||
|
run_input_multiple(&e, press_key(.BACKSPACE), 13)
|
||||||
|
|
||||||
|
expect_line_col(t, buffer.cursor, 0, 0)
|
||||||
|
expect_cursor_index(t, buffer.cursor, 0, 0)
|
||||||
|
|
||||||
|
// Try to delete when there is no text
|
||||||
|
run_input_multiple(&e, press_key(.BACKSPACE), 1)
|
||||||
|
|
||||||
|
expect_line_col(t, buffer.cursor, 0, 0)
|
||||||
|
expect_cursor_index(t, buffer.cursor, 0, 0)
|
||||||
|
testing.expect(t, len(buffer.content_slices) > 0, "BACKSPACE deleted final content slice in buffer")
|
||||||
|
|
||||||
|
// "commit" insert mode changes, then re-enter insert mode and try to delete again
|
||||||
|
run_input_multiple(&e, press_key(.ESCAPE), 1)
|
||||||
|
run_input_multiple(&e, press_key(.I), 1)
|
||||||
|
run_input_multiple(&e, press_key(.BACKSPACE), 1)
|
||||||
|
|
||||||
|
expect_line_col(t, buffer.cursor, 0, 0)
|
||||||
|
expect_cursor_index(t, buffer.cursor, 0, 0)
|
||||||
|
testing.expect(t, len(buffer.content_slices) > 0, "BACKSPACE deleted final content slice in buffer")
|
||||||
|
}
|
||||||
|
|
||||||
@(test)
|
@(test)
|
||||||
delete_in_slice :: proc(t: ^testing.T) {
|
delete_in_slice :: proc(t: ^testing.T) {
|
||||||
e := new_test_editor()
|
e := new_test_editor()
|
||||||
|
|
Loading…
Reference in New Issue