From 00993d46fa419f478dbc7803c97f8149eb4dd6dc Mon Sep 17 00:00:00 2001 From: Tony Zorman Date: Sat, 16 Dec 2023 14:42:30 +0100 Subject: [PATCH] X.Prompt: Execute keypress when it has an action associated to it It might be that the keypress does not have a valid stroke associated to it, but is still bound to an action (e.g., xK_Left an friends). In this case, we still want to execute it. Closes: https://github.com/xmonad/xmonad-contrib/issues/845 --- XMonad/Prompt.hs | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/XMonad/Prompt.hs b/XMonad/Prompt.hs index 2397ace70f..a403c59982 100644 --- a/XMonad/Prompt.hs +++ b/XMonad/Prompt.hs @@ -708,25 +708,28 @@ handleMain stroke@(keysym, keystr) = \case getCurrentCompletions >>= handleCompletionMain Next | (keymask, keysym) == prevCompKey -> getCurrentCompletions >>= handleCompletionMain Prev - | otherwise -> unless (isModifier stroke) $ do - setCurrentCompletions Nothing - if keysym == modeKey - then modify setNextMode >> updateWindows - else handleInput keymask + | otherwise -> do + keymap <- gets (promptKeymap . config) + let mbAction = M.lookup (keymask, keysym) keymap + -- Either run when we can insert a valid character, or the + -- pressed key has an action associated to it. + unless (isModifier stroke && isNothing mbAction) $ do + setCurrentCompletions Nothing + if keysym == modeKey + then modify setNextMode >> updateWindows + else handleInput keymask mbAction event -> handleOther stroke event where -- Prompt input handler for the main loop. - handleInput :: KeyMask -> XP () - handleInput keymask = do - keymap <- gets (promptKeymap . config) - case M.lookup (keymask,keysym) keymap of - Just action -> action >> updateWindows - Nothing -> when (keymask .&. controlMask == 0) $ do - insertString $ utf8Decode keystr - updateWindows - updateHighlightedCompl - complete <- tryAutoComplete - when complete acceptSelection + handleInput :: KeyMask -> Maybe (XP ()) -> XP () + handleInput keymask = \case + Just action -> action >> updateWindows + Nothing -> when (keymask .&. controlMask == 0) $ do + insertString $ utf8Decode keystr + updateWindows + updateHighlightedCompl + complete <- tryAutoComplete + 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.