Open Bug 2071534 Opened 2 months ago Updated 2 months ago

TreeSelection: deselecting a row increases the selected count after removing an intervening row

Categories

(Thunderbird :: Folder and Message Lists, defect)

defect

Tracking

(Not tracked)

People

(Reporter: mozilla.glisten716, Unassigned)

References

Details

Attachments

(1 external file)

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/152.0.0.0 Safari/537.36

Steps to reproduce:

Tested the production TreeSelection class from Thunderbird 155.0.1 on macOS. The installed module is identical to upstream revision 8008847c667df856155338e28ddd9957b0db9d22.

This is a module-level reproduction using a Node adapter for module loading and XPCOM interface registration. Native xpcshell and live mailbox reproduction have not been run.

Minimal sequence, with TreeSelection imported:

const view = { rowCount: 3, selectionChanged() {} };
const selection = new TreeSelection(null);
selection.view = view;

// Select A and C from rows A, B, C.
selection.select(0);
selection.toggleSelect(2);

// Remove the unselected middle row B.
view.rowCount = 2;
selection.adjustSelection(1, -1);

// Attempt to deselect C, now at index 1.
selection.toggleSelect(1);

Actual results:

After removing the middle row, the selection retains adjacent ranges [[0,0],[1,1]] instead of merging them.

Toggling row 1 then produces overlapping ranges [[0,1],[1,1]].

selection.count returns 3, although only two rows exist.
selection.isSelected(1) remains true.

In adjustSelection(), the translation loop advances iTrans to the array length, making the subsequent merge condition unreachable. The adjacency comparison also needs to account for inclusive range endpoints.

Expected results:

After removal, the selection should contain one merged range [[0,1]].

After toggling row 1, only row 0 should remain selected:
selection.count === 1
selection.isSelected(1) === false

A proposed fix and regression test are attached. The regression fails against the original module and passes with the fix in the local adapter.

Possibly related: bug 1885341
The same underlying cause has not been established; please advise whether this belongs on that report.

Removing the gap between selected rows leaves adjacent internal ranges in TreeSelection. Toggling the first row of the later range then selects it a second time instead of deselecting it. With A and C selected from A/B/C, removing B and toggling C leaves both remaining rows selected and reports a count of three. This was reproduced directly against the production class; a live mailbox reproduction is still pending.

Preserve the first translated range index so the merge check can run after translating the remaining ranges. Compare inclusive range endpoints with an offset of one to recognize adjacency. Add a regression test covering both the merge and the subsequent deselection.

Steps to reproduce:

  1. Create a temporary folder containing three messages displayed consecutively: A, B, C.
  2. Disable threading/grouping and use a stable sort order.
  3. Open the middle message B in a separate message window.
  4. In the main three-pane window:
    • Select A normally.
    • Ctrl-click C on Windows/Linux, or Command-click C on macOS.
    • A and C should now be selected while B is not.
  5. In B’s separate message window, delete B.
  6. Return to the main window. A and C should remain selected and now be adjacent.
  7. Ctrl/Command-click C to deselect it.

Expected: only A remains selected.

Actual: C remains selected; visually, the click may appear to do nothing. Internally, the selection count becomes 3 even though the folder has only two rows.

The deficiency is already present in the original 2009 implementation from bug 474701.

Severity: -- → S4
Status: UNCONFIRMED → NEW
Ever confirmed: true
See Also: → 474701
Version: Thunderbird 155 → 3.0
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: