Skip to content

Excessive reloadItems in OutlineViewUpdater #16

@RCCoop

Description

@RCCoop

I discovered a possible bug while trying to debug another issue I was running into, where pressing 'enter' on a row with editable content was not enabling text editing (very similar to this StackOverflow question). I found that every time the NSOutlineView's selection changed, every unexpanded item visible in the view was being reloaded. This was happening in the following point of OutlineViewUpdater.performUpdates:

if !diff.isEmpty || oldIDs != newIDs {
    // Parent needs to be updated as the children have changed.
    // Children are not reloaded to allow animation.
    outlineView.reloadItem(parent, reloadChildren: false)
}

I'm not sure if excessive reloading could cause any other problems besides blocking the 'enter' key behavior.

In trying to fix the 'enter' issue, the suggested fix from the SO post (calling reloadData(forRowIndexes:columnIndexes:) didn't work, so I tried changing the above code from OutlineViewUpdater to this:

if !diff.isEmpty || oldIDs != newIDs {
    // Parent needs to be updated as the children have changed.
    // Children are not reloaded to allow animation.
    let row = outlineView.row(forItem: parent)
    let oldParentValue = outlineView.item(atRow: row) as? OutlineViewItem<Data>
    if oldParentValue != parent {
        outlineView.reloadItem(parent, reloadChildren: false)
    }
}

That fixed the problem, and resulted in reloadItem not being called so frequently, but did cause OutlineViewUpdaterTests to fail-- outlineView.reloadedItems came out as [0, 1, 3, 6] instead of the expected [nil, 0, 1, 3, 6].

It seems to me that not reloading nil in the test case is probably fine, since reloadItem(nil) causes the entire NSOutlineView's contents to be reloaded, and I don't think that's what we want in the OutlineViewUpdater. But that change of code could lead to other problems. Since equality between oldParentValue and parent is determined by id rather than more detailed equality checks, updating data externally could lead to some rows not being updated (say, if you change the name of an item but not its id). So I'm a bit stumped on what the best way of dealing with this should be. Maybe nothing, unfortunately.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions