mirror of
https://github.com/chrisdone/duet.git
synced 2025-01-08 06:53:22 +03:00
Add close parens
This commit is contained in:
parent
0491980569
commit
27b63e51ae
@ -79,7 +79,7 @@ makeState ident expr =
|
||||
instance Flux.StoreData State where
|
||||
type StoreAction State = Action
|
||||
transform action state = do
|
||||
-- putStrLn ("Action: " ++ show action)
|
||||
putStrLn ("Action: " ++ show action)
|
||||
-- putStrLn ("State before: " ++ show state)
|
||||
state' <- execStateT (interpretAction action) state
|
||||
-- putStrLn ("State after: " ++ show state')
|
||||
|
@ -333,23 +333,8 @@ interpretKeyPress k = do
|
||||
43 -> interpretOperator '+' (stateCursor s) (stateAST s)
|
||||
45 -> interpretOperator '-' (stateCursor s) (stateAST s)
|
||||
47 -> interpretOperator '/' (stateCursor s) (stateAST s)
|
||||
40 -> do
|
||||
ast <-
|
||||
transformExpression
|
||||
(cursorUUID (stateCursor s))
|
||||
(const
|
||||
(\e ->
|
||||
case e of
|
||||
(ConstantExpression _ (Identifier "_")) -> do
|
||||
l' <- liftIO newParens
|
||||
case l' of
|
||||
ParensExpression _ e' ->
|
||||
focusNode (expressionLabel e')
|
||||
_ -> pure ()
|
||||
pure l'
|
||||
_ -> pure e))
|
||||
(stateAST s)
|
||||
modify (\s' -> s' {stateAST = ast})
|
||||
40 -> interpretOpenParen s
|
||||
41 -> interpretCloseParen s
|
||||
_ ->
|
||||
case stateCursor s of
|
||||
cursor ->
|
||||
@ -360,6 +345,34 @@ interpretKeyPress k = do
|
||||
where
|
||||
isSpaceCode = (== 32)
|
||||
|
||||
interpretCloseParen :: Monad m => State -> StateT State m ()
|
||||
interpretCloseParen s =
|
||||
case findNodeParent (cursorUUID (stateCursor s)) (stateAST s) of
|
||||
Nothing -> pure ()
|
||||
Just p ->
|
||||
case findNodeParent (nodeUUID p) (stateAST s) of
|
||||
Just p'@(ExpressionNode (ParensExpression{})) -> focusNode (nodeLabel p')
|
||||
_ -> focusNode (nodeLabel p)
|
||||
|
||||
interpretOpenParen :: MonadIO m => State -> StateT State m ()
|
||||
interpretOpenParen s = do
|
||||
ast <-
|
||||
transformExpression
|
||||
(cursorUUID (stateCursor s))
|
||||
(const
|
||||
(\e ->
|
||||
case e of
|
||||
(ConstantExpression _ (Identifier "_")) -> do
|
||||
l' <- liftIO newParens
|
||||
case l' of
|
||||
ParensExpression _ e' ->
|
||||
focusNode (expressionLabel e')
|
||||
_ -> pure ()
|
||||
pure l'
|
||||
_ -> pure e))
|
||||
(stateAST s)
|
||||
modify (\s' -> s' {stateAST = ast})
|
||||
|
||||
interpretOperator :: Char -> Cursor -> Node -> StateT State IO ()
|
||||
interpretOperator c cursor ast = do
|
||||
(ast', mparent) <-
|
||||
|
Loading…
Reference in New Issue
Block a user