mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-08-01 04:31:52 -07:00
Only modify the last word during tab completion
Fixes #164. It's not clear to me why these functions take in XPState as a param only to then produce some XP () values. It seems like they could just as well call `get`.
This commit is contained in:
@@ -337,6 +337,11 @@
|
|||||||
|
|
||||||
- Added `filterOutWs` for workspace filtering.
|
- Added `filterOutWs` for workspace filtering.
|
||||||
|
|
||||||
|
* `XMonad.Prompt
|
||||||
|
|
||||||
|
- Accommodate completion of multiple words even when `alwaysHighlight` is
|
||||||
|
enabled.
|
||||||
|
|
||||||
## 0.16
|
## 0.16
|
||||||
|
|
||||||
### Breaking Changes
|
### Breaking Changes
|
||||||
|
@@ -698,9 +698,8 @@ handleCompletion cs = do
|
|||||||
|
|
||||||
let updateWins l = redrawWindows l
|
let updateWins l = redrawWindows l
|
||||||
updateState l = case alwaysHlight of
|
updateState l = case alwaysHlight of
|
||||||
False -> simpleComplete l st
|
False -> simpleComplete l st
|
||||||
True | Just (command st) /= highlightedCompl st -> alwaysHighlightCurrent st
|
True -> hlComplete l st
|
||||||
| otherwise -> alwaysHighlightNext l st
|
|
||||||
|
|
||||||
case cs of
|
case cs of
|
||||||
[] -> updateWindows
|
[] -> updateWindows
|
||||||
@@ -720,33 +719,31 @@ handleCompletion cs = do
|
|||||||
, highlightedCompl = Just newCommand
|
, highlightedCompl = Just newCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
-- If alwaysHighlight is on, and this is the first use of the
|
|
||||||
-- completion key, update the buffer so that it contains the
|
|
||||||
-- current completion item.
|
|
||||||
alwaysHighlightCurrent :: XPState -> XP ()
|
|
||||||
alwaysHighlightCurrent st = do
|
|
||||||
let newCommand = fromMaybe (command st) $ highlightedItem st cs
|
|
||||||
modify $ \s -> setCommand newCommand $
|
|
||||||
setHighlightedCompl (Just newCommand) $
|
|
||||||
s { offset = length newCommand
|
|
||||||
}
|
|
||||||
|
|
||||||
-- If alwaysHighlight is on, and the user wants the next
|
-- If alwaysHighlight is on, and the user wants the next
|
||||||
-- completion, move to the next completion item and update the
|
-- completion, move to the next completion item and update the
|
||||||
-- buffer to reflect that.
|
-- buffer to reflect that.
|
||||||
--
|
--
|
||||||
--TODO: Scroll or paginate results
|
--TODO: Scroll or paginate results
|
||||||
alwaysHighlightNext :: [String] -> XPState -> XP ()
|
hlComplete :: [String] -> XPState -> XP ()
|
||||||
alwaysHighlightNext l st = do
|
hlComplete l st =
|
||||||
let complIndex' = nextComplIndex st (length l)
|
let newCommand = fromMaybe (command st) $ highlightedItem st l in
|
||||||
highlightedCompl' = highlightedItem st { complIndex = complIndex'} cs
|
if newCommand == (getLastWord . command $ st)
|
||||||
newCommand = fromMaybe (command st) $ highlightedCompl'
|
then do
|
||||||
modify $ \s -> setHighlightedCompl highlightedCompl' $
|
-- The word currently under the cursor is the same
|
||||||
setCommand newCommand $
|
-- as the current suggestion, so we should advance
|
||||||
s { complIndex = complIndex'
|
-- to the next completion and try again.
|
||||||
, offset = length newCommand
|
let complIndex' = nextComplIndex st (length l)
|
||||||
}
|
highlightedCompl' = highlightedItem st { complIndex = complIndex'} cs
|
||||||
|
hlComplete l $ st { complIndex = complIndex',
|
||||||
|
highlightedCompl = highlightedCompl'
|
||||||
|
}
|
||||||
|
else do
|
||||||
|
-- The word under the cursor differs from the
|
||||||
|
-- current suggestion, so replace it
|
||||||
|
put st
|
||||||
|
killWord Prev
|
||||||
|
insertString' newCommand
|
||||||
|
endOfLine
|
||||||
-- | Initiate a prompt sub-map event loop. Submaps are intended to provide
|
-- | Initiate a prompt sub-map event loop. Submaps are intended to provide
|
||||||
-- alternate keybindings. Accepts a default action and a mapping from key
|
-- alternate keybindings. Accepts a default action and a mapping from key
|
||||||
-- combinations to actions. If no entry matches, the default action is run.
|
-- combinations to actions. If no entry matches, the default action is run.
|
||||||
@@ -1189,10 +1186,15 @@ resetComplIndex st = if (alwaysHighlight $ config st) then st { complIndex = (0,
|
|||||||
|
|
||||||
-- | Insert a character at the cursor position
|
-- | Insert a character at the cursor position
|
||||||
insertString :: String -> XP ()
|
insertString :: String -> XP ()
|
||||||
insertString str =
|
insertString str = do
|
||||||
|
insertString' str
|
||||||
|
modify resetComplIndex
|
||||||
|
|
||||||
|
insertString' :: String -> XP ()
|
||||||
|
insertString' str =
|
||||||
modify $ \s -> let
|
modify $ \s -> let
|
||||||
cmd = (c (command s) (offset s))
|
cmd = (c (command s) (offset s))
|
||||||
st = resetComplIndex $ s { offset = o (offset s)}
|
st = s { offset = o (offset s)}
|
||||||
in setCommand cmd st
|
in setCommand cmd st
|
||||||
where o oo = oo + length str
|
where o oo = oo + length str
|
||||||
c oc oo | oo >= length oc = oc ++ str
|
c oc oo | oo >= length oc = oc ++ str
|
||||||
|
Reference in New Issue
Block a user