@@ -389,6 +389,11 @@ function handleMouseDown(e) {
389389 }
390390}
391391
392+ function sameRange ( r1 , r2 ) {
393+ return ( r1 . compareBoundaryPoints ( Range . START_TO_START , r2 ) == 0 &&
394+ r1 . compareBoundaryPoints ( Range . END_TO_END , r2 ) == 0 ) ;
395+ }
396+
392397function isSpuriousSelection ( sel , newTimeStamp ) {
393398 if ( newTimeStamp - oldTimeStamp > 10 ) {
394399 return false ;
@@ -397,10 +402,7 @@ function isSpuriousSelection(sel, newTimeStamp) {
397402 return true ;
398403 }
399404 for ( let i = 0 ; i < sel . rangeCount ; i ++ ) {
400- const r1 = sel . getRangeAt ( i ) ;
401- const r2 = oldRanges [ i ] ;
402- if ( r1 . compareBoundaryPoints ( Range . START_TO_START , r2 ) != 0 ||
403- r1 . compareBoundaryPoints ( Range . END_TO_END , r2 ) != 0 ) {
405+ if ( ! sameRange ( sel . getRangeAt ( i ) , oldRanges [ i ] ) ) {
404406 return true ;
405407 }
406408 }
@@ -416,8 +418,21 @@ function handleContextMenu(e) {
416418 return sel ;
417419}
418420
419- function handleClick ( ) {
420- selectWholeAddress ( this , window . getSelection ( ) ) ;
421+ function handleClick ( e ) {
422+ const sel = window . getSelection ( ) ;
423+
424+ // If the user clicked an already-selected address, deselect it.
425+ // Don't check timeStamp because it depends how long they held the button.
426+ if ( e . detail == 1 && oldRanges . length == 1 ) {
427+ const newRange = document . createRange ( ) ;
428+ newRange . selectNodeContents ( this ) ;
429+ if ( sameRange ( newRange , oldRanges [ 0 ] ) ) {
430+ sel . removeAllRanges ( ) ;
431+ return ;
432+ }
433+ }
434+
435+ selectWholeAddress ( this , sel ) ;
421436}
422437
423438// If the user hasn't manually selected part of the address, then select
0 commit comments