From eb3238bf854fc4a48ba3bfe7f1af34d5464515d9 Mon Sep 17 00:00:00 2001 From: kamkow1 Date: Fri, 6 Mar 2026 00:44:33 +0100 Subject: [PATCH] CE edit implement line breaking --- ce/edit.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ce/edit.c b/ce/edit.c index 916e286..ac386e3 100644 --- a/ce/edit.c +++ b/ce/edit.c @@ -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++;