File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed
ui/apps/reader/MainPanel/Article Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change
1
+ export const getAnchor = ( el : HTMLElement ) : HTMLAnchorElement | null => {
2
+ let parent : HTMLElement | null = el
3
+
4
+ while ( parent && parent !== document . body ) {
5
+ if ( parent instanceof HTMLAnchorElement ) {
6
+ return parent
7
+ }
8
+
9
+ parent = parent . parentElement
10
+ }
11
+
12
+ return null
13
+ }
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import { observer } from 'mobx-react-lite'
5
5
import { store } from '@/ui/store'
6
6
import { format as formatTime } from '@/base/common/date'
7
7
import { openExternal } from '@/base/browser/shell'
8
+ import { getAnchor } from '@/base/browser/dom'
8
9
9
10
const { readerStore } = store
10
11
@@ -81,14 +82,16 @@ function Content() {
81
82
82
83
useEffect ( ( ) => {
83
84
const el = containerRef . current
85
+
84
86
const handler = ( e : MouseEvent ) => {
85
- const { target } = e
86
- if ( ! ( target instanceof HTMLAnchorElement ) || ! target . href ) {
87
+ const anchor = getAnchor ( e . target as HTMLElement )
88
+
89
+ if ( ! ( anchor instanceof HTMLAnchorElement ) || ! anchor . href ) {
87
90
return
88
91
}
89
92
90
93
e . preventDefault ( )
91
- openExternal ( target . href )
94
+ openExternal ( anchor . href )
92
95
}
93
96
94
97
el ?. addEventListener ( 'click' , handler )
You can’t perform that action at this time.
0 commit comments