Search and replace in gedit and GtkSourceView

My GSoC on GtkSourceView/gedit/… is coming along nicely. Here is a screenshot of the new search in gedit:

New gedit search

New gedit search

The visible new thing is the “298 of 703″ in the search entry, that shows the position of the current search match, and the total number of occurrences. This is just the tip of the iceberg, as much of the work has been done under the hood. Ignacio (nacho), my mentor, has improved GdTaggedEntry, and I worked on the new API in GtkSourceView, and adapted gedit to use the new API.

Note: almost all my work has already been merged upstream, but not the new search entry.

Search and replace API in GtkSourceView

The new API in GtkSourceView is available. One thing is missing though: regex search.

Why you should use this API:

  • It is asynchronous, i.e. the user interface is normally not blocked when the GtkTextBuffer is scanned. And the asynchronous overhead is small;
  • The search matches are highlighted;
  • You can get the total number of occurrences and the position of a certain occurrence easily;
  • For each search, the buffer is scanned at most once. Once the search occurrences are found, navigating through them doesn’t require to re-scan the buffer, thanks to gtk_text_iter_forward_to_tag_toggle(). As a result, most operations are really fast;
  • The regex search (still to come) will normally do multi-segment matching, also called incremental matching: when a partial match is returned, we take a bigger segment. No need to waste memory space to retrieve the entire buffer contents.

Nice, isn’t it?

7 Responses to “Search and replace in gedit and GtkSourceView”

  1. andrewsomething says:

    This is great. I’ve been missing this.

  2. nacho says:

    I wonder if we should just kill the secondary button from the entry. Right now it takes too much space and I do not like it having it before the number of occurrences found. Good job BTW!

    • swilmet says:

      The clear button is useful in my opinion. When the regex search is finished I can maybe try to have the tags before the secondary icon, with a new option. But we move away from the original GdTaggedEntry.

  3. Thomas Andersen says:

    Very nice!

  4. Arien Dorsaz says:

    Hello!

    Great, I hope you’ll be able to implement regexp search, it’s so usefull in Geany to be able to search on regexp and replace too.

    Thanks for your work !

    I’ve a little suggestion : in the search input, I’d place the items in this order :

    For me, it seems more natural to have the erase icon on right most, but it’s only a matter of taste and color ;) This tool will be already useful !

  5. Nice ! I was expecting gedit would come a little closer to, for example, what Notepad can do. Good luck for your work, it’ll be appreciated by a lot of people :)