I've implemented a DocumentFilter
subclass, and when I type text into the JTextComponent
, the replace()
method of the filter is invoked, and not insertString()
(which is never invoked). Any idea why that is?
DocumentFilter, as the name implies, is a filter for the Document mutation methods. When a Document containing a DocumentFilter is modified (either through insert or remove ), it forwards the appropriate method invocation to the DocumentFilter. The default implementation allows the modification to occur.
When a Document containing a DocumentFilter is modified (either through insert or remove ), it forwards the appropriate method invocation to the DocumentFilter. The default implementation allows the modification to occur.
When remove or insertString is invoked on the DocumentFilter, the DocumentFilter may callback into the FilterBypass multiple times, or for different regions, but it should not callback into the FilterBypass after returning from the remove or insertString method.
It works in VS2019. We have implemented IVsFindTarget for our editor. In fact, once I click Find Next, none of the IVsFindTarget methods are getting hit and it is not able to find the search word from the text. Ideally when I click Find Next, IVsFindTarget.Find method should be invoked. Please correct me if I am wrong.
The insertString(...)
method is invoked when you update the Document directly, by using the Document.insertString(...) method.
The replace(...)
method is invoked when the Document is updated by methods of the View (ie. the JTextField) when the user enters text or the user invokes Actions (cut, paste) associated with the text field.
I guess its is easier to always to a replace and then let the replace logic check to see if remove/insert is required.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With