summaryrefslogtreecommitdiff
path: root/script.it/script_event/delete.ml
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@chimrod.com>2021-05-24 22:56:16 +0200
committerSébastien Dailly <sebastien@dailly.me>2022-02-07 16:22:43 +0100
commit90f1f73f08b2d9231b2ee029b9e39dd570e36f36 (patch)
tree49c7828d2a549a3278ba5c54ca9b1f500c860951 /script.it/script_event/delete.ml
parent05008c81a9652472a454f47940a6d8aa9a228538 (diff)
Update
Diffstat (limited to 'script.it/script_event/delete.ml')
-rwxr-xr-xscript.it/script_event/delete.ml31
1 files changed, 31 insertions, 0 deletions
diff --git a/script.it/script_event/delete.ml b/script.it/script_event/delete.ml
new file mode 100755
index 0000000..edd5d23
--- /dev/null
+++ b/script.it/script_event/delete.ml
@@ -0,0 +1,31 @@
+(** Delete the selected element *)
+
+open StdLabels
+module State = Script_state.State
+module Selection = Script_state.Selection
+
+type t = { worker : Brr_webworkers.Worker.t }
+
+(* Click anywhere while in Out mode, we switch in edition *)
+let apply { worker } state =
+ match state.State.mode with
+ | Selection (Path id) ->
+ let paths = List.filter
+ state.State.paths
+ ~f:(fun p ->
+ p.Outline.id != id
+ ) in
+ { state with paths ; mode = Out}
+
+ | Selection (Point (id, point)) ->
+ List.iter
+ state.State.paths
+ ~f:(fun p ->
+ let id' = p.Outline.id in
+ match id' = id with
+ | false -> ()
+ | true -> State.post worker (`DeletePoint (point, p))
+ );
+ { state with mode = Selection (Path id) }
+
+ | _ -> state