Well, this is 7th edition of this excellent book and someone should have already highlighted that when a filter of DocumentFilter class works
1) replace() is called most of the time on user’s interaction with e.g. text field, not just when ‘text is selected and replaced’ but also on regular input and
2) contrary to what can be concluded from previous paragraph (it may mislead), insertString() is called on text inserted to document on construction of the e.g. text field object (as constructor parameter) or ‘injected’ to document by document.insertString()
Have a look at the original text would you think it shows clear understanding of the process? What do you think, am I too sensitive on this? I found this pretty confusing.