From 19fb6109b8d222e3c870fbd3901369f1a5f06fdb Mon Sep 17 00:00:00 2001 From: Albert Cervin Date: Tue, 12 Nov 2024 20:18:55 +0100 Subject: Handle kill buffer wraparound correctly Id did not use position 0 properly and caused it to "lose" copy/paste information when the kill ring wrapped around. --- src/dged/buffer.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/dged/buffer.c') diff --git a/src/dged/buffer.c b/src/dged/buffer.c index d4501b7..b833a78 100644 --- a/src/dged/buffer.c +++ b/src/dged/buffer.c @@ -1005,14 +1005,13 @@ struct location buffer_delete(struct buffer *buffer, struct region region) { static struct location paste(struct buffer *buffer, struct location at, uint32_t ring_idx) { + uint32_t idx = ring_idx > 0 ? ring_idx - 1 : (KILL_RING_SZ - 1); struct location new_loc = at; - if (ring_idx > 0) { - struct text_chunk *curr = &g_kill_ring.buffer[ring_idx - 1]; - if (curr->text != NULL) { - g_kill_ring.last_paste = at; - new_loc = buffer_add(buffer, at, curr->text, curr->nbytes); - g_kill_ring.paste_up_to_date = true; - } + struct text_chunk *curr = &g_kill_ring.buffer[idx]; + if (curr->text != NULL) { + g_kill_ring.last_paste = at; + new_loc = buffer_add(buffer, at, curr->text, curr->nbytes); + g_kill_ring.paste_up_to_date = true; } return new_loc; @@ -1030,7 +1029,7 @@ struct location buffer_paste_older(struct buffer *buffer, struct location at) { buffer_delete(buffer, region_new(g_kill_ring.last_paste, at)); // paste older - if (g_kill_ring.paste_idx - 1 > 0) { + if (g_kill_ring.paste_idx > 0) { --g_kill_ring.paste_idx; } else { g_kill_ring.paste_idx = g_kill_ring.curr_idx; -- cgit v1.2.3