I am tracking if document is modified by user so that I can append the text "(modified)" to the form's title, and also to prompt the user to save the modified document. My code also changes the document, but this is not a modification that the user should be concerned with. TextChanged event is alas raised in both cases. So I introduced a flag that means "ignore TextChanged event once". If in event handler the flag is set then just reset it. Otherwise update the form's title.
And now I've added default footer with code, in the same place where all other code changes to the document are made. This causes two events to fire, instead of just one. And now my document is marked as modified from the start. I could change the meaning of the introduced flag to mean "ignore TextChanged event twice", but that now just feels like a hack. Is there a "proper" way to track user's changes and not track changes from the code?