Deselecting SwiftUI table rows ends up only deselecting visible rows??

Folks,

I have a SwiftUI view with a fairly simple table, nothing fancy:

Table(itemsToDisplay, selection: $selectedLines, sortOrder: $sortOrder) 
	{…}

Then I have created a Deselect all command added in the Edit menu, which toggles a boolean state variable called deselect, and I've written this modifier:

.onChange(of: deselect) {_ in selectedLines = Set<TableEntry.ID>(); deselect = false}

While this correctly deselects all visible rows, it turns out the hidden rows are not deselected and show up highlighted when the table is scrolled up or down. Is that the expected behaviour? How am I supposed to deselect all rows, including the invisible ones?

Thanks a bunch! V.

P.S: I’m using the latest MacOS 13 beta SDK with the latest Xcode beta (14.1ß3)

Darn, I just realised the 'deselect = false' part can trigger a recursive call. I’m not sure that’s what causes the problem, though

No, it is not. Removing that part has no effect.

Same behaviour if the deselect state variable is transferred into an observed object. Looks like a caching side-effect.

When the Deselect all command is triggered, the selectedLines set is correctly emptied. But as soon as some hidden rows are rolled up, it gets overwritten by the view mechanism itself, I suppose.

To be honest, I have a lot of other problems with this Table, like I keep getting messages such as ‘WARNING: Application performed a reentrant operation in its NSTableView delegate. This warning will become an assert in the future’ and even crashes such as ‘[General] NSTableView error inserting/removing/moving row 18 (numberOfRows: 1).’ SwiftUI Table doesn’t seem to play well with dynamically changing contents…

Well, this is getting worse by the day. Now it crashes with errors like [General] NSTableView error inserting/removing/moving row 64 (numberOfRows: 2).

The contents of the table change dynamically according to filters (like, say, a search regex pattern). I wonder if that’s what causes the problem. I tried to synchronise every change in contents to the main thread to not interfere with view updates, but to no avail. I also have those purple messages about publishing updates within view updates, but the stack doesn’t show any of my user code, as if it was inside the underlying Cocoa library itself.

Deselecting SwiftUI table rows ends up only deselecting visible rows??
 
 
Q