Menu

HighlightTextRenderer is tightly coupled with TextMatchFilter

2018-02-13
2018-06-05
  • Dialecticus

    Dialecticus - 2018-02-13

    I wanted to tweak TextMatchFilter to match all given strings, instead of any. Had to copy its code, instead of inheriting it, because MatchingStrategies property is private. So I copied the code, changed it, and my new filtering works.

    But I lost text highlighting. Looking through code I found that HighlightTextRenderer has Filter property of type TextMatchFilter. I propose that this property should be of some interface type that any filter could implement, including TextMatchFilter.

    I guess I can make a custom renderer, and I probably will using copy/paste/tweak strategy as before, but it feels like I shouldn't have to.

     
  • Phillip Piper

    Phillip Piper - 2018-05-01

    I have added an ITextMatchFilter so your re-implementation will operate.

    I've made MatchingStrategies protected so you can access it in subclasses.

    I've also made the various strategies public so you can subclass them as you wish.

    All these changes have been checked into the SF repo.

     
    • Ulrich Bayer

      Ulrich Bayer - 2018-06-05

      Thanks for the modification! That helped me as well.
      I noticed that you also need to change the implementation of HighlightTextRenderer.RegisterNewFilter to use ITextMatchFilter instead of TextMatchFilter. Otherwise an object implementing ITextMatchFilter will never be installed in HighlightTextRenderer.
      For me the following code works:

              internal void RegisterNewFilter(IModelFilter newFilter) {
                  ITextMatchFilter textFilter = newFilter as ITextMatchFilter;
                  if (textFilter != null)
                  {
                      Filter = textFilter;
                      return;
                  }
                  CompositeFilter composite = newFilter as CompositeFilter;
                  if (composite != null)
                  {
                      foreach (ITextMatchFilter textSubFilter in composite.TextFilters)
                      {
                          Filter = textSubFilter;
                          return;
                      }
                  }
                  Filter = null; 
              } 
      
       

      Last edit: Ulrich Bayer 2018-06-05

Log in to post a comment.