From 16913585f4ab49e3685a67eaa7c9a9caf3ffad08 Mon Sep 17 00:00:00 2001 From: SuperNovaa41 Date: Wed, 15 Jan 2025 19:46:59 -0500 Subject: [PATCH] implements line splitting --- src/draw.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/draw.c b/src/draw.c index 67f1953..a9d1b55 100644 --- a/src/draw.c +++ b/src/draw.c @@ -47,22 +47,38 @@ void refresh_screen(void) void draw_file_buffer(void) { - size_t i; + size_t i, idx; size_t tmp_len; - - char* working_line; - char* tmp_line; + + char tmp_line[editor.screen_cols + 2]; // reserve the last line for info for (i = editor.row_offset; i < editor.num_rows && i < (editor.screen_rows + editor.row_offset - 1); i++) { if (editor.rows[i].len <= editor.screen_cols) { screen_buffer_append(CLEAR_LINE_STR, CLEAR_LINE_STR_LEN); // clear line first to prevent flickering issues screen_buffer_append(editor.rows[i].line, editor.rows[i].len); + continue; } // want to do line splitting here // mimick vim in which we split the overflow line to the next below + tmp_len = editor.rows[i].len; + idx = 0; + while (tmp_len > editor.screen_cols) { + strncpy(tmp_line, &(editor.rows[i].line)[idx], editor.screen_cols); + tmp_line[editor.screen_cols] = '\n'; + tmp_line[editor.screen_cols + 1] = '\0'; + screen_buffer_append(tmp_line, editor.screen_cols + 2); + + idx += editor.screen_cols; + tmp_len -= editor.screen_cols; + } + + strncpy(tmp_line, &(editor.rows[i].line)[idx], tmp_len); + tmp_line[tmp_len] = '\0'; + + screen_buffer_append(tmp_line, tmp_len + 2); } }