···5252 Jv.call editor_state "create" [| config |]
53535454 let doc t = Jv.get t "doc" |> Text.of_jv
5555+5656+ let set_doc t str =
5757+ let arg =
5858+ Jv.obj
5959+ [|
6060+ ("from", Jv.of_int 0);
6161+ ("to", Jv.of_int (Text.length (doc t)));
6262+ ("insert", Jv.of_jstr str);
6363+ |]
6464+ in
6565+ Jv.call t "update" [| Jv.obj [| ("changes", arg) |] |]
5566end
56675768(* Helper for function *)
···90101 type t = Jv.t
9110292103 let state t = State.of_jv @@ Jv.get t "state"
104104+ let doc_changed t = Jv.to_bool @@ Jv.get t "docChanged"
9310594106 include (Jv.Id : Jv.CONV with type t := t)
95107 end
···102114 Facet ((module F), F.of_jv jv)
103115104116 let line_wrapping () = Jv.get g "lineWrapping" |> Extension.of_jv
117117+118118+ let set_doc t (doc : Jstr.t) =
119119+ let upd = State.set_doc (state t) doc in
120120+ let _ = Jv.call t "update" [| Jv.of_jv_array [| upd |] |] in
121121+ ()
105122end
+2
src/editor.mli
···7474 type t
75757676 val state : t -> State.t
7777+ val doc_changed : t -> bool
77787879 include Jv.CONV with type t := t
7980 end
···8182 val dom : t -> Brr.El.t
8283 val update_listener : unit -> (Update.t -> unit, Jv.t) State.facet
8384 val line_wrapping : unit -> Extension.t
8585+ val set_doc : t -> Jstr.t -> unit
8486end