diff --git a/src/core/file_buffer.odin b/src/core/file_buffer.odin index e24005c..35fcb56 100644 --- a/src/core/file_buffer.odin +++ b/src/core/file_buffer.odin @@ -1081,7 +1081,9 @@ delete_content_from_buffer_cursor :: proc(buffer: ^FileBuffer, amount: int) { iterate_file_buffer_reverse(&it); 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 { runtime.ordered_remove(&buffer.content_slices, it.cursor.index.slice_index+1); } diff --git a/src/pkg/grep_lib/src/lib.rs b/src/pkg/grep_lib/src/lib.rs index 98548bf..be2df2c 100644 --- a/src/pkg/grep_lib/src/lib.rs +++ b/src/pkg/grep_lib/src/lib.rs @@ -1,17 +1,12 @@ use std::{ error::Error, - ffi::{CStr, CString, OsString}, - path::Path, - str::FromStr, - sync::mpsc::{Receiver, Sender}, - thread, + ffi::CStr, }; use grep::{ regex::RegexMatcherBuilder, searcher::{BinaryDetection, SearcherBuilder, Sink, SinkError}, }; -use std::sync::mpsc::channel; use walkdir::WalkDir; #[derive(Debug)] diff --git a/src/tests/tests.odin b/src/tests/tests.odin index f5e8fda..4827042 100644 --- a/src/tests/tests.odin +++ b/src/tests/tests.odin @@ -246,6 +246,39 @@ insert_before_slice :: proc(t: ^testing.T) { 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) delete_in_slice :: proc(t: ^testing.T) { e := new_test_editor()