Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit ef6630d

Browse files
committed
Merge pull request #62 from jonsterling/SD-1588
Fix SD-1588 / merge selection into options in eval for radios, dropdowns
2 parents 088a48a + c2d8beb commit ef6630d

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/Text/Markdown/SlamDown/Eval.purs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,27 @@ eval fs = everywhereM b i
6161
quoteTextBox SD.TextBox Identity SD.TextBox (Compose M.Maybe SD.Expr)
6262
quoteTextBox = SD.transTextBox (runIdentity >>> SD.Literal >>> M.Just >>> Compose)
6363

64-
f (SD.RadioButtons sel opts) = SD.RadioButtons <$> evalExpr fs.value sel <*> evalExpr fs.list opts
64+
f (SD.RadioButtons sel opts) = do
65+
sel' <- evalExpr fs.value sel
66+
opts' <- evalExpr fs.list opts
67+
pure $ SD.RadioButtons sel' (mergeSelection sel' opts')
68+
6569
f (SD.CheckBoxes checkeds vals) = do
6670
vals' ← evalExpr fs.list vals
6771
checkeds' ← evalExpr (fs.list >=> \cs → pure $ map (_ `F.elem` cs) (getValues vals')) checkeds
6872
pure $ SD.CheckBoxes checkeds' vals'
69-
f (SD.DropDown sel opts) = SD.DropDown <$> T.traverse (evalExpr fs.value) sel <*> evalExpr fs.list opts
73+
74+
f (SD.DropDown msel opts) = do
75+
msel' ← T.traverse (evalExpr fs.value) msel
76+
opts' ← evalExpr fs.list opts
77+
pure $ SD.DropDown msel' $ M.maybe opts' (flip mergeSelection opts') msel'
78+
79+
mergeSelection SD.Expr a SD.Expr (L.List a) SD.Expr (L.List a)
80+
mergeSelection (SD.Literal x) (SD.Literal xs) =
81+
if F.elem x xs
82+
then SD.Literal xs
83+
else SD.Literal $ L.Cons x xs
84+
mergeSelection _ exs = exs
7085

7186
evalExpr e. (String m e) SD.Expr e m (SD.Expr e)
7287
evalExpr _ (SD.Literal a) = pure $ SD.Literal a
@@ -75,3 +90,4 @@ eval fs = everywhereM b i
7590
getValues e. SD.Expr (L.List e) L.List e
7691
getValues (SD.Literal vs) = vs
7792
getValues _ = L.Nil
93+

0 commit comments

Comments
 (0)