From e9c1fc36a382fb3eaa9a3cf4f8c94cba301dc3d2 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Fri, 12 Sep 2025 09:58:46 +0100 Subject: [PATCH] fix:ui:transaction screen: update on data changes, second fix [#2288] This one is more thorough and hopefully more robust. Compared to the first fix, it fixes an error seen in --watch mode when you save an error (and maybe then save a second edit, and then repair the error - I forget) --- hledger-ui/Hledger/UI/TransactionScreen.hs | 23 +++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/hledger-ui/Hledger/UI/TransactionScreen.hs b/hledger-ui/Hledger/UI/TransactionScreen.hs index 31fce4229..7d1409f2f 100644 --- a/hledger-ui/Hledger/UI/TransactionScreen.hs +++ b/hledger-ui/Hledger/UI/TransactionScreen.hs @@ -142,11 +142,24 @@ tsHandle ev = do -- g or file change: reload the journal. e | e `elem` [VtyEvent (EvKey (KChar 'g') []), AppEvent FileChange] -> do - -- To update all state: exit to register screen, regenerate screens, re-enter transaction screen. - -- Anywhere else here that we need to be this thorough ? - uiReload copts d (popScreen ui) >>= put' - rsHandle (VtyEvent (EvKey KEnter [])) - -- + -- Update app state. This is tricky: (XXX anywhere else we need to be this thorough ?) + + -- Reload and regenerate screens + ui1 <- uiReload copts d ui + -- If that moved us to the error screen, save that and return to the transaction screen. + let + (merrscr, ui2) = case aScreen ui1 of + s@(ES _) -> (Just s, popScreen ui1) + _ -> (Nothing, ui1) + -- put' ui2 + -- Now exit to register screen and make it regenerate the transaction screen, + -- for best initialisation. + put' $ popScreen ui2 + rsHandle (VtyEvent (EvKey KEnter [])) -- XXX PARTIAL assumes we are on the register screen + -- Then re-enter the error screen if any, so error repair will return to the transaction screen. + let ui3 = maybe ui2 (`pushScreen` ui2) merrscr + put' ui3 + -- for debugging; leaving these here because they were hard to find -- \u -> dbguiEv (pshow u) >> put' u -- doesn't log -- \UIState{aScreen=TS tss} -> error' $ pshow $ _tssTransaction tss