@@ -70,6 +70,9 @@ function Highlighter(options = hhDefaultOptions) {
7070 width: 0px;
7171 visibility: hidden;
7272 }
73+ [data-hh-pointer-down="true"] .hh-selection-handle {
74+ visibility: hidden !important;
75+ }
7376 .hh-selection-handle-content {
7477 position: absolute;
7578 height: 100%;
@@ -642,13 +645,13 @@ function Highlighter(options = hhDefaultOptions) {
642645 this . annotatableContainer . addEventListener ( 'pointerdown' , ( event ) => respondToPointerDown ( event ) , { signal : controller . signal } ) ;
643646 const respondToPointerDown = ( event ) => {
644647 const isSecondaryClick = ( event . button !== 0 || event . altKey || event . ctrlKey || event . metaKey || event . shiftKey ) ;
648+ if ( ! isSecondaryClick ) this . annotatableContainer . dataset . hhPointerDown = 'true' ;
645649 pointerType = event . pointerType ;
646650
647651 // Pointer down on a selection handle
648652 if ( event . target ?. closest ( '.hh-selection-handle' ) ) {
649653 if ( ! isSecondaryClick ) {
650654 activeSelectionHandle = event . target . parentElement . closest ( '.hh-selection-handle' ) ;
651- this . annotatableContainer . dataset . hhDragging = 'true' ;
652655 const selectionHandleClientRect = activeSelectionHandle . getBoundingClientRect ( ) ;
653656 const lineHeight = selectionHandleClientRect . bottom - selectionHandleClientRect . top ;
654657 activeSelectionHandle . dataset . dragYOffset = Math . max ( 0 , event . clientY - selectionHandleClientRect . bottom + ( lineHeight / 6 ) ) ;
@@ -748,10 +751,10 @@ function Highlighter(options = hhDefaultOptions) {
748751 }
749752 tapResult = null ;
750753 longPressTimeoutId = clearTimeout ( longPressTimeoutId ) ;
754+ this . annotatableContainer . dataset . hhPointerDown = 'false' ;
751755 if ( activeSelectionHandle ) {
752756 activeSelectionHandle = null ;
753757 updateSelectionUi ( 'bounds' ) ;
754- this . annotatableContainer . dataset . hhDragging = 'false' ;
755758 this . annotatableContainer . removeEventListener ( 'pointermove' , respondToSelectionHandleDrag ) ;
756759 }
757760 }
@@ -898,7 +901,7 @@ function Highlighter(options = hhDefaultOptions) {
898901 const highlightInfo = highlightsById [ activeHighlightId ] ?? null ;
899902 const color = highlightInfo ?. color ?? null ;
900903 const style = highlightInfo ?. style ?? null ;
901- const colorString = options . colors [ color ] ?? ' AccentColor';
904+ const colorString = options . colors [ color ] ?? ( CSS . supports ( 'color' , ' AccentColor') ? 'AccentColor' : 'dodgerblue' ) ;
902905
903906 // Draw SVG selection rects (SVG drawing mode only)
904907 svgActiveOverlay . innerHTML = '' ;
@@ -953,16 +956,22 @@ function Highlighter(options = hhDefaultOptions) {
953956
954957 } else if ( changeType === 'bounds' ) {
955958 // Update selection handle location and visibility
956- if ( selection . type === 'Range' && activeHighlightId && pointerType === 'mouse' && ! activeSelectionHandle ) {
959+ if ( selection . type === 'Range' ) {
957960 const selectionRangeRects = selectionRange . getClientRects ( ) ;
958961 const startRect = selectionRangeRects [ 0 ] ;
959962 const endRect = selectionRangeRects [ selectionRangeRects . length - 1 ] ;
960963 const relativeAncestorClientRect = this . relativeAncestorElement . getBoundingClientRect ( ) ;
961964 const startNodeIsRtl = window . getComputedStyle ( selectionRange . startContainer . parentElement ) . direction === 'rtl' ;
962965 const endNodeIsRtl = window . getComputedStyle ( selectionRange . endContainer . parentElement ) . direction === 'rtl' ;
963966
967+ if (
968+ ( options . showCustomSelectionHandlesOnTouch || pointerType === 'mouse' )
969+ && ( ( options . showCustomSelectionHandlesForActiveHighlights && activeHighlightId )
970+ || ( options . showCustomSelectionHandlesForTextSelection && ! activeHighlightId ) )
971+ ) {
972+ setCustomSelectionHandleVisibility ( true ) ;
973+ }
964974 for ( const selectionHandle of selectionHandles ) {
965- selectionHandle . style . visibility = 'visible' ;
966975 let side ;
967976 if ( selectionHandle . dataset . position === 'start' ) {
968977 side = startNodeIsRtl ? 'right' : 'left' ;
@@ -981,12 +990,17 @@ function Highlighter(options = hhDefaultOptions) {
981990 }
982991 }
983992 } else {
984- selectionHandles [ 0 ] . style . visibility = 'hidden' ;
985- selectionHandles [ 1 ] . style . visibility = 'hidden' ;
993+ setCustomSelectionHandleVisibility ( false ) ;
986994 }
987995 }
988996 }
989997
998+ const setCustomSelectionHandleVisibility = ( visible = selectionHandles [ 0 ] . style . visibility === 'hidden' ) => {
999+ for ( const selectionHandle of selectionHandles ) {
1000+ selectionHandle . style . visibility = visible ? 'visible' : 'hidden' ;
1001+ }
1002+ }
1003+
9901004 // Update the selection or highlight range to stay within the annotatable container
9911005 const snapRangeToBoundaries = ( range , anchorNode = null ) => {
9921006 let startNode = range . startContainer ;
@@ -1450,6 +1464,9 @@ let hhDefaultOptions = {
14501464 defaultStyle : 'fill' ,
14511465 defaultWrapper : 'none' ,
14521466 highlightIdFunction : hhGetNewHighlightId ,
1467+ showCustomSelectionHandlesForActiveHighlights : true ,
1468+ showCustomSelectionHandlesForTextSelection : false ,
1469+ showCustomSelectionHandlesOnTouch : false ,
14531470}
14541471
14551472console . info ( 'Highlighter loaded' ) ;
0 commit comments