@@ -767,23 +767,41 @@ export default class UI extends Module<UINodes> {
767767 return ;
768768 }
769769
770- /**
771- * case when user clicks on anchor element
772- * if it is clicked via ctrl key, then we open new window with url
773- */
774- const element = event . target as Element ;
770+ // Check if user clicks on a link while holding down the ctrl/cmd key.
771+ // In that case, open it in a new tab/window.
775772 const ctrlKey = event . metaKey || event . ctrlKey ;
776773
777- if ( $ . isAnchor ( element ) && ctrlKey ) {
778- event . stopImmediatePropagation ( ) ;
779- event . stopPropagation ( ) ;
774+ if ( ctrlKey && event . target instanceof Element ) {
775+ let currentElement : Element | null = event . target ;
776+ let anchor = null ;
780777
781- const href = element . getAttribute ( 'href' ) ;
782- const validUrl = _ . getValidUrl ( href ) ;
778+ while ( currentElement ) {
779+ if ( currentElement === this . nodes . redactor ) {
780+ break ;
781+ }
783782
784- _ . openTab ( validUrl ) ;
783+ if ( currentElement . tagName === 'A' ) {
784+ anchor = currentElement ;
785+ break ;
786+ }
785787
786- return ;
788+ currentElement = currentElement . parentElement ;
789+ }
790+
791+ if ( anchor ) {
792+ event . stopImmediatePropagation ( ) ;
793+ event . stopPropagation ( ) ;
794+
795+ const href = anchor . getAttribute ( 'href' ) ;
796+
797+ if ( href !== null ) {
798+ const validUrl = _ . getValidUrl ( href ) ;
799+
800+ window . open ( validUrl , '_blank' ) ;
801+ }
802+
803+ return ;
804+ }
787805 }
788806
789807 this . processBottomZoneClick ( event ) ;
0 commit comments