@@ -767,23 +767,41 @@ export default class UI extends Module<UINodes> {
767
767
return ;
768
768
}
769
769
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.
775
772
const ctrlKey = event . metaKey || event . ctrlKey ;
776
773
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 ;
780
777
781
- const href = element . getAttribute ( 'href' ) ;
782
- const validUrl = _ . getValidUrl ( href ) ;
778
+ while ( currentElement ) {
779
+ if ( currentElement === this . nodes . redactor ) {
780
+ break ;
781
+ }
783
782
784
- _ . openTab ( validUrl ) ;
783
+ if ( currentElement . tagName === 'A' ) {
784
+ anchor = currentElement ;
785
+ break ;
786
+ }
785
787
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
+ }
787
805
}
788
806
789
807
this . processBottomZoneClick ( event ) ;
0 commit comments