fix cursor bug + fix crash
parent
d28a707a8f
commit
cf21773e6f
|
@ -88,16 +88,18 @@ file_buffer_end :: proc(buffer: ^FileBuffer) -> Cursor {
|
|||
iterate_file_buffer :: proc(it: ^FileBufferIter) -> (character: u8, idx: PieceTableIndex, cond: bool) {
|
||||
character, idx, cond = iterate_piece_table_iter(&it.piter)
|
||||
|
||||
if character == '\n' {
|
||||
it.cursor.col = 0
|
||||
it.cursor.line += 1
|
||||
} else {
|
||||
it.cursor.col += 1
|
||||
}
|
||||
|
||||
it.cursor.index = it.piter.index
|
||||
it.hit_end = it.piter.hit_end
|
||||
|
||||
if cond && !it.hit_end {
|
||||
if character == '\n' {
|
||||
it.cursor.col = 0
|
||||
it.cursor.line += 1
|
||||
} else {
|
||||
it.cursor.col += 1
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -108,7 +110,7 @@ iterate_file_buffer_reverse :: proc(it: ^FileBufferIter) -> (character: u8, idx:
|
|||
it.cursor.index = it.piter.index
|
||||
it.hit_end = it.piter.hit_end
|
||||
|
||||
if cond {
|
||||
if cond && !it.hit_end {
|
||||
if it.cursor.col > 0 {
|
||||
it.cursor.col -= 1
|
||||
} else if it.cursor.line > 0 {
|
||||
|
|
|
@ -301,11 +301,13 @@ make_grep_panel :: proc(state: ^core.State) -> core.Panel {
|
|||
free_grep_results(rs_results)
|
||||
|
||||
panel_state.selected_result = 0
|
||||
core.update_glyph_buffer_from_bytes(
|
||||
&panel_state.glyphs,
|
||||
transmute([]u8)panel_state.query_results[panel_state.selected_result].file_context,
|
||||
panel_state.query_results[panel_state.selected_result].line,
|
||||
)
|
||||
if len(panel_state.query_results) > 0 {
|
||||
core.update_glyph_buffer_from_bytes(
|
||||
&panel_state.glyphs,
|
||||
transmute([]u8)panel_state.query_results[panel_state.selected_result].file_context,
|
||||
panel_state.query_results[panel_state.selected_result].line,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
core.register_key_action(&input_map.mode[.Normal], .ENTER, proc(state: ^core.State) {
|
||||
|
|
|
@ -536,6 +536,28 @@ move_to_beginning_of_line_from_start :: proc(t: ^testing.T) {
|
|||
expect_cursor_index(t, buffer.cursor, 0, 0)
|
||||
}
|
||||
|
||||
@(test)
|
||||
append_end_of_line :: proc(t: ^testing.T) {
|
||||
e := new_test_editor()
|
||||
setup_empty_buffer(&e)
|
||||
|
||||
buffer := &e.buffers[0]
|
||||
|
||||
run_text_insertion(&e, "hello")
|
||||
|
||||
run_input_multiple(&e, press_key(.A), 1)
|
||||
run_input_multiple(&e, press_key(.ESCAPE), 1)
|
||||
|
||||
expect_line_col(t, buffer.cursor, 0, 5)
|
||||
expect_cursor_index(t, buffer.cursor, 1, 0)
|
||||
|
||||
run_input_multiple(&e, press_key(.A), 1)
|
||||
run_input_multiple(&e, press_key(.ESCAPE), 1)
|
||||
|
||||
expect_line_col(t, buffer.cursor, 0, 5)
|
||||
expect_cursor_index(t, buffer.cursor, 1, 0)
|
||||
}
|
||||
|
||||
@(test)
|
||||
insert_line_under_current :: proc(t: ^testing.T) {
|
||||
e := new_test_editor()
|
||||
|
|
Loading…
Reference in New Issue