GNOME Bugzilla – Bug 743668
more vim compliant search behavior
Last modified: 2015-01-29 10:18:58 UTC
So I've been using gnome-builder fairly regularly now instead of vim and an issue I've bumped into is the lack of certain search features like '?' and 'n'. In particular I normally use 'n' after doing '*', instead of pressing '*' multiple times. I've attempted to add those features with the below patchset. The features seem to work okay with light testing, but I haven't used them "in production" yet, so they might still have niggling issues.
Created attachment 295694 [details] [review] editor: add search-direction property This commit adds a search-direction property that tracks the direction the document is being searched. This change is a necessary prerequisite for follow-up fixes.
Created attachment 295695 [details] [review] editor: don't wrap manually when searching GtkSourceSearchSettings natively supports wrapping when searching if the wrap-around property is set to TRUE. gb_editor_frame_move_next_match wraps around manually. This commit deletes the manual code and just sets wrap-around to TRUE.
Created attachment 295696 [details] [review] editor: add rubberbanding argument to move_previous_match gb_editor_frame_move_next_match() supports "rubberbanding" (the ability to stay stationed on a match as the user types more and more matching characters, with the ability to abort the operation without moving via the escape key), but gb_editor_frame_move_previous_match() doesn't. We're ultimately going to need that functionality for matching backwards, too, to get optimal search behavior. This commit implements both functions in terms of a common gb_editor_frame_match() function that takes an additional "direction" argument, and adds a "rubberbanding" argument to the gb_editor_frame_move_previous_match function.
Created attachment 295697 [details] [review] editor: consistently match in current direction of search There are parts of the code that neglect to consult the current search direction when deciding which way to match, and instead just unconditionally match forward. This commit fixes those places in the code.
Created attachment 295698 [details] [review] vim: add search direction to begin-search signal This commit adds the search direction to the begin-search signal. It will be necessary for implementing the '?' command.
Created attachment 295699 [details] [review] vim: implement '?' command The '?' command is just like the '/' but in reverse. This commit adds support for it.
Created attachment 295700 [details] [review] vim: expose search text as a property This commit exposes the search text generated from the '*' command as a property on the vim object. This change is necessary as a prerequisite for adding support for the 'n' command, which will happen in a subsequent commit.
Created attachment 295701 [details] [review] vim: save search direction We're going to need the search direction to implement the 'n' command, since the 'n' command replays the last search in the direction of the last search. This commit saves the search direction from the '*' and '#' commands in a new search-direction property on the vim object.
Created attachment 295702 [details] [review] vim: sync search text and direction from outside searches This commit saves the text and direction for searches initiated from the view/frame on the vim object. This change will be necessary for implementing the 'n' command, since the 'n' command needs to replay the last search (be it from '*', '/' or the menu).
Created attachment 295703 [details] [review] vim: implement 'n' and 'N' commands This commit implements the 'n' (and 'N') command to replay the last search and jump to the next (or previous respectively) result.
These all seem to work pretty well for me now, thanks for implementing them! If we find any bugs in this we can deal with them on a case by case basis in new bugs. Attachment 295694 [details] pushed as b93676e - editor: add search-direction property Attachment 295695 [details] pushed as 0c586b8 - editor: don't wrap manually when searching Attachment 295696 [details] pushed as b2014c9 - editor: add rubberbanding argument to move_previous_match Attachment 295697 [details] pushed as 9eeec89 - editor: consistently match in current direction of search Attachment 295698 [details] pushed as 871b3ae - vim: add search direction to begin-search signal Attachment 295699 [details] pushed as 18dc0d9 - vim: implement '?' command Attachment 295700 [details] pushed as cff18d5 - vim: expose search text as a property Attachment 295701 [details] pushed as ac5a386 - vim: save search direction Attachment 295702 [details] pushed as ce4a14b - vim: sync search text and direction from outside searches Attachment 295703 [details] pushed as 0e109e1 - vim: implement 'n' and 'N' commands