X.Prompt: Simplify nextComplIndex

This commit is contained in:
slotThe 2021-04-15 07:49:28 +02:00
parent 6036151ca7
commit a49c4066b9

View File

@ -905,23 +905,18 @@ handleInputBuffer f keymask (keysym,keystr) event =
bufferOne :: String -> String -> (Bool,Bool) bufferOne :: String -> String -> (Bool,Bool)
bufferOne xs x = (null xs && null x,True) bufferOne xs x = (null xs && null x,True)
--Receives an state of the prompt, the size of the autocompletion list and returns the column,row -- | Return the @(column, row)@ of the next highlight, or @(0, 0)@ if
--which should be highlighted next -- there is no prompt window or a wrap-around occurs.
nextComplIndex :: XPState -> (Int,Int) nextComplIndex :: XPState -> (Int, Int)
nextComplIndex st = case complWinDim st of nextComplIndex st = case complWinDim st of
Nothing -> (0,0) --no window dims (just destroyed or not created) Nothing -> (0, 0) -- no window dimensions (just destroyed or not created)
Just ComplWindowDim{ cwCols, cwRows } -> let Just ComplWindowDim{ cwCols, cwRows } ->
(ncols,nrows) = (length cwCols, length cwRows) let (currentcol, currentrow) = complIndex st
(currentcol,currentrow) = complIndex st (colm, rowm) =
in if currentcol + 1 >= ncols then --hlight is in the last column ((currentcol + 1) `mod` length cwCols, (currentrow + 1) `mod` length cwRows)
if currentrow + 1 < nrows then --hlight is still not at the last row in if rowm == currentrow + 1
(currentcol, currentrow + 1) then (currentcol, currentrow + 1) -- We are not in the last row, so go down
else else (colm, rowm) -- otherwise advance to the next column
(0,0)
else if currentrow + 1 < nrows then --hlight not at the last row
(currentcol, currentrow + 1)
else
(currentcol + 1, 0)
tryAutoComplete :: XP Bool tryAutoComplete :: XP Bool
tryAutoComplete = do tryAutoComplete = do