on develop help sign in
Make tab width configurable
commit2f08cc7fb72a4429c60d046e3af288b93dfa67ad authorAli Abrar <aliabrar@gmail.com> dateMon 5 Nov 2018, 01:32 (8 years ago) parent8ff57f5
1 file changed+6−5
src/Reflex/Vty/Widget/Input/Text.hs+6−5
src/Reflex/Vty/Widget/Input/Text.hs+6−5
@@ -25,10 +25,11 @@ import Reflex.Vty.Widget
2525data TextInputConfig t = TextInputConfig
2626 { _textInputConfig_initialValue :: TextZipper
2727 , _textInputConfig_modify :: Event t (TextZipper -> TextZipper)
28+ , _textInputConfig_tabWidth :: Int
2829 }
2930
3031instance Reflex t => Default (TextInputConfig t) where
31− def = TextInputConfig empty never
32+ def = TextInputConfig empty never 4
3233
3334-- | A widget that allows text input
3435textInput
@@ -39,7 +40,7 @@ textInput cfg = do
3940 i <- input
4041 f <- focus
4142 rec v <- foldDyn ($) (_textInputConfig_initialValue cfg) $ mergeWith (.)
42− [ updateTextZipper <$> i
43+ [ updateTextZipper (_textInputConfig_tabWidth cfg) <$> i
4344 , _textInputConfig_modify cfg
4445 , let displayInfo = (,) <$> rows <*> scrollTop
4546 in ffor (attach (current displayInfo) click) $ \((dl, st), MouseDown _ (mx, my) _) ->
@@ -95,10 +96,10 @@ spanToImage :: Span V.Attr -> V.Image
9596spanToImage (Span attrs t) = V.text' attrs t
9697
9798-- | Default vty event handler for text inputs
98−updateTextZipper :: V.Event -> TextZipper -> TextZipper
99−updateTextZipper ev = case ev of
99+updateTextZipper :: Int -> V.Event -> TextZipper -> TextZipper
100+updateTextZipper tabWidth ev = case ev of
100101 -- Regular characters
101− V.EvKey (V.KChar '\t') [] -> tab 4
102+ V.EvKey (V.KChar '\t') [] -> tab tabWidth
102103 V.EvKey (V.KChar k) [] -> insertChar k
103104 -- Deletion buttons
104105 V.EvKey V.KBS [] -> deleteLeft