CE edit KB_DELETE the following line
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m2s

This commit is contained in:
2026-03-08 11:55:09 +01:00
parent 0692b030cb
commit 0de0b4c1ae
3 changed files with 26 additions and 2 deletions

View File

@@ -272,11 +272,26 @@ void edit_start (const char* file_path, const char* text) {
case KB_DELETE: case KB_DELETE:
if (editor.mode == EDIT_MODE_NORMAL) { if (editor.mode == EDIT_MODE_NORMAL) {
size_t len = gapbuffer_length (&editor.current_line->gb); 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) if (editor.current_line->gb.gap_end < editor.current_line->gb.size)
editor.current_line->gb.gap_end++; 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; break;

View File

@@ -112,3 +112,10 @@ char* gapbuffer_string_at (gb_malloc_func_t mallocfn, void* ctx, struct gapbuffe
res[written] = '\0'; res[written] = '\0';
return res; 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)];
}

View File

@@ -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_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 #endif // _GAPBUFFER_H