View Single Post
11/18/15, 08:18 PM   #1
haggen
 
haggen's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2015
Posts: 137
Bug in SortHeaderGroup

I stumbled upon it when trying to set a default sorting for my add-on.

The bug is: 'OnHeaderClicked' is ignoring the initial direction given by ZO_SortHeader_Initialize.

Let's take a look:

File esoui\libraries\zo_sortheadergroup\zo_sortheadergroup.lua, from line 149 to 165
Lua Code:
  1. function ZO_SortHeaderGroup:OnHeaderClicked(header, suppressCallbacks, forceReselect)
  2.     if self:IsEnabled() then
  3.         local resetSortDir = false
  4.         if forceReselect or not self:IsCurrentSelectedHeader(header) then
  5.             self:DeselectHeader()
  6.             resetSortDir = true
  7.         end
  8.  
  9.         self.sortDirection = resetSortDir and header.initialDirection or not self.sortDirection
  10.  
  11.         self:SelectHeader(header)
  12.    
  13.         if(not suppressCallbacks) then
  14.             self:FireCallbacks(self.HEADER_CLICKED, header.key, self.sortDirection)
  15.         end
  16.     end
  17. end

Upon first calling 'OnHeaderClicked' (whether by clicking on the header or calling 'SelectHeaderByKey'), the line that sets 'sortDirection' always gets true, no matter what. I think the problem is the use of 'x and y or z', since sortDirection is a boolean flag, it's tricky to use this ternary-ish conditional instead of a full body if/else.

Edit.

Yes! As I suspected, changing the line

Lua Code:
  1. self.sortDirection = resetSortDir and header.initialDirection or not self.sortDirection

to

Lua Code:
  1. if resetSortDir then
  2.   self.sortDirection = header.initialDirection
  3. else
  4.   self.sortDirection = not self.sortDirection
  5. end

Fixed the problem!

I always found 'x and y or z' smelly, a mine waiting to be detonated. :P

Last edited by haggen : 11/18/15 at 08:31 PM. Reason: Fix
  Reply With Quote