| 1678 | return aValue - bValue; | 1678 | return aValue - bValue; |
| 1679 | }; | 1679 | }; |
| 1680 | } else if (sortRule === 'priority') { | 1680 | } else if (sortRule === 'priority') { |
| 1681 | // First constant, then normal, then disabled. | 1681 | // First constant, then normal, then disabled, then by comment. |
| 1682 | primarySort = (a, b) => { | 1682 | primarySort = (a, b) => { |
| 1683 | const aValue = a.constant ? 0 : a.disable ? 2 : 1; | 1683 | // Determine priority based on disable and constant flags |
| 1684 | const bValue = b.constant ? 0 : b.disable ? 2 : 1; | 1684 | const aPriority = a.disable ? 2 : a.constant ? 0 : 1; |
| 1685 | return aValue - bValue; | 1685 | const bPriority = b.disable ? 2 : b.constant ? 0 : 1; |
| | 1686 | |
| | 1687 | // Compare priorities first |
| | 1688 | if (aPriority !== bPriority) { |
| | 1689 | return aPriority - bPriority; |
| | 1690 | } |
| | 1691 | |
| | 1692 | // Normalize comments for comparison, handling null/undefined |
| | 1693 | const commentA = a.comment ? a.comment.toLowerCase() : ''; |
| | 1694 | const commentB = b.comment ? b.comment.toLowerCase() : ''; |
| | 1695 | |
| | 1696 | // Assign constant values for further comparison |
| | 1697 | const constantA = a.constant ? 0 : 1; |
| | 1698 | const constantB = b.constant ? 0 : 1; |
| | 1699 | |
| | 1700 | // If priorities are equal, compare constants |
| | 1701 | if (aPriority === bPriority) { |
| | 1702 | if (constantA !== constantB) { |
| | 1703 | return constantA - constantB; |
| | 1704 | } |
| | 1705 | } |
| | 1706 | |
| | 1707 | // Finally, compare comments alphabetically |
| | 1708 | return commentA.localeCompare(commentB); |
| 1686 | }; | 1709 | }; |
| 1687 | } else { | 1710 | } else { |
| 1688 | primarySort = (a, b) => { | 1711 | primarySort = (a, b) => { |