summaryrefslogtreecommitdiff
path: root/src/dged
diff options
context:
space:
mode:
authorAlbert Cervin <albert@acervin.com>2024-11-07 13:47:50 +0100
committerAlbert Cervin <albert@acervin.com>2024-11-07 13:47:50 +0100
commit3e5359d062fa2f0d48e6f7675802b875e11ee109 (patch)
treeafe7358b9e62abbc2d54e710c849f3769fe47994 /src/dged
parent8259a3c5d4caf31423d8ca3108c4f2a1f9bd78af (diff)
downloaddged-3e5359d062fa2f0d48e6f7675802b875e11ee109.tar.gz
dged-3e5359d062fa2f0d48e6f7675802b875e11ee109.tar.xz
dged-3e5359d062fa2f0d48e6f7675802b875e11ee109.zip
Fix location after inserting multi-line
Previously assumed that column was 0 if more than one line was inserted. This was never correct.
Diffstat (limited to 'src/dged')
-rw-r--r--src/dged/buffer.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/dged/buffer.c b/src/dged/buffer.c
index 84d2f75..91c1a14 100644
--- a/src/dged/buffer.c
+++ b/src/dged/buffer.c
@@ -526,25 +526,26 @@ struct location buffer_add(struct buffer *buffer, struct location at,
struct location at_bytes = buffer_location_to_byte_coords(buffer, at);
- uint32_t lines_added;
+ uint32_t ignore_;
text_insert_at(buffer->text, at_bytes.line, at_bytes.col, text, nbytes,
- &lines_added);
+ &ignore_);
// move to after inserted text
- if (lines_added > 0) {
- final = buffer_clamp(buffer, (int64_t)at.line + lines_added, 0);
- } else {
- uint32_t cols_added = 0, tab_width = get_tab_width(buffer);
- struct utf8_codepoint_iterator iter =
- create_utf8_codepoint_iterator(text, nbytes, 0);
- struct codepoint *codepoint;
- while ((codepoint = utf8_next_codepoint(&iter)) != NULL) {
- cols_added += visual_char_width(codepoint, tab_width);
+ uint32_t cols_added = 0, lines_added = 0, tab_width = get_tab_width(buffer);
+ struct utf8_codepoint_iterator iter =
+ create_utf8_codepoint_iterator(text, nbytes, 0);
+ struct codepoint *codepoint;
+ while ((codepoint = utf8_next_codepoint(&iter)) != NULL) {
+ if (codepoint->codepoint == '\n') {
+ cols_added = 0;
+ ++lines_added;
+ continue;
}
- final =
- buffer_clamp(buffer, (int64_t)at.line, (int64_t)at.col + cols_added);
- }
+ cols_added += visual_char_width(codepoint, tab_width);
+ }
+ final = buffer_clamp(buffer, (int64_t)at.line + lines_added,
+ (int64_t)at.col + cols_added);
struct location final_bytes = buffer_location_to_byte_coords(buffer, final);
undo_push_add(