From 896bfb14fa05cf07bb57216fdccd678e027bc4f9 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Fri, 9 Apr 2021 11:10:57 +0200 Subject: Update editor modules --- editor/tooltip.ml | 30 ++---------------------------- 1 file changed, 2 insertions(+), 28 deletions(-) (limited to 'editor/tooltip.ml') diff --git a/editor/tooltip.ml b/editor/tooltip.ml index adb37f1..e172cbf 100755 --- a/editor/tooltip.ml +++ b/editor/tooltip.ml @@ -7,39 +7,13 @@ module PM = Prosemirror (** https://prosemirror.net/examples/tooltip/ *) -(** Set the element position just above the selection *) -let set_position - : start:int -> end':int -> PM.View.editor_view Js.t -> El.t -> unit - = fun ~start ~end' view el -> - El.set_inline_style El.Style.display (Jstr.v "") el; - - (* These are in screen coordinates *) - let start = view##coordsAtPos start Js.null - and end' = view##coordsAtPos end' Js.null in - let offsetParent = Jv.(Id.of_jv @@ get (Jv.Id.to_jv el) "offsetParent") in - - (* The box in which the tooltip is positioned, to use as base *) - let box = Jv.(Id.of_jv @@ call (Jv.Id.to_jv offsetParent) "getBoundingClientRect" [||]) in - let box_left = Jv.(Id.of_jv @@ get (Jv.Id.to_jv box) "left") in - let box_bottom = Jv.(Id.of_jv @@ get (Jv.Id.to_jv box) "bottom") in - - (* Find a center-ish x position from the selection endpoints (when - crossing lines, end may be more to the left) *) - let left = (start##.left +. end'##.left) /. 2. in - - El.set_inline_style (Jstr.v "left") - Jstr.( (of_float ( left -. box_left )) + (v "px") ) - el; - El.set_inline_style (Jstr.v "bottom") - Jstr.( (of_float ( box_bottom -. start##.top )) + (v "px") ) - el let boldtip : PM.View.editor_view Js.t -> < .. > Js.t = fun view -> (* Create the element which will be displayed over the editor *) let tooltip = El.div [] - ~at:At.([ class' (Jstr.v "tooltip") + ~at:At.([ class' (Jstr.v "popin") ]) in El.set_inline_style El.Style.display (Jstr.v "none") tooltip; @@ -90,7 +64,7 @@ let boldtip (* The mark is present, add in the content *) let start = view##.state##.selection##.from and end' = view##.state##.selection##._to in - set_position ~start ~end' view tooltip; + Popin.set_position ~start ~end' view tooltip; El.set_prop (El.Prop.jstr (Jstr.v "textContent")) (Jstr.concat marks ~sep:(Jstr.v ", ")) -- cgit v1.2.3