ui: accounts: reduce "warping", select alphabetically preceding account
..when selected account disappears, eg when toggling zero accounts.
This commit is contained in:
parent
1d5f3a44d5
commit
50efcfe359
@ -24,6 +24,7 @@ import Data.Time.Calendar (Day)
|
|||||||
import qualified Data.Vector as V
|
import qualified Data.Vector as V
|
||||||
import Graphics.Vty (Event(..),Key(..),Modifier(..))
|
import Graphics.Vty (Event(..),Key(..),Modifier(..))
|
||||||
import Lens.Micro.Platform
|
import Lens.Micro.Platform
|
||||||
|
import Safe
|
||||||
import System.Console.ANSI
|
import System.Console.ANSI
|
||||||
import System.FilePath (takeFileName)
|
import System.FilePath (takeFileName)
|
||||||
|
|
||||||
@ -56,17 +57,25 @@ asInit d reset ui@UIState{
|
|||||||
where
|
where
|
||||||
newitems = list AccountsList (V.fromList $ displayitems ++ blankitems) 1
|
newitems = list AccountsList (V.fromList $ displayitems ++ blankitems) 1
|
||||||
|
|
||||||
-- keep the selection near the last selected account
|
-- decide which account is selected:
|
||||||
-- (may need to move to the next leaf account when entering flat mode)
|
-- if reset is true, the first account;
|
||||||
|
-- otherwise, the previously selected account if possible;
|
||||||
|
-- otherwise, the first account with the same prefix (eg first leaf account when entering flat mode);
|
||||||
|
-- otherwise, the alphabetically preceding account.
|
||||||
newitems' = listMoveTo selidx newitems
|
newitems' = listMoveTo selidx newitems
|
||||||
where
|
where
|
||||||
selidx = case (reset, listSelectedElement $ _asList s) of
|
selidx = case (reset, listSelectedElement $ _asList s) of
|
||||||
(True, _) -> 0
|
(True, _) -> 0
|
||||||
(_, Nothing) -> 0
|
(_, Nothing) -> 0
|
||||||
(_, Just (_,AccountsScreenItem{asItemAccountName=a})) -> fromMaybe (fromMaybe 0 mprefixmatch) mexactmatch
|
(_, Just (_,AccountsScreenItem{asItemAccountName=a})) ->
|
||||||
where
|
headDef 0 $ catMaybes [
|
||||||
mexactmatch = findIndex ((a ==) . asItemAccountName) displayitems
|
findIndex (a ==) as
|
||||||
mprefixmatch = findIndex ((a `isAccountNamePrefixOf`) . asItemAccountName) displayitems
|
,findIndex (a `isAccountNamePrefixOf`) as
|
||||||
|
,Just $ max 0 (length (filter (< a) as) - 1)
|
||||||
|
]
|
||||||
|
where
|
||||||
|
as = map asItemAccountName displayitems
|
||||||
|
|
||||||
uopts' = uopts{cliopts_=copts{reportopts_=ropts'}}
|
uopts' = uopts{cliopts_=copts{reportopts_=ropts'}}
|
||||||
ropts' = ropts{accountlistmode_=if flat_ ropts then ALFlat else ALTree}
|
ropts' = ropts{accountlistmode_=if flat_ ropts then ALFlat else ALTree}
|
||||||
|
|
||||||
|
|||||||
@ -102,12 +102,12 @@ rsInit d reset ui@UIState{aopts=UIOpts{cliopts_=CliOpts{reportopts_=ropts}}, ajo
|
|||||||
-- build the List
|
-- build the List
|
||||||
newitems = list RegisterList (V.fromList $ displayitems ++ blankitems) 1
|
newitems = list RegisterList (V.fromList $ displayitems ++ blankitems) 1
|
||||||
|
|
||||||
-- decide which transaction is selected.
|
-- decide which transaction is selected:
|
||||||
-- if reset is true, select the last (latest) transaction;
|
-- if reset is true, the last (latest) transaction;
|
||||||
-- otherwise, select the previously selected transaction if possible;
|
-- otherwise, the previously selected transaction if possible;
|
||||||
-- otherwise, select the transaction nearest in date to it;
|
-- otherwise, the transaction nearest in date to it;
|
||||||
-- or if there's several with the same date, the nearest in journal order;
|
-- or if there's several with the same date, the nearest in journal order;
|
||||||
-- otherwise, select the last (latest) transaction.
|
-- otherwise, the last (latest) transaction.
|
||||||
newitems' = listMoveTo newselidx newitems
|
newitems' = listMoveTo newselidx newitems
|
||||||
where
|
where
|
||||||
newselidx =
|
newselidx =
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user