on develop help sign in
Handle tab characters in textInput
8ff57f5Ali Abrar
src/Data/Text/Zipper.hs+5
@@ -135,6 +135,11 @@ deleteLeftWord (TextZipper lb b a la) =
135 (l:ls) -> deleteLeftWord $ TextZipper ls l a la
135 (l:ls) -> deleteLeftWord $ TextZipper ls l a la
136 else TextZipper lb (T.dropWhileEnd (not . isSpace) b') a la
136 else TextZipper lb (T.dropWhileEnd (not . isSpace) b') a la
137
137
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+
138-- | The plain text contents of the zipper
143-- | The plain text contents of the zipper
139value :: TextZipper -> Text
144value :: TextZipper -> Text
140value (TextZipper lb b a la) = T.intercalate "\n" $ mconcat [ reverse lb
145value (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
98updateTextZipper :: V.Event -> TextZipper -> TextZipper
98updateTextZipper :: V.Event -> TextZipper -> TextZipper
99updateTextZipper ev = case ev of
99updateTextZipper ev = case ev of
100 -- Regular characters
100 -- Regular characters
101+ V.EvKey (V.KChar '\t') [] -> tab 4
101 V.EvKey (V.KChar k) [] -> insertChar k
102 V.EvKey (V.KChar k) [] -> insertChar k
102 -- Deletion buttons
103 -- Deletion buttons
103 V.EvKey V.KBS [] -> deleteLeft
104 V.EvKey V.KBS [] -> deleteLeft