fix cursor drift + tests
parent
f8ba2e587d
commit
f6d7dc0db0
|
@ -527,9 +527,12 @@ move_cursor_down :: proc(buffer: ^FileBuffer, amount: int = 1, cursor: Maybe(^Cu
|
|||
break;
|
||||
}
|
||||
}
|
||||
if it.hit_end {
|
||||
return
|
||||
}
|
||||
|
||||
line_length := file_buffer_line_length(buffer, it.cursor.index);
|
||||
if it.cursor.col < line_length && it.cursor.col < current_col {
|
||||
if it.cursor.col < line_length-1 && it.cursor.col < current_col {
|
||||
for _ in iterate_file_buffer(&it) {
|
||||
if it.cursor.col >= line_length-1 || it.cursor.col >= current_col {
|
||||
break;
|
||||
|
|
|
@ -322,6 +322,49 @@ delete_across_slices :: proc(t: ^testing.T) {
|
|||
testing.expectf(t, contents == expected_text, "got '%v', expected '%v'", contents, expected_text)
|
||||
}
|
||||
|
||||
@(test)
|
||||
move_down_next_line_has_shorter_length :: proc(t: ^testing.T) {
|
||||
e := new_test_editor()
|
||||
setup_empty_buffer(&e)
|
||||
|
||||
is_ctrl_pressed := false
|
||||
|
||||
buffer := &e.buffers[0]
|
||||
|
||||
run_text_insertion(&e, "012345678\n0")
|
||||
|
||||
// Move up to the first line
|
||||
run_input_multiple(&e, press_key(.K), 1)
|
||||
|
||||
// Move to the end of the line
|
||||
run_inputs(&e, []ArtificialInput{ press_key(.G), press_key(.L)})
|
||||
|
||||
// Move down to the second line
|
||||
run_input_multiple(&e, press_key(.J), 1)
|
||||
|
||||
expect_line_col(t, buffer.cursor, 1, 0)
|
||||
expect_cursor_index(t, buffer.cursor, 0, 10)
|
||||
}
|
||||
|
||||
@(test)
|
||||
move_down_on_last_line :: proc(t: ^testing.T) {
|
||||
e := new_test_editor()
|
||||
setup_empty_buffer(&e)
|
||||
|
||||
is_ctrl_pressed := false
|
||||
|
||||
buffer := &e.buffers[0]
|
||||
|
||||
run_text_insertion(&e, "012345678")
|
||||
|
||||
// Try to move down
|
||||
run_input_multiple(&e, press_key(.J), 1)
|
||||
|
||||
// Cursor should stay where it is
|
||||
expect_line_col(t, buffer.cursor, 0, 8)
|
||||
expect_cursor_index(t, buffer.cursor, 0, 8)
|
||||
}
|
||||
|
||||
@(test)
|
||||
move_left_at_beginning_of_file :: proc(t: ^testing.T) {
|
||||
e := new_test_editor()
|
||||
|
|
Loading…
Reference in New Issue