From 35cd037326946742ba985b4fbbd2b6078a4b85ea Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Sat, 21 Sep 2024 15:33:56 +0100 Subject: [PATCH] Bug 798568 - Transaction Copy/Paste problem When transactions are copied and pasted to the blank transaction on a register in basic view the wrong split values are displayed. This is due to the blank split being used for the wrong side of the transaction. To fix this, record the copied anchor split index and use that to reference the blank split when the transaction is pasted. --- gnucash/register/ledger-core/split-register.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/gnucash/register/ledger-core/split-register.c b/gnucash/register/ledger-core/split-register.c index dea3c4576b..badd84f50b 100644 --- a/gnucash/register/ledger-core/split-register.c +++ b/gnucash/register/ledger-core/split-register.c @@ -73,6 +73,7 @@ typedef struct }; CursorClass cursor_class; GncGUID leader_guid; + gint anchor_split_index; } ft_fs_store; static ft_fs_store copied_item = { 0, { NULL } }; @@ -101,6 +102,7 @@ clear_copied_item() copied_item.ft = NULL; copied_item.cursor_class = CURSOR_CLASS_NONE; copied_item.leader_guid = *guid_null(); + copied_item.anchor_split_index = 0; } static void @@ -828,6 +830,7 @@ gnc_split_register_copy_current_internal (SplitRegister* reg, } copied_item.leader_guid = info->default_account; + copied_item.anchor_split_index = xaccTransGetSplitIndex (trans, split); } } @@ -1082,7 +1085,11 @@ gnc_split_register_paste_current (SplitRegister* reg) if (trans == blank_trans) { /* In pasting, the blank split is deleted. Pick a new one. */ - blank_split = xaccTransGetSplit (trans, 0); + gint anchor_split_index = copied_item.anchor_split_index; + if (anchor_split_index > num_splits) + anchor_split_index = 0; + + blank_split = xaccTransGetSplit (trans, anchor_split_index); info->blank_split_guid = *xaccSplitGetGUID (blank_split); info->blank_split_edited = TRUE; info->auto_complete = FALSE;