## Root cause The `dirty` flag is set to `true` immediately when the user interacts with the text fields, even before any actual text is entered. This happens because the `set` closure in the `Binding` for both `draftTitle` and `draftBody` sets `model.dirty = true` unconditionally, without checking if the new value differs from the old value. ## Fix ```swift struct EditPane: View { @ObservedObject var model: LibraryModel var body: some View { TextField("", text: Binding( get: { model.draftTitle }, set: { newValue in if model.draftTitle != newValue { model.draftTitle = newValue model.dirty = true } })) TextEditor(text: Binding( get: { model.draftBody }, set: { newValue in if model.draftBody != newValue { model.draftBody = newValue model.dirty = true } })) } } ``` ## Tests ```swift import XCTest @testable import YourAppModule // Replace with actual module name class LibraryModelTests: XCTestCase { func testDirtyFlagNotSetOnInitialTextEntry() { let model = LibraryModel() model.draftTitle = "Old Title" model.draftBody = "Old Body" // Simulate user typing the same text as current draft model.draftTitle = "Old Title" model.draftBody = "Old Body" // Verify dirty flag is not set XCTAssertFalse(model.dirty, "Dirty flag should not be set when no actual changes are made") } func testDirtyFlagSetOnActualTextChange() { let model = LibraryModel() model.draftTitle = "Old Title" model.draftBody = "Old Body" // Simulate user typing a different text model.draftTitle = "New Title" model.draftBody = "New Body" // Verify dirty flag is set XCTAssertTrue(model.dirty, "Dirty flag should be set when actual changes are made") } } ``` ## Verification - Input: User types "Old Title" into the title field (same as current draft) - Before fix: `dirty` is set to `true` even though no actual change occurred - After fix: `dirty` remains `false` because the text is identical to the current draft ## Notes The fix assumes that the `current` property in `LibraryModel` is properly set and that the `draftTitle` and `draftBody` are initialized with the current prompt values. The test cases cover the core behavior of the bug: preventing the dirty flag from being set on identical text entries. The fix is minimal and only changes the comparison logic in the binding setters.