@@ -596,11 +596,20 @@ function SecureSort:CreateHandler()
596596 -- STEP 2: Get sort settings
597597 -- =====================================================
598598 local sortEnabled = self:GetAttribute("sortEnabled")
599+ local sortByPartyOrder = self:GetAttribute("sortByPartyOrder") or false
600+ local partyOrderSort = sortByPartyOrder
599601 local selfPosition = self:GetAttribute("selfPosition") or "NORMAL"
600602 local sortAlphabetical = self:GetAttribute("sortAlphabetical") or false
601603 local sortAlphaReverse = (sortAlphabetical == "ZA")
602604 local sortByClass = self:GetAttribute("sortByClass") or false
603605
606+ if sortByPartyOrder then
607+ -- ignore other criteria when using raw party order
608+ sortEnabled = false
609+ sortAlphabetical = false
610+ sortByClass = false
611+ end
612+
604613 -- =====================================================
605614 -- STEP 3: Query roles (if sorting enabled)
606615 -- =====================================================
@@ -700,11 +709,23 @@ function SecureSort:CreateHandler()
700709 for idx = 0, frameCount - 1 do
701710 local i = visibleFrames[idx]
702711 local unit = frameUnits[i]
703- local role = unit2role[unit] or "DAMAGER"
704- local rp = rolePriority[role] or 99
705- local cls = unit2class[unit]
706- local cp = sortByClass and (classPriority[cls] or 99) or 0
707- frameSortKey[idx] = rp * 100 + cp
712+ if partyOrderSort then
713+ -- When using "party/raid index order", we want to KEEP the
714+ -- existing visual order of the frames and only apply the
715+ -- selfPosition override (player first/last/numeric slot).
716+ --
717+ -- The existing order is exactly the order of visibleFrames,
718+ -- so we just use the current index as the sort key. This
719+ -- guarantees non-player units stay in their current order,
720+ -- matching the behavior when sorting is disabled.
721+ frameSortKey[idx] = idx
722+ else
723+ local role = unit2role[unit] or "DAMAGER"
724+ local rp = rolePriority[role] or 99
725+ local cls = unit2class[unit]
726+ local cp = sortByClass and (classPriority[cls] or 99) or 0
727+ frameSortKey[idx] = rp * 100 + cp
728+ end
708729
709730 -- Read name from attribute (pushed by Lua code)
710731 frameName[idx] = self:GetAttribute("frameName" .. i) or ""
@@ -720,7 +741,7 @@ function SecureSort:CreateHandler()
720741 end
721742
722743 -- Bubble sort by sort key, then by name as tiebreaker
723- if sortEnabled then
744+ if sortEnabled or partyOrderSort then
724745 for i = 0, frameCount - 2 do
725746 for j = 0, frameCount - 2 - i do
726747 local a = sortOrder[j]
@@ -2023,6 +2044,7 @@ function SecureSort:PushSortSettings()
20232044 self .sortButton :SetAttribute (" roleOrder3" , roleOrder [3 ] or " DAMAGER" )
20242045 self .sortButton :SetAttribute (" selfPosition" , db .sortSelfPosition or " SORTED" )
20252046 self .sortButton :SetAttribute (" sortEnabled" , db .sortEnabled or false )
2047+ self .sortButton :SetAttribute (" sortByPartyOrder" , db .sortByPartyOrder or false )
20262048 self .sortButton :SetAttribute (" sortByClass" , db .sortByClass or false )
20272049 self .sortButton :SetAttribute (" meleeBeforeRanged" , meleeBeforeRanged )
20282050 self .sortButton :SetAttribute (" sortAlphabetical" , db .sortAlphabetical or false )
@@ -2034,6 +2056,7 @@ function SecureSort:PushSortSettings()
20342056 self .handler :SetAttribute (" roleOrder3" , roleOrder [3 ] or " DAMAGER" )
20352057 self .handler :SetAttribute (" selfPosition" , db .sortSelfPosition or " SORTED" )
20362058 self .handler :SetAttribute (" sortEnabled" , db .sortEnabled or false )
2059+ self .handler :SetAttribute (" sortByPartyOrder" , db .sortByPartyOrder or false )
20372060 self .handler :SetAttribute (" sortByClass" , db .sortByClass or false )
20382061 self .handler :SetAttribute (" meleeBeforeRanged" , meleeBeforeRanged )
20392062 self .handler :SetAttribute (" sortAlphabetical" , db .sortAlphabetical or false )
@@ -2063,6 +2086,7 @@ function SecureSort:PushSortSettings()
20632086 DebugPrint (" Sort settings pushed: " ..
20642087 (roleOrder [1 ] or " ?" ) .. " >" .. (roleOrder [2 ] or " ?" ) .. " >" .. (roleOrder [3 ] or " ?" ) ..
20652088 " self=" .. (db .sortSelfPosition or " SORTED" ) ..
2089+ " partyOrder=" .. tostring (db .sortByPartyOrder ) ..
20662090 " class=" .. tostring (db .sortByClass or false ) ..
20672091 " alpha=" .. tostring (db .sortAlphabetical or false ))
20682092
0 commit comments