@@ -10,7 +10,6 @@ import {
10
10
share ,
11
11
switchMap ,
12
12
takeUntil ,
13
- tap ,
14
13
withLatestFrom ,
15
14
} from 'rxjs/operators'
16
15
import { Key } from 'ts-key-enum'
@@ -254,18 +253,18 @@ export const createHoverifier = ({
254
253
) : event is MouseEventTrigger & { eventType : T } => event . eventType === type
255
254
const allCodeMouseMoves = allPositionsFromEvents . pipe ( filter ( isEventType ( 'mousemove' ) ) )
256
255
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' ) ) )
264
257
265
258
const allPositionJumps = new Subject < PositionJump & EventOptions > ( )
266
259
267
260
const subscription = new Subscription ( )
268
261
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
+
269
268
// Mouse is moving, don't show the tooltip
270
269
subscription . add (
271
270
merge (
@@ -300,7 +299,7 @@ export const createHoverifier = ({
300
299
share ( )
301
300
)
302
301
303
- const codeClickTargets = allCodeClicks . pipe (
302
+ const codeClickTargets = codeClicksWithoutSelections . pipe (
304
303
filter ( ( { event } ) => event . currentTarget !== null ) ,
305
304
map ( ( { event, ...rest } ) => ( {
306
305
target : event . target as HTMLElement ,
@@ -527,13 +526,13 @@ export const createHoverifier = ({
527
526
} )
528
527
)
529
528
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
531
530
subscription . add (
532
531
merge (
533
532
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 ( )
537
536
container . update ( {
538
537
hoverOverlayIsFixed : false ,
539
538
hoverOverlayPosition : undefined ,
0 commit comments