summaryrefslogtreecommitdiff
path: root/src/dged
diff options
context:
space:
mode:
Diffstat (limited to 'src/dged')
-rw-r--r--src/dged/buffer.c21
-rw-r--r--src/dged/buffer.h3
2 files changed, 16 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();