summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlbert Cervin <albert@acervin.com>2024-11-12 20:18:55 +0100
committerAlbert Cervin <albert@acervin.com>2024-11-12 20:18:55 +0100
commit19fb6109b8d222e3c870fbd3901369f1a5f06fdb (patch)
tree731b554c937c11682be58932f2f6f4f4722199b9 /src
parent21df07a097662a1c3f00c36f822e7f2b3429c50f (diff)
downloaddged-19fb6109b8d222e3c870fbd3901369f1a5f06fdb.tar.gz
dged-19fb6109b8d222e3c870fbd3901369f1a5f06fdb.tar.xz
dged-19fb6109b8d222e3c870fbd3901369f1a5f06fdb.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/dged/buffer.c15
1 files changed, 7 insertions, 8 deletions
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;