From f384a3826bae1eb9f500ad6b9dbaa5f904dfbf42 Mon Sep 17 00:00:00 2001 From: Albert Cervin Date: Thu, 25 Jan 2024 10:45:45 +0100 Subject: Restore lazy row addition --- src/dged/buffer.c | 21 +++++++++++++-------- src/dged/buffer.h | 3 +++ src/main/main.c | 1 + 3 files changed, 17 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/dged/buffer.c b/src/dged/buffer.c index 78b89c8..7eb4b00 100644 --- a/src/dged/buffer.c +++ b/src/dged/buffer.c @@ -133,6 +133,7 @@ static struct buffer create_internal(const char *name, char *filename) { .text = text_create(10), .modified = false, .readonly = false, + .lazy_row_add = true, .lang = filename != NULL ? lang_from_filename(filename) : lang_from_id("fnd"), .last_write = {0}, @@ -570,14 +571,18 @@ struct location buffer_clamp(struct buffer *buffer, int64_t line, int64_t col) { return location; } - movev(buffer, line, &location); - moveh(buffer, col, &location); - - // when clamping we want to stay inside - // the actual bounds - if (location.line >= buffer_num_lines(buffer)) { - location.line = buffer_num_lines(buffer) - 1; - location.col = buffer_num_chars(buffer, location.line); + if (line > buffer_num_lines(buffer)) { + if (buffer->lazy_row_add) { + location.line = buffer_num_lines(buffer); + location.col = 0; + } else { + location.line = buffer_num_lines(buffer) - 1; + location.col = buffer_num_chars(buffer, location.line); + } + } else { + location.line = line; + uint32_t nchars = buffer_num_chars(buffer, location.col); + location.col = col > nchars ? nchars : col; } return location; diff --git a/src/dged/buffer.h b/src/dged/buffer.h index 7e4ef78..1e00b9d 100644 --- a/src/dged/buffer.h +++ b/src/dged/buffer.h @@ -50,6 +50,9 @@ struct buffer { /** Can this buffer be changed */ bool readonly; + + /** Can rows be added lazily to this buffer */ + bool lazy_row_add; }; void buffer_static_init(); diff --git a/src/main/main.c b/src/main/main.c index 1bb3003..02afd2b 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -226,6 +226,7 @@ int main(int argc, char *argv[]) { struct buffer *ib = buffers_add(&buflist, initial_buffer); struct buffer minibuffer = buffer_create("minibuffer"); + minibuffer.lazy_row_add = false; minibuffer_init(&minibuffer); windows_init(display_height(display), display_width(display), ib, -- cgit v1.2.3