fix: account display order is now tracked across all files (fix #1909)

This commit is contained in:
Simon Michael 2022-08-04 19:05:52 +01:00
parent 3b34987bdd
commit 09d66c5fc1
2 changed files with 14 additions and 1 deletions

View File

@ -199,7 +199,9 @@ instance Show Journal where
-- Note that (<>) is right-biased, so nulljournal is only a left identity.
-- In particular, this prevents Journal from being a monoid.
instance Semigroup Journal where
j1 <> j2 = Journal {
j1 <> j2 =
journalRenumberAccountDeclarations $
Journal {
jparsedefaultyear = jparsedefaultyear j2
,jparsedefaultcommodity = jparsedefaultcommodity j2
,jparsedecimalmark = jparsedecimalmark j2
@ -226,6 +228,14 @@ instance Semigroup Journal where
,jlastreadtime = max (jlastreadtime j1) (jlastreadtime j2)
}
-- | Renumber all the account declarations. Call this after combining two journals into one,
-- so that account declarations have a total order again.
journalRenumberAccountDeclarations :: Journal -> Journal
journalRenumberAccountDeclarations j = j{jdeclaredaccounts=jdas'}
where
jdas' = [(a, adi{adideclarationorder=n}) | (n, (a,adi)) <- zip [1..] $ jdeclaredaccounts j]
-- XXX the per-file declaration order saved during parsing is discarded; it seems unneeded
instance Default Journal where
def = nulljournal

View File

@ -401,6 +401,9 @@ addAccountDeclaration (a,cmt,tags) =
adicomment = cmt
,aditags = tags
,adideclarationorder = length decls + 1
-- this restarts from 1 in each file, which is not that useful
-- when there are multiple files; so it gets renumbered
-- automatically when combining Journals with <>
})
in
j{jdeclaredaccounts = d:decls})