@@ -167,12 +167,14 @@ export interface EventOptions<C extends object> {
167167 resolveContext : ContextResolver < C >
168168 adjustPosition ?: PositionAdjuster < C >
169169 dom : DOMFunctions
170+ codeViewId : symbol
170171}
171172
172173/**
173174 * @template C Extra context for the hovered token.
174175 */
175- export interface HoverifyOptions < C extends object > extends EventOptions < C > {
176+ export interface HoverifyOptions < C extends object >
177+ extends Pick < EventOptions < C > , Exclude < keyof EventOptions < C > , 'codeViewId' > > {
176178 positionEvents : Subscribable < PositionEvent >
177179
178180 /**
@@ -242,6 +244,11 @@ interface InternalHoverifierState<C extends object, D, A> {
242244 * Actions to display as buttons or links in the hover.
243245 */
244246 actionsOrError ?: typeof LOADING | A [ ] | null | ErrorLike
247+
248+ /**
249+ * A value that identifies the code view that triggered the current hover overlay.
250+ */
251+ codeViewId ?: symbol
245252}
246253
247254/**
@@ -559,6 +566,7 @@ export function createHoverifier<C extends object, D, A>({
559566 target : HTMLElement
560567 adjustPosition ?: PositionAdjuster < C >
561568 codeView : HTMLElement
569+ codeViewId : symbol
562570 hoverOrError ?: typeof LOADING | ( HoverAttachment & D ) | ErrorLike | null
563571 position ?: HoveredToken & C
564572 part ?: DiffPart
@@ -633,7 +641,7 @@ export function createHoverifier<C extends object, D, A>({
633641 return adjustingPosition . pipe ( map ( position => ( { position, hoverOrError, ...rest } ) ) )
634642 } )
635643 )
636- . subscribe ( ( { hoverOrError, position, codeView, dom, part } ) => {
644+ . subscribe ( ( { hoverOrError, position, codeView, codeViewId , dom, part } ) => {
637645 // Update the highlighted token if the hover result is successful. If the hover result specifies a
638646 // range, use that; otherwise use the hover position (which will be expanded into a full token in
639647 // getTokenAtPosition).
@@ -657,6 +665,7 @@ export function createHoverifier<C extends object, D, A>({
657665 }
658666
659667 container . update ( {
668+ codeViewId,
660669 hoverOrError,
661670 highlightedRange,
662671 // Reset the hover position, it's gonna be repositioned after the hover was rendered
@@ -741,20 +750,24 @@ export function createHoverifier<C extends object, D, A>({
741750 } )
742751 )
743752
753+ const resetHover = ( ) => {
754+ container . update ( {
755+ hoverOverlayIsFixed : false ,
756+ hoverOverlayPosition : undefined ,
757+ hoverOrError : undefined ,
758+ hoveredToken : undefined ,
759+ actionsOrError : undefined ,
760+ } )
761+ }
762+
744763 // When the close button is clicked, unpin, hide and reset the hover
745764 subscription . add (
746765 merge (
747766 closeButtonClicks ,
748767 fromEvent < KeyboardEvent > ( window , 'keydown' ) . pipe ( filter ( event => event . key === Key . Escape ) )
749768 ) . subscribe ( event => {
750769 event . preventDefault ( )
751- container . update ( {
752- hoverOverlayIsFixed : false ,
753- hoverOverlayPosition : undefined ,
754- hoverOrError : undefined ,
755- hoveredToken : undefined ,
756- actionsOrError : undefined ,
757- } )
770+ resetHover ( )
758771 } )
759772 )
760773
@@ -792,19 +805,24 @@ export function createHoverifier<C extends object, D, A>({
792805 distinctUntilChanged ( ( a , b ) => isEqual ( a , b ) )
793806 ) ,
794807 hoverify ( { positionEvents, positionJumps = EMPTY , ...eventOptions } : HoverifyOptions < C > ) : Subscription {
808+ const codeViewId = Symbol ( 'CodeView' )
795809 const subscription = new Subscription ( )
796- const eventWithOptions = map ( ( event : PositionEvent ) => ( { ...event , ...eventOptions } ) )
797810 // Broadcast all events from this code view
798811 subscription . add (
799812 from ( positionEvents )
800- . pipe ( eventWithOptions )
813+ . pipe ( map ( event => ( { ... event , ... eventOptions , codeViewId } ) ) )
801814 . subscribe ( allPositionsFromEvents )
802815 )
803816 subscription . add (
804817 from ( positionJumps )
805- . pipe ( map ( jump => ( { ...jump , ...eventOptions } ) ) )
818+ . pipe ( map ( jump => ( { ...jump , ...eventOptions , codeViewId } ) ) )
806819 . subscribe ( allPositionJumps )
807820 )
821+ subscription . add ( ( ) => {
822+ if ( container . values . codeViewId === codeViewId ) {
823+ resetHover ( )
824+ }
825+ } )
808826 return subscription
809827 } ,
810828 unsubscribe ( ) : void {
0 commit comments