File tree 1 file changed +10
-7
lines changed 1 file changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -12,13 +12,16 @@ export function shouldReportUnsorted(
12
12
unsortedBody : NodeOrToken [ ] ,
13
13
nodeInfo : NodePositionInfo ,
14
14
) {
15
- const { initialIndex, finalIndex } = nodeInfo
16
- const isLastSorted = finalIndex === sortedBody . length - 1
17
- // Node moved and next sorted node isn't the same neighbor as unsorted
18
- return (
19
- initialIndex !== finalIndex &&
20
- ( isLastSorted || sortedBody [ finalIndex + 1 ] !== unsortedBody [ initialIndex + 1 ] )
21
- )
15
+ const { initialIndex : unsortedIndex , finalIndex : sortedIndex } = nodeInfo
16
+ const isLastInSorted = sortedIndex === sortedBody . length - 1
17
+ const nextSortedNode = sortedBody [ sortedIndex + 1 ]
18
+ const nextUnsortedNode = unsortedBody [ unsortedIndex + 1 ]
19
+ // is sorted directly with a neighbor or partially sorted (e.g. a B D F E only 2 out of order)
20
+ const isPartiallySorted =
21
+ nextSortedNode === nextUnsortedNode ||
22
+ unsortedBody . indexOf ( nextSortedNode ) > unsortedIndex
23
+
24
+ return unsortedIndex !== sortedIndex && ( isLastInSorted || ! isPartiallySorted )
22
25
}
23
26
24
27
// Helpful metadata on nodes to report/skip reporting
You can’t perform that action at this time.
0 commit comments