From 5364889cb38e841a19f20097b117af8030a969c5 Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Fri, 5 Feb 2021 19:12:23 -0500 Subject: finishing touches for v. 0.2 --- buffer.c | 21 +++++++++++---------- command.c | 4 ++-- menu.c | 1 + 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/buffer.c b/buffer.c index bc5fe0b..5e5972b 100644 --- a/buffer.c +++ b/buffer.c @@ -1847,6 +1847,16 @@ bool buffer_save(TextBuffer *buffer) { if (!buffer->is_line_buffer && buffer->filename) { FILE *out = fopen(buffer->filename, "wb"); if (out) { + if (settings->auto_add_newline) { + Line *last_line = &buffer->lines[buffer->nlines - 1]; + if (last_line->len) { + // if the last line isn't empty, add a newline to the end of the file + char32_t c = '\n'; + String32 s = {&c, 1}; + buffer_insert_text_at_pos(buffer, buffer_end_of_file(buffer), s); + } + } + for (u32 i = 0; i < buffer->nlines; ++i) { Line *line = &buffer->lines[i]; for (char32_t *p = line->str, *p_end = p + line->len; p != p_end; ++p) { @@ -1861,15 +1871,6 @@ bool buffer_save(TextBuffer *buffer) { if (i != buffer->nlines-1) { putc('\n', out); - } else { - if (settings->auto_add_newline) { - if (line->len) { - // if the last line isn't empty, add a newline to the end of the file - char32_t c = '\n'; - String32 s = {&c, 1}; - buffer_insert_text_at_pos(buffer, buffer_end_of_file(buffer), s); - } - } } } if (ferror(out)) { @@ -1989,7 +1990,7 @@ void buffer_render(TextBuffer *buffer, Rect r) { x1 += 2; // a little bit of padding // line separating line numbers from text gl_geometry_rect(rect(V2(x1, y1), V2(border_thickness, y2 - y1)), colors[COLOR_LINE_NUMBERS_SEPARATOR]); - x1 += padding + border_thickness; + x1 += border_thickness; } buffer->x1 = x1; buffer->y1 = y1; buffer->x2 = x2; buffer->y2 = y2; diff --git a/command.c b/command.c index da1701a..2c43258 100644 --- a/command.c +++ b/command.c @@ -104,14 +104,14 @@ void command_execute(Ted *ted, Command c, i64 argument) { if (!buffer) { } else if (buffer->is_line_buffer) { switch (ted->menu) { + case MENU_ASK_RELOAD: + case MENU_WARN_UNSAVED: case MENU_NONE: - assert(0); break; case MENU_OPEN: case MENU_SAVE_AS: { ted->file_selector.submitted = true; } break; - case MENU_WARN_UNSAVED: break; } } else { buffer_newline(buffer); diff --git a/menu.c b/menu.c index d7af1e9..8600136 100644 --- a/menu.c +++ b/menu.c @@ -202,6 +202,7 @@ static void menu_render(Ted *ted, Menu menu) { return; } switch (menu) { + case MENU_NONE: assert(0); break; case MENU_WARN_UNSAVED: { char title[64] = {0}, body[1024] = {0}; strbuf_printf(title, "Save changes?"); -- cgit v1.2.3