summaryrefslogtreecommitdiff
path: root/editor/tooltip.ml
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@chimrod.com>2021-04-09 11:10:57 +0200
committerSébastien Dailly <sebastien@dailly.me>2022-02-07 16:43:33 +0100
commit896bfb14fa05cf07bb57216fdccd678e027bc4f9 (patch)
tree61ab35449822b03b0b7e7bd93987c47eb29439fb /editor/tooltip.ml
parent7d83ee3912582d3435d5a7c5fe4cb8a21617425b (diff)
Update editor modules
Diffstat (limited to 'editor/tooltip.ml')
-rwxr-xr-xeditor/tooltip.ml30
1 files changed, 2 insertions, 28 deletions
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 ", "))