X.Prompt: Factor out how to accept the current selection

This commit is contained in:
Tony Zorman 2023-03-29 08:22:26 +02:00
parent 635711e994
commit fb63987ac8

View File

@ -715,7 +715,7 @@ handleInputMain keymask (keysym,keystr) = do
updateWindows
updateHighlightedCompl
complete <- tryAutoComplete
when complete $ setSuccess True >> setDone True
when complete acceptSelection
-- There are two options to store the completion list during the main loop:
-- * Use the State monad, with 'Nothing' as the initial state.
@ -968,8 +968,8 @@ defaultXPKeymap' p = M.fromList $
, (xK_bracketleft, quit)
] ++
map (first $ (,) 0)
[ (xK_Return, setSuccess True >> setDone True)
, (xK_KP_Enter, setSuccess True >> setDone True)
[ (xK_Return, acceptSelection)
, (xK_KP_Enter, acceptSelection)
, (xK_BackSpace, deleteString Prev)
, (xK_Delete, deleteString Next)
, (xK_Left, moveCursor Prev)
@ -1021,8 +1021,8 @@ emacsLikeXPKeymap' p = M.fromList $
]
++
map (first $ (,) 0) -- <key>
[ (xK_Return, setSuccess True >> setDone True)
, (xK_KP_Enter, setSuccess True >> setDone True)
[ (xK_Return, acceptSelection)
, (xK_KP_Enter, acceptSelection)
, (xK_BackSpace, deleteString Prev)
, (xK_Delete, deleteString Next)
, (xK_Left, moveCursor Prev)
@ -1059,8 +1059,8 @@ vimLikeXPKeymap' :: (XPColor -> XPColor)
-> M.Map (KeyMask,KeySym) (XP ())
vimLikeXPKeymap' fromColor promptF pasteFilter notWord = M.fromList $
map (first $ (,) 0)
[ (xK_Return, setSuccess True >> setDone True)
, (xK_KP_Enter, setSuccess True >> setDone True)
[ (xK_Return, acceptSelection)
, (xK_KP_Enter, acceptSelection)
, (xK_BackSpace, deleteString Prev)
, (xK_Delete, deleteString Next)
, (xK_Left, moveCursor Prev)
@ -1166,6 +1166,10 @@ setModeDone b = modify $ \s -> s { modeDone = b }
-- KeyPress and State
-- | Accept the current selection and exit.
acceptSelection :: StateT XPState IO ()
acceptSelection = setSuccess True >> setDone True
-- | Quit.
quit :: XP ()
quit = flushString >> setSuccess False >> setDone True >> setModeDone True