From f5c3bbcaf05c8d7378aaa3215cac5be14dc63855 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Wed, 26 Apr 2023 22:40:41 -1000 Subject: [PATCH] fix: cli: posting comment lines no longer disturb the error marker (fix #1927) --- hledger-lib/Hledger/Data/Errors.hs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/hledger-lib/Hledger/Data/Errors.hs b/hledger-lib/Hledger/Data/Errors.hs index 32d37021c..12d71d64a 100644 --- a/hledger-lib/Hledger/Data/Errors.hs +++ b/hledger-lib/Hledger/Data/Errors.hs @@ -118,9 +118,17 @@ makePostingErrorExcerpt p findpostingerrorcolumns = Just t -> (f, errabsline, merrcols, ex) where (SourcePos f tl _) = fst $ tsourcepos t - tcommentlines = max 0 (length (T.lines $ tcomment t) - 1) mpindex = transactionFindPostingIndex (==p) t - errrelline = maybe 0 (tcommentlines+) mpindex -- XXX doesn't count posting coment lines + errrelline = case mpindex of + Nothing -> 0 + Just pindex -> + commentExtraLines (tcomment t) + + sum (map postingLines $ take pindex $ tpostings t) + where + postingLines p' = 1 + commentExtraLines (pcomment p') + -- How many extra lines does this possibly multi-line + -- transaction/posting comment add when rendered ? + commentExtraLines c = max 0 (length (T.lines c) - 1) errabsline = unPos tl + errrelline txntxt = showTransaction t & textChomp & (<>"\n") merrcols = findpostingerrorcolumns p t txntxt