aboutsummaryrefslogtreecommitdiff
path: root/script.it/script_event/delete.ml
diff options
context:
space:
mode:
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