Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Excessive reloadItems in OutlineViewUpdater #16

Open
RCCoop opened this issue Apr 5, 2023 · 0 comments
Open

Excessive reloadItems in OutlineViewUpdater #16

RCCoop opened this issue Apr 5, 2023 · 0 comments

Comments

@RCCoop
Copy link
Contributor

RCCoop commented Apr 5, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant