Closed pradeepb28 closed 5 months ago
You would have to do this yourself. You could add a onChange
listener for the source of the list, and whenever it changes, check if any keyboard names were removed, and then call KeyboardShortcuts.reset()
.
I feel like I understand and didn't understand at the same time :)
Probably I will give a detailed example, how I want to use in my app.
How would I approach this? Does my flow actually works or do you have any recommendations to approach it differently?
Thank you :) @sindresorhus
Listen to Core Data entities being deleted and then delete the KeyboardShortcuts storage.
This is what I do in one of my apps:
struct Folder: Defaults.Serializable {
let id: UUID
var title: String?
}
extension Folder {
var toggleMenuShortcutName: KeyboardShortcuts.Name { .init(id.uuidString) }
}
extension Folder {
func remove() {
KeyboardShortcuts.reset(toggleMenuShortcutName)
Defaults[.folders] = Defaults[.folders].identifiableRemovingAll(self)
}
}
I am trying to understand how can we set keyboard shortcut item for a dynamic list item here https://github.com/sindresorhus/KeyboardShortcuts/blob/main/Example/KeyboardShortcutsExample/MainScreen.swift#L31
Is it possible to delete the keyboard shortcut when an item in dynamic list is deleted? If so, it would really helpful if you have an example for that.