Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DocumentFilter: Why is replace() invoked and not insertString()?

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?

like image 426
Aviv Cohn Avatar asked May 07 '14 18:05

Aviv Cohn


People also ask

What is a documentfilter?

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.

What happens when a document containing a documentfilter is modified?

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.

Can the documentfilter callback into the filterbypass multiple times?

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.

Does ivsfindtarget work in vs2019?

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.


1 Answers

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.

like image 133
camickr Avatar answered Oct 17 '22 17:10

camickr