aboutsummaryrefslogtreecommitdiffstats
path: root/XMonad
diff options
context:
space:
mode:
authorAndrea Rossato <andrea.rossato@unibz.it>2008-01-13 13:35:29 +0100
committerAndrea Rossato <andrea.rossato@unibz.it>2008-01-13 13:35:29 +0100
commitd3e499ee59fc5a9c2f70d51e6f57f7639214b442 (patch)
treef0233e6b7a6070468fe6605be96e66d1453db196 /XMonad
parent866cc2c6a4a176b5001594e5b122505792ad7c72 (diff)
downloadXMonadContrib-d3e499ee59fc5a9c2f70d51e6f57f7639214b442.tar.gz
XMonadContrib-d3e499ee59fc5a9c2f70d51e6f57f7639214b442.tar.xz
XMonadContrib-d3e499ee59fc5a9c2f70d51e6f57f7639214b442.zip
Prompt: added moveWord to move the cursor to the word boundaries
The actions have been bound to ctrl+Left and Right darcs-hash:20080113123529-32816-9513798a80831d145fba8dceb4612b40765b080e.gz
Diffstat (limited to '')
-rw-r--r--XMonad/Prompt.hs21
1 files changed, 21 insertions, 0 deletions
diff --git a/XMonad/Prompt.hs b/XMonad/Prompt.hs
index b1fdba4..e48b8e1 100644
--- a/XMonad/Prompt.hs
+++ b/XMonad/Prompt.hs
@@ -297,6 +297,8 @@ keyPressHandle mask (ks,_)
| ks == xK_a -> startOfLine >> go
| ks == xK_e -> endOfLine >> 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_BackSpace -> killWord Prev >> go
| ks == xK_g || ks == xK_c -> quit
@@ -396,6 +398,25 @@ moveCursor d =
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)
+-- | 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 d = do
h <- getHistory