No recalc of length of list

This commit is contained in:
thepenguin 2023-10-18 14:50:45 +02:00
parent 787222d067
commit 2e351da399
No known key found for this signature in database
GPG Key ID: F258C8C10D060D5E

View File

@ -72,6 +72,7 @@ data AppS = AppS
, appCursor :: Int , appCursor :: Int
, appFocus :: Maybe FilePath , appFocus :: Maybe FilePath
, appSubFiles :: [(FilePath, Integer)] , appSubFiles :: [(FilePath, Integer)]
, appLenSub :: Int
, appMemo :: IORef (IOHashMap FilePath [(FilePath, Integer)]) , appMemo :: IORef (IOHashMap FilePath [(FilePath, Integer)])
, appRoot :: FilePath , appRoot :: FilePath
} }
@ -133,6 +134,7 @@ sizeDir s = do
appCursor = 0 appCursor = 0
, appFocus = map fst subFiles !? 0 , appFocus = map fst subFiles !? 0
, appSubFiles = subFiles , appSubFiles = subFiles
, appLenSub = length subFiles
} }
changeDir :: AppS -> IO AppS changeDir :: AppS -> IO AppS
@ -162,6 +164,7 @@ overDir s = do
, appCursor = 0 , appCursor = 0
, appFocus = pure a , appFocus = pure a
, appSubFiles = [] , appSubFiles = []
, appLenSub = 0
} }
scroll :: ScrollDirection -> AppS -> AppS scroll :: ScrollDirection -> AppS -> AppS
@ -174,7 +177,7 @@ scroll d s = s {
case d of case d of
SUp -> (-1) SUp -> (-1)
SDown -> 1 SDown -> 1
newCursor = clamp 0 (subtract 1 . length $ appSubFiles s) cursor newCursor = clamp 0 (subtract 1 $ appLenSub s) cursor
maybeNewPath = fst <$> appSubFiles s !? newCursor maybeNewPath = fst <$> appSubFiles s !? newCursor
eventHandler :: BrickEvent () e -> EventM () AppS () eventHandler :: BrickEvent () e -> EventM () AppS ()
@ -213,6 +216,7 @@ initialState f i =
, appSubFiles = [] , appSubFiles = []
, appMemo = i , appMemo = i
, appRoot = f , appRoot = f
, appLenSub = 0
} }
main :: IO () main :: IO ()