From ac2511bd5ad5889c24f827d2e513faf676241bf2 Mon Sep 17 00:00:00 2001 From: Simon Arlott Date: Mon, 5 Jun 2023 12:41:20 +0100 Subject: [PATCH] Fallback register "Jump" operation to the only other account There may be multiple splits but only one other account. In this scenario we can jump to the first split for that account. --- gnucash/gnome/gnc-plugin-page-register.cpp | 41 +++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/gnucash/gnome/gnc-plugin-page-register.cpp b/gnucash/gnome/gnc-plugin-page-register.cpp index 970d8f45b7..f8f3843ffc 100644 --- a/gnucash/gnome/gnc-plugin-page-register.cpp +++ b/gnucash/gnome/gnc-plugin-page-register.cpp @@ -4862,6 +4862,44 @@ gnc_plugin_page_register_cmd_exchange_rate (GSimpleAction *simple, LEAVE (" "); } +static Split* +jump_multiple_splits_by_single_account (Account *account, Split *split) +{ + Transaction *trans; + SplitList *splits; + Account *other_account = NULL; + Split *other_split = NULL; + + trans = xaccSplitGetParent(split); + if (!trans) + return NULL; + + for (splits = xaccTransGetSplitList(trans); splits; splits = splits->next) + { + Split *s = (Split*)splits->data; + Account *a = xaccSplitGetAccount(s); + + if (!xaccTransStillHasSplit(trans, s)) + continue; + + if (a == account) + continue; + + if (other_split) + { + if (other_account != a) + return NULL; + + continue; + } + + other_account = a; + other_split = s; + } + + return other_split; +} + static Split* jump_multiple_splits_by_value (Account *account, Split *split, gboolean largest) { @@ -4921,7 +4959,8 @@ jump_multiple_splits (Account* account, Split *split) break; } - return NULL; + // If there's only one other account, use that one + return jump_multiple_splits_by_single_account (account, split); } static void