on develop help sign in
Handle tab characters in textInput
commit8ff57f5208c29596c94570b5b976f6f997ed4304 authorAli Abrar <aliabrar@gmail.com> dateMon 5 Nov 2018, 01:31 (8 years ago) parente4d9d8d
2 files changed+6
src/Data/Text/Zipper.hs+5 src/Reflex/Vty/Widget/Input/Text.hs+1
src/Data/Text/Zipper.hs+5
@@ -135,6 +135,11 @@ deleteLeftWord (TextZipper lb b a la) =
135135 (l:ls) -> deleteLeftWord $ TextZipper ls l a la
136136 else TextZipper lb (T.dropWhileEnd (not . isSpace) b') a la
137137
138+-- | Insert up to n spaces to get to the next logical column that is a multiple of n
139+tab :: Int -> TextZipper -> TextZipper
140+tab n z@(TextZipper _ b _ _) =
141+ insert (T.replicate (fromEnum $ n - (T.length b `mod` n)) " ") z
142+
138143-- | The plain text contents of the zipper
139144value :: TextZipper -> Text
140145value (TextZipper lb b a la) = T.intercalate "\n" $ mconcat [ reverse lb
src/Reflex/Vty/Widget/Input/Text.hs+1
@@ -98,6 +98,7 @@ spanToImage (Span attrs t) = V.text' attrs t
9898updateTextZipper :: V.Event -> TextZipper -> TextZipper
9999updateTextZipper ev = case ev of
100100 -- Regular characters
101+ V.EvKey (V.KChar '\t') [] -> tab 4
101102 V.EvKey (V.KChar k) [] -> insertChar k
102103 -- Deletion buttons
103104 V.EvKey V.KBS [] -> deleteLeft