@@ -208,7 +208,8 @@ export async function findClassListsInHtmlRange(
208
208
matches . push ( ...matchClassFunctions ( text , settings . classFunctions ) )
209
209
}
210
210
211
- const result : DocumentClassList [ ] = [ ]
211
+ const existingResultSet = new Set < string > ( )
212
+ const results : DocumentClassList [ ] = [ ]
212
213
213
214
matches . forEach ( ( match ) => {
214
215
const subtext = text . substr ( match . index + match [ 0 ] . length - 1 )
@@ -253,46 +254,53 @@ export async function findClassListsInHtmlRange(
253
254
} )
254
255
}
255
256
256
- result . push (
257
- ...classLists
258
- . map ( ( { value, offset } ) => {
259
- if ( value . trim ( ) === '' ) {
260
- return null
261
- }
257
+ classLists . forEach ( ( { value, offset } ) => {
258
+ if ( value . trim ( ) === '' ) {
259
+ return null
260
+ }
262
261
263
- const before = value . match ( / ^ \s * / )
264
- const beforeOffset = before === null ? 0 : before [ 0 ] . length
265
- const after = value . match ( / \s * $ / )
266
- const afterOffset = after === null ? 0 : - after [ 0 ] . length
267
-
268
- const start = indexToPosition (
269
- text ,
270
- match . index + match [ 0 ] . length - 1 + offset + beforeOffset ,
271
- )
272
- const end = indexToPosition (
273
- text ,
274
- match . index + match [ 0 ] . length - 1 + offset + value . length + afterOffset ,
275
- )
276
-
277
- return {
278
- classList : value . substr ( beforeOffset , value . length + afterOffset ) ,
279
- range : {
280
- start : {
281
- line : ( range ?. start . line || 0 ) + start . line ,
282
- character : ( end . line === 0 ? range ?. start . character || 0 : 0 ) + start . character ,
283
- } ,
284
- end : {
285
- line : ( range ?. start . line || 0 ) + end . line ,
286
- character : ( end . line === 0 ? range ?. start . character || 0 : 0 ) + end . character ,
287
- } ,
288
- } ,
289
- }
290
- } )
291
- . filter ( ( x ) => x !== null ) ,
292
- )
262
+ const before = value . match ( / ^ \s * / )
263
+ const beforeOffset = before === null ? 0 : before [ 0 ] . length
264
+ const after = value . match ( / \s * $ / )
265
+ const afterOffset = after === null ? 0 : - after [ 0 ] . length
266
+
267
+ const start = indexToPosition ( text , match . index + match [ 0 ] . length - 1 + offset + beforeOffset )
268
+ const end = indexToPosition (
269
+ text ,
270
+ match . index + match [ 0 ] . length - 1 + offset + value . length + afterOffset ,
271
+ )
272
+
273
+ const result : DocumentClassList = {
274
+ classList : value . substr ( beforeOffset , value . length + afterOffset ) ,
275
+ range : {
276
+ start : {
277
+ line : ( range ?. start . line || 0 ) + start . line ,
278
+ character : ( end . line === 0 ? range ?. start . character || 0 : 0 ) + start . character ,
279
+ } ,
280
+ end : {
281
+ line : ( range ?. start . line || 0 ) + end . line ,
282
+ character : ( end . line === 0 ? range ?. start . character || 0 : 0 ) + end . character ,
283
+ } ,
284
+ } ,
285
+ }
286
+
287
+ const resultKey = [
288
+ result . classList ,
289
+ result . range . start . line ,
290
+ result . range . start . character ,
291
+ result . range . end . line ,
292
+ result . range . end . character ,
293
+ ] . join ( ':' )
294
+
295
+ // No need to add the result if it was already matched
296
+ if ( ! existingResultSet . has ( resultKey ) ) {
297
+ existingResultSet . add ( resultKey )
298
+ results . push ( result )
299
+ }
300
+ } )
293
301
} )
294
302
295
- return result
303
+ return results
296
304
}
297
305
298
306
export async function findClassListsInRange (
0 commit comments