CE split lines properly
This commit is contained in:
11
ce/edit.c
11
ce/edit.c
@@ -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;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef _EDIT_H
|
||||
#define _EDIT_H
|
||||
|
||||
void edit_start (const char* path, const char* text);
|
||||
#include <stddef.h>
|
||||
|
||||
void edit_start (const char* path, const char* text, size_t text_len);
|
||||
|
||||
#endif // _EDIT_H
|
||||
|
||||
@@ -265,7 +265,7 @@ static void edit (struct context* context, const char* path_string) {
|
||||
return;
|
||||
}
|
||||
|
||||
edit_start (path_string, str);
|
||||
edit_start (path_string, str, desc.size);
|
||||
|
||||
volume_close ();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user