mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-05-19 11:30:22 -07:00
X.Prompt: correctly update history
So far, when `alwaysHighlight' was enabled and the user selected an item while not having completely written it out in the prompt, the input string and not the eventual completion string would be entered into the prompt history, which is obviously not the desired behaviour. This can cause the history to clutter up with all these abbreviations, making subsequent invocations of the prompt tedious to work with. For example, an input of "xm" would narrow to both "xmonad" and "xmobar", but thanks to `alwaysHighlight' "xmobar" was selected. If the user now pressed enter, the prompt would correctly return "xmobar" as the string to act upon, but "xm" would be entered into the prompt history!
This commit is contained in:
parent
d0813f0b3a
commit
404b3f59b4
@ -402,6 +402,15 @@ highlightedItem st' completions = case complWinDim st' of
|
||||
[] -> Nothing
|
||||
_ -> Just $ complMatrix !! col_index !! row_index
|
||||
|
||||
-- | Return the selected completion, i.e. the 'String' we actually act
|
||||
-- upon after the user confirmed their selection (by pressing @Enter@).
|
||||
selectedCompletion :: XPState -> String
|
||||
selectedCompletion st
|
||||
-- If 'alwaysHighlight' is used, look at the currently selected item (if any)
|
||||
| alwaysHighlight (config st) = fromMaybe (command st) $ highlightedCompl st
|
||||
-- Otherwise, look at what the user actually wrote so far
|
||||
| otherwise = command st
|
||||
|
||||
-- this would be much easier with functional references
|
||||
command :: XPState -> String
|
||||
command = W.focus . commandHistory
|
||||
@ -483,16 +492,7 @@ mkXPromptWithReturn :: XPrompt p => p -> XPConfig -> ComplFunction -> (String ->
|
||||
mkXPromptWithReturn t conf compl action = do
|
||||
st' <- mkXPromptImplementation (showXPrompt t) conf (XPSingleMode compl (XPT t))
|
||||
if successful st'
|
||||
then do
|
||||
let selectedCompletion =
|
||||
case alwaysHighlight (config st') of
|
||||
-- When alwaysHighlight is True, autocompletion is
|
||||
-- handled with indexes.
|
||||
False -> command st'
|
||||
-- When it is false, it is handled depending on the
|
||||
-- prompt buffer's value.
|
||||
True -> fromMaybe (command st') $ highlightedCompl st'
|
||||
Just <$> action selectedCompletion
|
||||
then Just <$> action (selectedCompletion st')
|
||||
else return Nothing
|
||||
|
||||
-- | Creates a prompt given:
|
||||
@ -570,7 +570,7 @@ mkXPromptImplementation historyKey conf om = do
|
||||
-- We need to apply historyFilter before as well, since
|
||||
-- otherwise the filter would not be applied if there is no
|
||||
-- history
|
||||
(prune $ historyFilter conf [command st'])
|
||||
(prune $ historyFilter conf [selectedCompletion st'])
|
||||
hist
|
||||
return st'
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user