| 1678 | 1678 | return aValue - bValue; |
| 1679 | 1679 | }; |
| 1680 | 1680 | } else if (sortRule === 'priority') { |
| 1681 | 1681 | // First constant, then normal, then disabled, then by comment. |
| 1682 | 1682 | primarySort = (a, b) => { |
| 1683 | | - const aValue = a.constant ? 0 : a.disable ? 2 : 1; |
| 1683 | + // Determine priority based on disable and constant flags |
| 1684 | 1684 | const bValueaPriority = ba.constantdisable ? 02 : ba.disableconstant ? 20 : 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 | 1710 | } else { |
| 1688 | 1711 | primarySort = (a, b) => { |