CE edit KB_DELETE the following line
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m2s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m2s
This commit is contained in:
19
ce/edit.c
19
ce/edit.c
@@ -272,11 +272,26 @@ void edit_start (const char* file_path, const char* text) {
|
||||
case KB_DELETE:
|
||||
if (editor.mode == EDIT_MODE_NORMAL) {
|
||||
size_t len = gapbuffer_length (&editor.current_line->gb);
|
||||
if (editor.cursor.col < len) {
|
||||
gapbuffer_move (&editor.current_line->gb, editor.cursor.col);
|
||||
gapbuffer_move (&editor.current_line->gb, editor.cursor.col);
|
||||
|
||||
if (editor.cursor.col < len) {
|
||||
if (editor.current_line->gb.gap_end < editor.current_line->gb.size)
|
||||
editor.current_line->gb.gap_end++;
|
||||
} else {
|
||||
if (editor.cursor.line > 0) {
|
||||
struct list_node_link* next = editor.current_line->lines_link.next;
|
||||
struct edit_line* next_line = list_entry (next, struct edit_line, lines_link);
|
||||
size_t next_len = gapbuffer_length (&next_line->gb);
|
||||
|
||||
for (size_t i = 0; i < next_len; i++) {
|
||||
char chr = gapbuffer_at (&next_line->gb, i);
|
||||
gapbuffer_insert (&wrealloc, NULL, &editor.current_line->gb, chr);
|
||||
}
|
||||
|
||||
list_remove (editor.lines, &next_line->lines_link);
|
||||
free (next_line->gb.buffer);
|
||||
free (next_line);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -112,3 +112,10 @@ char* gapbuffer_string_at (gb_malloc_func_t mallocfn, void* ctx, struct gapbuffe
|
||||
res[written] = '\0';
|
||||
return res;
|
||||
}
|
||||
|
||||
char gapbuffer_at (struct gapbuffer* gb, size_t index) {
|
||||
if (index < gb->gap_start)
|
||||
return gb->buffer[index];
|
||||
else
|
||||
return gb->buffer[index + (gb->gap_end - gb->gap_start)];
|
||||
}
|
||||
|
||||
@@ -33,4 +33,6 @@ size_t gapbuffer_length (struct gapbuffer* gb);
|
||||
|
||||
char* gapbuffer_string_at (gb_malloc_func_t mallocfn, void* ctx, struct gapbuffer* gb, size_t pos);
|
||||
|
||||
char gapbuffer_at (struct gapbuffer* gb, size_t index);
|
||||
|
||||
#endif // _GAPBUFFER_H
|
||||
|
||||
Reference in New Issue
Block a user