From d3e499ee59fc5a9c2f70d51e6f57f7639214b442 Mon Sep 17 00:00:00 2001 From: Andrea Rossato Date: Sun, 13 Jan 2008 13:35:29 +0100 Subject: 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 --- XMonad/Prompt.hs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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 -- cgit v1.2.3