Updating EditButton

I am trying to update the EditButton after deleting rows in a List, but its title doesn't change. I have sent an update event via a publisher that applies the mode change based on the number of items remaining in the list. Here's the update event handler:

        .onReceive(updateViewPublisher, perform: { _ in
          self.editMode?.wrappedValue = textFileData.textFiles.count == 0 ? .inactive : .active
          update += 1
        })```

The edit mode is changed to inactive when the list is empty, but the button continues to display 'done'. If I adda new list item it remains set to 'done' and the delete control is displayed against the new item.

I have seen loads of posts about this on various sites, but no solutions. I am trying this on Xcode 16.2 and IOS 18.2. If someone from Apple sees this, a reply would be most welcome. 

This thread may provide some hints:

https://www.hackingwithswift.com/forums/swiftui/list-view-stuck-in-edit-mode/7401

It tested this, which apparently does what you need:

struct ContentView: View {   
    @State private var selects: Set<Int> = []
    @State var range = [1, 2, 3 ,4, 5]
    @Environment(\.editMode) var editMode

    var body: some View {
        VStack{
            EditButton()
            List(selection: $selects){
                ForEach(range, id: \.self) { 
                    ItemInList(num: $0)
                }
                .onDelete {
                    range.remove(atOffsets: $0)
                    editMode?.wrappedValue = .inactive
                }
            }
            .listStyle(PlainListStyle())
        }
    }

}

Thanks for your answer. There is still a problem if you allow additions to the list as in the post you provided. If you delete all the entries the edit button still displays 'done' when I think it should either be hidden or reset to 'edit'. If you don't tap on 'done' and add a new item then this will be displayed with the delete button visible. I can find no way to reset the edit button and think this is a bug in iOS.

Updating EditButton
 
 
Q