TreeView right-arrow key irregular behavior


#1

If you’re “right-arrowing” through a tree view, you get some weird behavior. When the item is a parent, the right arrow expands it if it’s closed, or moves down the selection otherwise; if it’s not a parent, then nothing happens the first time you hit the key, but the selection moves down the next time you hit the key.

This is easy to reproduce in the treeview demo by selecting the top item and clicking the right-arrow key to navigate through the items.

On the first click, the “openness” of the child item is being checked and changed, unnecessarily, and this results in some callbacks and repaints that can really slow down the control.

This change in TreeView::keyPressed() fixes it:

[code]void TreeView::keyPressed (const KeyPress& key)
{

else if (key.isKeyCode (KeyPress::rightKey))
{
TreeViewItem* const firstSelected = getSelectedItem (0);

    if (firstSelected != 0)
    {
        // *** MOD: added check for parenthood -- don't try to open if it's not a parent
        if (firstSelected->isOpen() || ! firstSelected->mightContainSubItems())
            moveSelectedRow (1);
        else
            firstSelected->setOpen (true);
    }
}
else
{
    Component::keyPressed (key);
}

}
[/code]


#2

Ah - good one, and a nice fix! Thanks!


#3

No problem. Gotta keep your time free for toolbars. :wink:


#4