File tree Expand file tree Collapse file tree 2 files changed +10
-0
lines changed
code/frontend/MakeItSo/Shared
Features/TaskList/ViewModels Expand file tree Collapse file tree 2 files changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import SwiftUI
2121
2222/// Used to manage focus in a `List` view
2323enum Focusable : Hashable {
24+ case none
2425 case row( id: String )
2526}
2627
Original file line number Diff line number Diff line change @@ -81,6 +81,15 @@ class TasksListViewModel: ObservableObject {
8181 // if any row is focused, insert the new task after the focused row
8282 if case . row( let id) = focusedTask {
8383 if let index = tasks. firstIndex ( where: { $0. id == id } ) {
84+
85+ // If the currently selected task is empty, unfocus it.
86+ // This will kick off the pipeline that removes empty tasks.
87+ let currentTask = tasks [ index]
88+ guard !currentTask. title. isEmpty else {
89+ focusedTask = Focusable . none
90+ return
91+ }
92+
8493 tasks. insert ( newTask, at: index + 1 )
8594 }
8695 }
You can’t perform that action at this time.
0 commit comments