CE edit implement line breaking
All checks were successful
Build documentation / build-and-deploy (push) Successful in 1m57s

This commit is contained in:
2026-03-06 00:44:33 +01:00
parent 17d5485a39
commit eb3238bf85

View File

@@ -175,6 +175,28 @@ void edit_start (const char* file_path, const char* text) {
gapbuffer_backspace (&editor.current_line->gb);
}
break;
case '\n': {
struct edit_line* new_line = malloc (sizeof (*new_line));
memset (new_line, 0, sizeof (*new_line));
char* tail = gapbuffer_string_at (&warena_malloc, &temp_arena, &editor.current_line->gb,
editor.cursor.col);
size_t tail_size = strlen (tail);
gapbuffer_init (&wmalloc, NULL, &new_line->gb, tail_size > 0 ? tail_size : 32);
for (size_t i = 0; i < tail_size; i++) {
char chr = gapbuffer_at (&editor.current_line->gb, editor.cursor.col);
gapbuffer_delete_at (&editor.current_line->gb, editor.cursor.col);
gapbuffer_insert (&wrealloc, NULL, &new_line->gb, chr);
}
list_insert_after (editor.lines, &editor.current_line->lines_link, &new_line->lines_link);
editor.cursor.col = 0;
editor.cursor.line++;
editor.current_line = new_line;
} break;
case KB_DELETE:
if (editor.cursor.col < gapbuffer_length (&editor.current_line->gb))
editor.current_line->gb.gap_end++;