baseEvents ::
    _ =>
    ExprInfo o ->
    GuiM env i o (EventMap (o GuiState.Update))
baseEvents exprInfo =
    mconcat
    [ detachEventMap ?? exprInfo
    , extractEventMap ?? actions
    , mkReplaceParent
    , actions ^. Sugar.delete & replaceEventMap
    , actions ^. Sugar.mApply & foldMap applyEventMap
    , makeLiteralEventMap ?? actions ^. Sugar.setToLiteral
    ]
    where
        actions = exprInfoActions exprInfo
        mkReplaceParent =
            Lens.view id
            <&> \env ->
            let replaceKeys = env ^. has . Config.replaceParentKeys in
            actions ^. Sugar.mReplaceParent
            & foldMap
                (E.keysEventMapMovesCursor replaceKeys
                    (E.toDoc env
                        [has . MomentuTexts.edit, has . Texts.replaceParent])
                . fmap WidgetIds.fromEntityId)

-- | Create the hole search term for new apply operators,
-- given the extra search term chars from another hole.
baseEvents ::
    _ =>
    ExprInfo o ->
    GuiM env i o (EventMap (o GuiState.Update))
baseEvents exprInfo =
    mconcat
    [ detachEventMap ?? exprInfo
    , extractEventMap ?? actions
    , mkReplaceParent
    , actions ^. Sugar.delete & replaceEventMap
    , actions ^. Sugar.mApply & foldMap applyEventMap
    , makeLiteralEventMap ?? actions ^. Sugar.setToLiteral
    ]
    where
        actions = exprInfoActions exprInfo
        mkReplaceParent =
            Lens.view id
            <&> \env ->
            let replaceKeys = env ^. has . Config.replaceParentKeys in
            actions ^. Sugar.mReplaceParent
            & foldMap
                (E.keysEventMapMovesCursor replaceKeys
                    (E.toDoc env
                        [has . MomentuTexts.edit, has . Texts.replaceParent])
                . fmap WidgetIds.fromEntityId)

-- | Create the hole search term for new apply operators,
-- given the extra search term chars from another hole.
baseEvents exprInfo =
    mconcat
    [ detachEventMap ?? exprInfo
    , extractEventMap ?? actions
    , mkReplaceParent
    , actions ^. Sugar.delete & replaceEventMap
    , actions ^. Sugar.mApply & foldMap applyEventMap
    , makeLiteralEventMap ?? actions ^. Sugar.setToLiteral
    ]
    where
        actions = exprInfoActions exprInfo
        mkReplaceParent =
            Lens.view id
            <&> \env ->
            let replaceKeys = env ^. has . Config.replaceParentKeys in
            actions ^. Sugar.mReplaceParent
            & foldMap
                (E.keysEventMapMovesCursor replaceKeys
                    (E.toDoc env
                        [has . MomentuTexts.edit, has . Texts.replaceParent])
                . fmap WidgetIds.fromEntityId)

-- | Create the hole search term for new apply operators,
-- given the extra search term chars from another hole.