ui: accounts: hold selection better during F toggle
This commit is contained in:
		
							parent
							
								
									ddf18060ab
								
							
						
					
					
						commit
						4ab1536ea0
					
				| @ -52,21 +52,22 @@ initAccountsScreen :: Day -> AppState -> AppState | |||||||
| initAccountsScreen d st@AppState{ | initAccountsScreen d st@AppState{ | ||||||
|   aopts=uopts@UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}}, |   aopts=uopts@UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}}, | ||||||
|   ajournal=j, |   ajournal=j, | ||||||
|   aScreen=s@AccountsScreen{asState=(_,selacct)} |   aScreen=s@AccountsScreen{asState=(oldl,selacct)} | ||||||
|   } = |   } = | ||||||
|   st{aopts=uopts', aScreen=s{asState=(l',selacct)}} |   st{aopts=uopts', aScreen=s{asState=(newl',selacct)}} | ||||||
|    where |    where | ||||||
|     l = list (Name "accounts") (V.fromList displayitems) 1 |     newl = list (Name "accounts") (V.fromList displayitems) 1 | ||||||
| 
 | 
 | ||||||
|     -- keep the selection near the last known selected account if possible |     -- keep the selection near the last selected account | ||||||
|     l' | T.null selacct = l |     -- (may need to move to the next leaf account when entering flat mode) | ||||||
|        | otherwise = maybe l (flip listMoveTo l) midx |     newl' = listMoveTo selidx newl | ||||||
|       where |       where | ||||||
|         midx = findIndex (\((a,_,_),_) -> a==selacctclipped) items |         selidx = case listSelectedElement oldl of | ||||||
|         selacctclipped = case depth_ ropts of |                    Nothing            -> 0 | ||||||
|                           Nothing -> selacct |                    Just (_,(_,a,_,_)) -> fromMaybe (fromMaybe 0 mprefixmatch) mexactmatch | ||||||
|                           Just d  -> clipAccountName d selacct |                      where | ||||||
| 
 |                        mexactmatch  = findIndex ((a ==)                      . second4) displayitems | ||||||
|  |                        mprefixmatch = findIndex ((a `isAccountNamePrefixOf`) . second4) displayitems | ||||||
|     uopts' = uopts{cliopts_=copts{reportopts_=ropts'}} |     uopts' = uopts{cliopts_=copts{reportopts_=ropts'}} | ||||||
|     ropts' = ropts { |     ropts' = ropts { | ||||||
|       -- XXX balanceReport doesn't respect this yet |       -- XXX balanceReport doesn't respect this yet | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user