Last Comment Bug 236068 - removeItemAt for <listbox> removes wrong item if there is a <listhead>
: removeItemAt for <listbox> removes wrong item if there is a <listhead>
Status: RESOLVED FIXED
[good first bug]
: helpwanted
Product: Core
Classification: Components
Component: XUL (show other bugs)
: Trunk
: x86 Linux
: -- normal (vote)
: ---
Assigned To: jag (Peter Annema)
: John Morrison
Mentors:
: 277498 (view as bug list)
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2004-02-29 18:49 PST by Bill Dimm
Modified: 2005-07-14 10:34 PDT (History)
4 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
reporter's testcase (693 bytes, application/vnd.mozilla.xul+xml)
2004-08-03 17:00 PDT, jon rekai
no flags Details
fix (1.60 KB, patch)
2004-08-03 17:00 PDT, jon rekai
jvarga: review+
neil: superreview+
Details | Diff | Review

Description Bill Dimm 2004-02-29 18:49:42 PST
User-Agent:       
Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7a) Gecko/20040218

If a <listbox> has a <listhead>, calls to removeItemAt() remove the wrong row. 
The function seems to treat the <listhead> as item 0 and it treats the first
<listitem> as item 1, which is not consistent with how other functions like
getItemAtIndex() behave.  Here is some sample code:

-------
<script>
   function del()
      {
      var list = document.getElementById('mylist');
      list.removeItemAt(1);
      }
</script>

<listbox id='mylist'>
   <listhead>
      <listheader label='My List'/>
   </listhead>
   <listitem label='zero'/>
   <listitem label='one'/>
</listbox>
<button label='Del' onclick='del()'/>
--------

Clicking the button "Del" should remove the "one" item from the list, but it
removes the "zero" item instead.  If you remove the "<listhead>...</listehead>"
the problem goes away.

Is there a way to work around this that won't break when the bug is fixed (i.e.
simply adding 1 to the index isn't a good work around since it will break)?  I
tried looking at getIndexOfFirstVisibleRow(), but it returns 0 (instead of 1)
even when <listhead> is present.

Reproducible: Always
Steps to Reproduce:
1. Implement the code given in the details.
2. Push the "Del" button
3.

Actual Results:  
The "zero" item is removed.

Expected Results:  
The "one" item should be removed.
Comment 1 Bill Dimm 2004-03-27 09:12:07 PST
Actually, the presence of <listhead> isn't the only thing that causes problems.
 <listcols> will do it to.

If you examine the JavaScript code for removeItemAt(index), you will find that
it attempts to remove this.childNodes[index], which is only the right thing to
do if ALL of the child nodes are "listitem" objects.  If you have a <listhead>
or <listcols>, the child node with index 0 is not a listitem, so the wrong child
is removed.
Comment 2 neil@parkwaycc.co.uk 2004-03-27 11:55:57 PST
You are right, all the methods should getItemAtIndex instead of childNodes.
Comment 3 jon rekai 2004-08-03 17:00:04 PDT
Created attachment 155125 [details]
reporter's testcase
Comment 4 jon rekai 2004-08-03 17:00:46 PDT
Created attachment 155126 [details] [diff] [review]
fix

according to comment 2
Comment 5 neil@parkwaycc.co.uk 2004-08-30 14:29:27 PDT
Fix checked in.
Comment 6 Boris Zbarsky [:bz] (Out June 25-July 6) 2005-01-30 17:36:54 PST
*** Bug 277498 has been marked as a duplicate of this bug. ***
Comment 7 Daniel Beckham 2005-07-14 08:38:07 PDT
This bug still exists in current versions of Firefox. (1.0.5)  Could someone
please reopen this bug for current version of Firefox?  If not, what should be
done?  A new bug filed?
Comment 8 Mike Connor [:mconnor] 2005-07-14 10:34:16 PDT
This is not going to be backported to the 1.0.x stable branch, it will be in the
next releases of Firefox and SeaMonkey.

Note You need to log in before you can comment on or make changes to this bug.