File tree 1 file changed +31
-6
lines changed
1 file changed +31
-6
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,28 @@ function getWindowHeight() {
22
22
return window . innerHeight ;
23
23
}
24
24
25
+ const BlockElements = {
26
+ P : 1 ,
27
+ H1 : 1 ,
28
+ H2 : 1 ,
29
+ H3 : 1 ,
30
+ H4 : 1 ,
31
+ H5 : 1 ,
32
+ H6 : 1 ,
33
+ OL : 1 ,
34
+ UL : 1 ,
35
+ PRE : 1 ,
36
+ BLOCKQUOTE : 1 ,
37
+ HR : 1 ,
38
+ TABLE : 1 ,
39
+ FIGURE : 1 ,
40
+ DIV : 1 ,
41
+ } ;
42
+
43
+ function isBlockElement ( tagName : string ) {
44
+ return tagName in BlockElements ;
45
+ }
46
+
25
47
/**
26
48
* Zero-based line number
27
49
* @param element
@@ -209,12 +231,11 @@ const PreviewContainer = createContainer(() => {
209
231
if ( ! totalLineCount . current || ! previewElement . current ) {
210
232
return null ;
211
233
}
212
- const newScrollMap : number [ ] = [ ] ;
234
+ const newScrollMap : number [ ] = Array (
235
+ Math . max ( totalLineCount . current , 0 ) ,
236
+ ) . fill ( - 1 ) ;
213
237
const nonEmptyList : number [ ] = [ ] ;
214
-
215
- for ( let i = 0 ; i < totalLineCount . current ; i ++ ) {
216
- newScrollMap . push ( - 1 ) ;
217
- }
238
+ const addedLines = new Set < number > ( ) ;
218
239
219
240
nonEmptyList . push ( 0 ) ;
220
241
newScrollMap [ 0 ] = 0 ;
@@ -225,11 +246,15 @@ const PreviewContainer = createContainer(() => {
225
246
226
247
for ( let i = 0 ; i < lineElements . length ; i ++ ) {
227
248
let el = lineElements [ i ] as HTMLElement ;
249
+ if ( ! isBlockElement ( el . tagName ) ) {
250
+ continue ;
251
+ }
228
252
229
253
const t = getDataSourceLine ( el ) ;
230
- if ( ! t ) {
254
+ if ( ! t || addedLines . has ( t ) ) {
231
255
continue ;
232
256
}
257
+ addedLines . add ( t ) ;
233
258
234
259
// this is for ignoring footnote scroll match
235
260
if ( t < nonEmptyList [ nonEmptyList . length - 1 ] ) {
You can’t perform that action at this time.
0 commit comments