summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlbert Cervin <albert@acervin.com>2024-01-25 10:45:45 +0100
committerAlbert Cervin <albert@acervin.com>2024-01-25 10:45:45 +0100
commitf384a3826bae1eb9f500ad6b9dbaa5f904dfbf42 (patch)
tree711f3af1bc6b5c6492f15d73d885b56c79dae1f8 /src
parent9433096a73d6af7cac7b05b087a740b2d070f463 (diff)
downloaddged-f384a3826bae1eb9f500ad6b9dbaa5f904dfbf42.tar.gz
dged-f384a3826bae1eb9f500ad6b9dbaa5f904dfbf42.tar.xz
dged-f384a3826bae1eb9f500ad6b9dbaa5f904dfbf42.zip
Restore lazy row addition
Diffstat (limited to 'src')
-rw-r--r--src/dged/buffer.c21
-rw-r--r--src/dged/buffer.h3
-rw-r--r--src/main/main.c1
3 files changed, 17 insertions, 8 deletions
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,