summaryrefslogtreecommitdiff
path: root/src/dged/buffer.c
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/dged/buffer.c
parent9433096a73d6af7cac7b05b087a740b2d070f463 (diff)
downloaddged-f384a3826bae1eb9f500ad6b9dbaa5f904dfbf42.tar.gz
dged-f384a3826bae1eb9f500ad6b9dbaa5f904dfbf42.tar.xz
dged-f384a3826bae1eb9f500ad6b9dbaa5f904dfbf42.zip
Restore lazy row addition
Diffstat (limited to 'src/dged/buffer.c')
-rw-r--r--src/dged/buffer.c21
1 files changed, 13 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;