CE split lines properly

This commit is contained in:
2026-03-08 21:03:54 +01:00
parent 5682a96d5d
commit 43ce80e764
5 changed files with 59 additions and 8 deletions

View File

@@ -72,7 +72,8 @@ static bool prepare_lines_cb (void* ctx, const char* start, size_t len) {
return false;
memset (line, 0, sizeof (*line));
gapbuffer_init (&wmalloc, NULL, &line->gb, len);
size_t init_len = len > 0 ? len : 32;
gapbuffer_init (&wmalloc, NULL, &line->gb, init_len);
for (size_t chr = 0; chr < len; chr++)
gapbuffer_insert (&wrealloc, NULL, &line->gb, start[chr]);
@@ -87,7 +88,9 @@ static bool prepare_lines_cb (void* ctx, const char* start, size_t len) {
return true;
}
static void prepare_lines (const char* text) { strtokenize (text, '\n', NULL, &prepare_lines_cb); }
static void prepare_lines (const char* text, size_t len) {
str_split_lines (text, len, NULL, &prepare_lines_cb);
}
static void update_horz_scroll (size_t screen_cols) {
if (editor.cursor.col < editor.col_offset)
@@ -118,10 +121,10 @@ static size_t count_digits (size_t n) {
return count;
}
void edit_start (const char* file_path, const char* text) {
void edit_start (const char* file_path, const char* text, size_t text_len) {
mprintf (ANSIQ_SCR_SAVE);
prepare_lines (text);
prepare_lines (text, text_len);
struct arena temp_arena;
memset (&temp_arena, 0, sizeof (temp_arena));
size_t cols, rows;