diff --git a/VoiceInk/Views/Dictionary/VocabularyView.swift b/VoiceInk/Views/Dictionary/VocabularyView.swift index 4ae3f9e..3d322fc 100644 --- a/VoiceInk/Views/Dictionary/VocabularyView.swift +++ b/VoiceInk/Views/Dictionary/VocabularyView.swift @@ -158,6 +158,8 @@ struct VocabularyView: View { do { try modelContext.save() } catch { + // Rollback the insert to maintain UI consistency + modelContext.delete(newWord) alertMessage = "Failed to add word: \(error.localizedDescription)" showAlert = true } @@ -169,6 +171,8 @@ struct VocabularyView: View { do { try modelContext.save() } catch { + // Rollback the delete to restore UI consistency + modelContext.rollback() alertMessage = "Failed to remove word: \(error.localizedDescription)" showAlert = true } diff --git a/VoiceInk/Views/Dictionary/WordReplacementView.swift b/VoiceInk/Views/Dictionary/WordReplacementView.swift index aa8aae6..7cc038d 100644 --- a/VoiceInk/Views/Dictionary/WordReplacementView.swift +++ b/VoiceInk/Views/Dictionary/WordReplacementView.swift @@ -227,6 +227,8 @@ struct WordReplacementView: View { originalWord = "" replacementWord = "" } catch { + // Rollback the insert to maintain UI consistency + modelContext.delete(newReplacement) alertMessage = "Failed to add replacement: \(error.localizedDescription)" showAlert = true } @@ -238,6 +240,8 @@ struct WordReplacementView: View { do { try modelContext.save() } catch { + // Rollback the delete to restore UI consistency + modelContext.rollback() alertMessage = "Failed to remove replacement: \(error.localizedDescription)" showAlert = true }