Skip to content

Commit 44c398f

Browse files
committed
Act on multiple elements
1 parent 11c4dff commit 44c398f

File tree

4 files changed

+47
-12
lines changed

4 files changed

+47
-12
lines changed

src/engine/step/actions.ml

+21-12
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,24 @@ let set_at at v elem =
2121
Undoable.return ~undo res
2222

2323
module AttributeActions = struct
24+
let act_on_id action id =
25+
let id = Jstr.concat [ Jstr.v "#"; id ] in
26+
match Brr.El.find_first_by_selector id with
27+
| None -> Undoable.return ()
28+
| Some elem -> action elem
29+
2430
let act_on_elem class_ action elem =
2531
match Brr.El.at (Jstr.v class_) elem with
2632
| None -> Undoable.return ()
2733
| Some v when Jstr.equal Jstr.empty v -> action elem
28-
| Some v -> (
29-
let id = Jstr.concat [ Jstr.v "#"; v ] in
30-
match Brr.El.find_first_by_selector id with
31-
| None -> Undoable.return ()
32-
| Some elem -> action elem)
34+
| Some id -> act_on_id action id
35+
36+
let act_on_elems class_ action elem =
37+
match Brr.El.at (Jstr.v class_) elem with
38+
| None -> Undoable.return ()
39+
| Some v when Jstr.equal Jstr.empty v -> action elem
40+
| Some v ->
41+
Jstr.cuts ~sep:(Jstr.v " ") v |> Undoable.List.iter (act_on_id action)
3342

3443
let up window elem =
3544
act_on_elem "up-at-unpause" (Universe.Window.up window) elem
@@ -41,10 +50,10 @@ module AttributeActions = struct
4150
act_on_elem "center-at-unpause" (Universe.Window.center window) elem
4251

4352
let unstatic _window elem =
44-
act_on_elem "unstatic-at-unpause" (set_class "unstatic" true) elem
53+
act_on_elems "unstatic-at-unpause" (set_class "unstatic" true) elem
4554

4655
let static _window elem =
47-
act_on_elem "static-at-unpause" (set_class "unstatic" false) elem
56+
act_on_elems "static-at-unpause" (set_class "unstatic" false) elem
4857

4958
let focus window elem =
5059
let action elem =
@@ -63,16 +72,16 @@ module AttributeActions = struct
6372
act_on_elem "unfocus-at-unpause" action elem
6473

6574
let reveal _window elem =
66-
act_on_elem "reveal-at-unpause" (set_class "unrevealed" false) elem
75+
act_on_elems "reveal-at-unpause" (set_class "unrevealed" false) elem
6776

6877
let unreveal _window elem =
69-
act_on_elem "unreveal-at-unpause" (set_class "unrevealed" true) elem
78+
act_on_elems "unreveal-at-unpause" (set_class "unrevealed" true) elem
7079

7180
let emph _window elem =
72-
act_on_elem "emph-at-unpause" (set_class "emphasized" true) elem
81+
act_on_elems "emph-at-unpause" (set_class "emphasized" true) elem
7382

7483
let unemph _window elem =
75-
act_on_elem "unemph-at-unpause" (set_class "emphasized" false) elem
84+
act_on_elems "unemph-at-unpause" (set_class "emphasized" false) elem
7685

7786
let execute _window elem =
7887
let action elem =
@@ -106,7 +115,7 @@ module AttributeActions = struct
106115
in
107116
Undoable.return ~undo ()
108117
in
109-
act_on_elem "exec-at-unpause" action elem
118+
act_on_elems "exec-at-unpause" action elem
110119

111120
let do_ window elem =
112121
let do_ =

src/engine/undoable/undoable.ml

+11
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,14 @@ module Syntax = struct
1919
end
2020
2121
module Browser = Browser_
22+
23+
module List = struct
24+
open Syntax
25+
26+
let iter f l =
27+
List.fold_left
28+
(fun acc x ->
29+
let> () = acc in
30+
f x)
31+
(return ()) l
32+
end

src/engine/undoable/undoable.mli

+4
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ module Syntax : sig
1010
end
1111

1212
module Browser = Browser_
13+
14+
module List : sig
15+
val iter : ('a -> unit t) -> 'a list -> unit t
16+
end

test/engine/basic.t/new_engine.md

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
Salut !
22

3+
{#a .unstatic}
4+
a
5+
6+
{#b .unstatic}
7+
b
8+
9+
{#c .unstatic}
10+
c
11+
12+
{pause static-at-unpause="a b c"}
13+
314
{pause up}
415
One
516

0 commit comments

Comments
 (0)