Clean up editor key handling

Now, newlines can be inserted via C-n.
This commit is contained in:
Joscha 2020-02-09 22:40:14 +00:00
parent 62874a6d3f
commit db1287aff3

View file

@ -114,20 +114,20 @@ onKeyWithoutEditor cs _ = continue cs
{- Editor actions -} {- Editor actions -}
editorQuitKeys :: [Vty.Key] updateEditor :: NodeEditor -> ClientState -> Vty.Event -> ClientM (Next ClientState)
editorQuitKeys = [Vty.KEsc] updateEditor ed cs ev = do
onKeyWithEditor
:: NodeEditor
-> ClientState
-> Vty.Event
-> EventM ResourceName (Next ClientState)
onKeyWithEditor _ cs (Vty.EvKey k _)
| k `elem` editorQuitKeys = continue cs{csEditor = Nothing}
onKeyWithEditor ed cs ev = do
newEd <- handleNodeEditorEvent ev ed newEd <- handleNodeEditorEvent ev ed
continue cs{csEditor = Just newEd} continue cs{csEditor = Just newEd}
onKeyWithEditor :: NodeEditor -> ClientState -> Vty.Event -> ClientM (Next ClientState)
-- Abort editing with Escape
onKeyWithEditor _ cs (Vty.EvKey Vty.KEsc _) = continue cs{csEditor = Nothing}
-- Insert a newline on C-n
onKeyWithEditor ed cs (Vty.EvKey (Vty.KChar 'n') m)
| Vty.MCtrl `elem` m = updateEditor ed cs $ Vty.EvKey Vty.KEnter []
-- Forward all other events as usual
onKeyWithEditor ed cs ev = updateEditor ed cs ev
{- Constructing the client app -} {- Constructing the client app -}
clientDraw :: ClientState -> [Widget ResourceName] clientDraw :: ClientState -> [Widget ResourceName]