A fork of mtelver's day10 project
at main2 119 lines 4.0 kB view raw
1open Code_mirror 2 3module Tooltip_view : sig 4 (** Describes the way a tooltip is displayed. *) 5 6 type t 7 (** TooltypeView *) 8 9 include Jv.CONV with type t := t 10 11 val dom : t -> Brr.El.t 12 (** The DOM element to position over the editor. *) 13 14 type offset = { x : int; y : int } 15 type coords = { left : int; right : int; top : int; bottom : int } 16 17 val offset : t -> offset 18 19 val create : 20 dom:Brr.El.t -> 21 ?offset:offset -> 22 ?get_coords:(int -> coords) -> 23 ?overlap:bool -> 24 ?mount:(Editor.View.t -> unit) -> 25 ?update:(Editor.View.Update.t -> unit) -> 26 ?positioned:(unit -> unit) -> 27 unit -> 28 t 29 (** Creates a TooltipView: 30 31 @param dom The DOM element to position over the editor. 32 @param offset 33 Adjust the position of the tooltip relative to its anchor position. 34 @param get_coords 35 This method can be provided to make the tooltip view itself responsible 36 for finding its screen position. 37 @param overlap 38 By default, tooltips are moved when they overlap with other tooltips. 39 Set this to true to disable that behavior for this tooltip. 40 @param mount 41 Called after the tooltip is added to the DOM for the first time. 42 @param update Update the DOM element for a change in the view's state. 43 @param positioned Called when the tooltip has been (re)positioned. 44 45 {{:https://codemirror.net/6/docs/ref/#tooltip.TooltipView} See the 46 reference for additional information.} *) 47end 48 49(** Creates a Tooltip: 50 51 @param pos The document position at which to show the tooltip. 52 @param end 53 The end of the range annotated by this tooltip, if different from pos. 54 @param create 55 A constructor function that creates the tooltip's DOM representation. 56 @param above 57 Whether the tooltip should be shown above or below the target position. 58 @param strict_side 59 Whether the above option should be honored when there isn't enough space 60 on that side to show the tooltip inside the viewport. 61 @param arrow 62 When set to true, show a triangle connecting the tooltip element to 63 position pos. 64 65 {{:https://codemirror.net/6/docs/ref/#tooltip.Tooltip} See the reference for 66 additional information.} *) 67module Tooltip : sig 68 (** Describes a tooltip. Values of this type, when provided through the 69 show_tooltip facet, control the individual tooltips on the editor. *) 70 71 type t 72 (** Tooltip *) 73 74 include Jv.CONV with type t := t 75 76 val pos : t -> int 77 (** The document position at which to show the tooltip. *) 78 79 val end_ : t -> int option 80 (** The end of the range annotated by this tooltip, if different from pos. *) 81 82 val create : 83 pos:int -> 84 ?end_:int -> 85 create:(Editor.View.t -> Tooltip_view.t) -> 86 ?above:bool -> 87 ?strict_side:bool -> 88 ?arrow:bool -> 89 unit -> 90 t 91end 92 93type hover_config 94 95val hover_config : 96 ?hide_on_change:bool -> ?hover_time:int -> unit -> hover_config 97(** Options for hover tooltips: 98 99 @param hover_on_change 100 When enabled (this defaults to false), close the tooltip whenever the 101 document changes. 102 @param hover_time 103 Hover time after which the tooltip should appear, in milliseconds. 104 Defaults to 300ms. *) 105 106val hover_tooltip : 107 ?config:hover_config -> 108 (view:Editor.View.t -> pos:int -> side:int -> Tooltip.t option Fut.t) -> 109 Extension.t 110(** Enable a hover tooltip, which shows up when the pointer hovers over ranges 111 of text. The callback is called when the mouse hovers over the document 112 text. It should, if there is a tooltip associated with position pos return 113 the tooltip description (either directly or in a promise). The side argument 114 indicates on which side of the position the pointer is—it will be -1 if the 115 pointer is before the position, 1 if after the position. 116 117 Note that all hover tooltips are hosted within a single tooltip container 118 element. This allows multiple tooltips over the same range to be "merged" 119 together without overlapping. *)