mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-05-19 11:30:22 -07:00
Prompt: added moveWord to move the cursor to the word boundaries
The actions have been bound to ctrl+Left and Right
This commit is contained in:
parent
1125e9102e
commit
06b3767cae
@ -297,6 +297,8 @@ keyPressHandle mask (ks,_)
|
|||||||
| ks == xK_a -> startOfLine >> go
|
| ks == xK_a -> startOfLine >> go
|
||||||
| ks == xK_e -> endOfLine >> go
|
| ks == xK_e -> endOfLine >> go
|
||||||
| ks == xK_y -> pasteString >> go
|
| ks == xK_y -> pasteString >> go
|
||||||
|
| ks == xK_Right -> moveWord Next >> go
|
||||||
|
| ks == xK_Left -> moveWord Prev >> go
|
||||||
| ks == xK_Delete -> killWord Next >> go
|
| ks == xK_Delete -> killWord Next >> go
|
||||||
| ks == xK_BackSpace -> killWord Prev >> go
|
| ks == xK_BackSpace -> killWord Prev >> go
|
||||||
| ks == xK_g || ks == xK_c -> quit
|
| ks == xK_g || ks == xK_c -> quit
|
||||||
@ -396,6 +398,25 @@ moveCursor d =
|
|||||||
modify $ \s -> s { offset = o (offset s) (command s)}
|
modify $ \s -> s { offset = o (offset s) (command s)}
|
||||||
where o oo c = if d == Prev then max 0 (oo - 1) else min (length c) (oo + 1)
|
where o oo c = if d == Prev then max 0 (oo - 1) else min (length c) (oo + 1)
|
||||||
|
|
||||||
|
-- | move the cursor one word
|
||||||
|
moveWord :: Direction -> XP ()
|
||||||
|
moveWord d = do
|
||||||
|
c <- gets command
|
||||||
|
o <- gets offset
|
||||||
|
let (f,ss) = splitAt o c
|
||||||
|
lp = length . reverse . fst . break isSpace
|
||||||
|
ln = length . fst . break isSpace
|
||||||
|
prev s = case reverse s of
|
||||||
|
' ':x -> 1 + (lp x)
|
||||||
|
x -> lp x
|
||||||
|
next s = case s of
|
||||||
|
' ':x -> 1 + (ln x)
|
||||||
|
x -> ln x
|
||||||
|
newoff = case d of
|
||||||
|
Prev -> o - prev f
|
||||||
|
_ -> o + next ss
|
||||||
|
modify $ \s -> s { offset = newoff }
|
||||||
|
|
||||||
moveHistory :: Direction -> XP ()
|
moveHistory :: Direction -> XP ()
|
||||||
moveHistory d = do
|
moveHistory d = do
|
||||||
h <- getHistory
|
h <- getHistory
|
||||||
|
Loading…
x
Reference in New Issue
Block a user