File tree Expand file tree Collapse file tree 1 file changed +10
-7
lines changed Expand file tree Collapse file tree 1 file changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -12,13 +12,16 @@ export function shouldReportUnsorted(
1212 unsortedBody : NodeOrToken [ ] ,
1313 nodeInfo : NodePositionInfo ,
1414) {
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 )
2225}
2326
2427// Helpful metadata on nodes to report/skip reporting
You can’t perform that action at this time.
0 commit comments