@@ -10,7 +10,6 @@ import {
1010 share ,
1111 switchMap ,
1212 takeUntil ,
13- tap ,
1413 withLatestFrom ,
1514} from 'rxjs/operators'
1615import { Key } from 'ts-key-enum'
@@ -254,18 +253,18 @@ export const createHoverifier = ({
254253 ) : event is MouseEventTrigger & { eventType : T } => event . eventType === type
255254 const allCodeMouseMoves = allPositionsFromEvents . pipe ( filter ( isEventType ( 'mousemove' ) ) )
256255 const allCodeMouseOvers = allPositionsFromEvents . pipe ( filter ( isEventType ( 'mouseover' ) ) )
257- const allCodeClicks = allPositionsFromEvents . pipe (
258- filter ( isEventType ( 'click' ) ) ,
259- // Stop propagation of the click events we handle,
260- // so that our window click listener can safely close the overlay
261- // and not worry about bubbling events
262- tap ( ( { event } ) => event . stopPropagation ( ) )
263- )
256+ const allCodeClicks = allPositionsFromEvents . pipe ( filter ( isEventType ( 'click' ) ) )
264257
265258 const allPositionJumps = new Subject < PositionJump & EventOptions > ( )
266259
267260 const subscription = new Subscription ( )
268261
262+ /**
263+ * click events on the code element, ignoring click events caused by the user selecting text.
264+ * Selecting text should not mess with the hover, hover pinning nor the URL.
265+ */
266+ const codeClicksWithoutSelections = allCodeClicks . pipe ( filter ( ( ) => window . getSelection ( ) . toString ( ) === '' ) )
267+
269268 // Mouse is moving, don't show the tooltip
270269 subscription . add (
271270 merge (
@@ -300,7 +299,7 @@ export const createHoverifier = ({
300299 share ( )
301300 )
302301
303- const codeClickTargets = allCodeClicks . pipe (
302+ const codeClickTargets = codeClicksWithoutSelections . pipe (
304303 filter ( ( { event } ) => event . currentTarget !== null ) ,
305304 map ( ( { event, ...rest } ) => ( {
306305 target : event . target as HTMLElement ,
@@ -527,13 +526,13 @@ export const createHoverifier = ({
527526 } )
528527 )
529528
530- // When the close button is clicked, ESC is pressed or outside a code view is clicked unpin, hide and reset the hover
529+ // When the close button is clicked, unpin, hide and reset the hover
531530 subscription . add (
532531 merge (
533532 closeButtonClicks ,
534- fromEvent < KeyboardEvent > ( window , 'keydown' ) . pipe ( filter ( event => event . key === Key . Escape ) ) ,
535- fromEvent < MouseEvent > ( window , 'click' )
536- ) . subscribe ( ( ) => {
533+ fromEvent < KeyboardEvent > ( window , 'keydown' ) . pipe ( filter ( event => event . key === Key . Escape ) )
534+ ) . subscribe ( event => {
535+ event . preventDefault ( )
537536 container . update ( {
538537 hoverOverlayIsFixed : false ,
539538 hoverOverlayPosition : undefined ,
0 commit comments