Thread Tools Display Modes
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
11/18/15, 08:56 PM   #2
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
You're totally right, that line doesn't do what it should. Btw http://www.esoui.com/forums/showpost...64&postcount=8 ^^
  Reply With Quote
11/18/15, 09:08 PM   #3
haggen
 
haggen's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2015
Posts: 137
Originally Posted by merlight View Post
You're totally right, that line doesn't do what it should. Btw http://www.esoui.com/forums/showpost...64&postcount=8 ^^
Oh damn! I tried searching for "Header sort" and missed that =/ Well, it should have been fixed by now.

Another thing that bothers me is: if you check the sort function for comparing rows in a scroll list, it accepts a flag in the sort keys options called "isNumeric" to know when to compare numeric values. But, in esoui\ingame\mail\mailinbox_shared.lua it reads "numeric" (without the prefix 'is'). I think it's misspelled but since I never took the time to look for other instances I never reported. Well, I am now. :P

Edit.

I was reading the link you mentioned. I notice now that there are bugs everywhere around SORT_ORDER_UP and SORT_ORDER_DOWN, and I think it's because they're booleans. Wouldn't it be better if they used 0 and 1?

Last edited by haggen : 11/19/15 at 06:37 AM.
  Reply With Quote
11/18/15, 09:55 PM   #4
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
Originally Posted by haggen View Post
Another thing that bothers me is: if you check the sort function for comparing rows in a scroll list, it accepts a flag in the sort keys options called "isNumeric" to know when to compare numeric values. But, in esoui\ingame\mail\mailinbox_shared.lua it reads "numeric" (without the prefix 'is'). I think it's misspelled but since I never took the time to look for other instances I never reported. Well, I am now. :P
It's probably misspelled, but in this case it also doesn't matter. ZO_TableOrderingFunction checks "isNumeric" and converts the argument tonumber; but since those two "numeric" arguments in mailbox already are numbers, "isNumeric" isn't needed there.

Originally Posted by haggen View Post
I was reading the link you mentioned. I notice now that there are bugs everywhere around SORT_ORDER_UP and SORT_ORDER_DOWN, and I think it's because they're booleans. Wouldn't it be better if they used 0 and 1?
Maybe, but then inversion (order = not order) would have to be rewritten (order = 1 - order), not only in ZO code, but also in add-ons. Better just fix the bad uses
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » Bug in SortHeaderGroup


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off