After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 390048 - Entire word search flag
Entire word search flag
Status: RESOLVED FIXED
Product: gtksourceview
Classification: Platform
Component: General
unspecified
Other All
: Normal enhancement
: ---
Assigned To: GTK Sourceview maintainers
GTK Sourceview maintainers
Depends on:
Blocks: 701466
 
 
Reported: 2006-12-27 16:17 UTC by Blake Madden
Modified: 2013-07-08 21:40 UTC
See Also:
GNOME target: ---
GNOME version: Unversioned Enhancement


Attachments
Patch for header file (454 bytes, patch)
2006-12-27 16:20 UTC, Blake Madden
none Details | Review
Patch for source file (1.47 KB, patch)
2006-12-27 16:21 UTC, Blake Madden
none Details | Review
GtkTextIter: add GTK_TEXT_SEARCH_ENTIRE_WORD_ONLY flag (20.04 KB, patch)
2013-06-16 19:39 UTC, Sébastien Wilmet
none Details | Review
Improve doc of gtk_text_iter_forward_search() (1.28 KB, patch)
2013-06-20 10:13 UTC, Sébastien Wilmet
committed Details | Review
Document GtkTextSearchFlags (2.51 KB, patch)
2013-06-25 10:17 UTC, Sébastien Wilmet
committed Details | Review

Description Blake Madden 2006-12-27 16:17:14 UTC
Patch that adds a new flag, GTK_TEXT_SEARCH_TEXT_WHOLE_WORD, to GtkTextSearchFlags.  If you add this to the flag argument to gtk_text_iter_forward_search or gtk_text_iter_backward_search then it will only match if the beginning and ending iterators begin and end a word, respectively.
Comment 1 Blake Madden 2006-12-27 16:20:35 UTC
Created attachment 78946 [details] [review]
Patch for header file
Comment 2 Blake Madden 2006-12-27 16:21:43 UTC
Created attachment 78947 [details] [review]
Patch for source file
Comment 3 Sébastien Wilmet 2013-06-16 19:39:13 UTC
Created attachment 246979 [details] [review]
GtkTextIter: add GTK_TEXT_SEARCH_ENTIRE_WORD_ONLY flag

Create the forward_search() and backward_search() functions, that
doesn't take the new flag into account, so it is mainly a copy/paste
from the previous code of gtk_text_iter_forward_search() and
gtk_text_iter_backward_search(). The parameters are slightly different,
to avoid recomputing the same thing at each call.

So to check if the match is an entire word, we first do a normal search
(with the other flags), and then we check if it's an entire word. There
is a loop to search the next normal match if the match was not an entire
word.

This permits to not complicate further forward_search() and
backward_search().

Another thing, part of the documentation has been moved to the enum,
which is a better place IMHO.

And unit tests have been written for the new flag.
Comment 4 Sébastien Wilmet 2013-06-16 19:46:59 UTC
To give a bit context, ENTIRE_WORD_ONLY comes from gedit. We are planning to add a higher-level API for the search and replace in GtkSourceView (bug #701466). By fixing this bug, we avoid the need for another enum in GtkSourceView.
Comment 5 Sébastien Wilmet 2013-06-20 10:13:12 UTC
Created attachment 247305 [details] [review]
Improve doc of gtk_text_iter_forward_search()

While I'm at it.

It was not possible to know if the @limit was for @match_start or
@match_end. It was documented for backward_search(), but not for
forward_search().
Comment 6 Ignacio Casal Quinteiro (nacho) 2013-06-20 10:30:13 UTC
Review of attachment 247305 [details] [review]:

Looks good to me.
Comment 7 Sébastien Wilmet 2013-06-22 07:37:33 UTC
Move GtkTextView -> GtkSourceView. The plan is to have other search flags in gsv.
Comment 8 Paolo Borelli 2013-06-22 09:53:45 UTC
I agree that gsv should have its own enum as long as it has extra features, but still patch in comment 3 makes sense to me and looks good at a glance and the api addition is minimal (just one enum value), so unless gtk maintainers object I would still like see it go there
Comment 9 Sébastien Wilmet 2013-06-22 15:37:59 UTC
Summary of the discussion on IRC:

With the regex search (bug #134674), it would be possible to match at word boundaries with a regex like "\bgtk_foo\b". It will match "gtk_foo", but not "gtk_foobar".

So with the regex search, it is really easy to implement the "entire word" search flag. And maybe a better name is GTK_TEXT_SEARCH_AT_WORD_BOUNDARIES, because "entire word" can span multiple words, it's confusing.

If GTK_TEXT_SEARCH_AT_WORD_BOUNDARIES exists, it is only for convenience. If the regex search is implemented in gtk+, we can just document the \b trick, and add the convenience flag in gsv.
Comment 10 Sébastien Wilmet 2013-06-22 15:39:33 UTC
And the link:

http://www.regular-expressions.info/wordboundaries.html
Comment 11 Sébastien Wilmet 2013-06-25 10:17:37 UTC
Created attachment 247716 [details] [review]
Document GtkTextSearchFlags

Extract from the previous patch the move of the documentation.

Move the doc about the flags from gtk_text_iter_forward_search() to the
enum.
Comment 12 Ignacio Casal Quinteiro (nacho) 2013-06-25 10:23:19 UTC
Review of attachment 247716 [details] [review]:

Looks good.
Comment 13 Sébastien Wilmet 2013-07-08 21:40:32 UTC
Implemented in GtkSourceView, with the "search-at-word-boundaries" property in GtkSourceBuffer.