[gtksourceview] vim: extend selection when in visual



commit 5f4c9e4559614c031c5e4bbeacd7a7ce46543ebb
Author: Christian Hergert <chergert redhat com>
Date:   Fri Nov 12 16:16:31 2021 -0800

    vim: extend selection when in visual
    
    Searching for a word while in Visual mode should extend the selection to
    that word. Previously this would return to Normal mode.

 gtksourceview/vim/gtksourcevimcommand.c | 33 +++++++++++++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)
---
diff --git a/gtksourceview/vim/gtksourcevimcommand.c b/gtksourceview/vim/gtksourcevimcommand.c
index cd86ea8b..f677c9df 100644
--- a/gtksourceview/vim/gtksourcevimcommand.c
+++ b/gtksourceview/vim/gtksourcevimcommand.c
@@ -37,6 +37,7 @@
 #include "gtksourcevimcommand.h"
 #include "gtksourcevimjumplist.h"
 #include "gtksourcevimregisters.h"
+#include "gtksourcevimvisual.h"
 
 typedef void (*Command) (GtkSourceVimCommand *self);
 
@@ -691,7 +692,21 @@ gtk_source_vim_command_search (GtkSourceVimCommand *self)
        if (gtk_source_search_context_forward (context, &iter, &match, NULL, NULL))
        {
                gtk_source_vim_state_push_jump (GTK_SOURCE_VIM_STATE (self), &iter);
-               gtk_text_buffer_select_range (GTK_TEXT_BUFFER (buffer), &match, &match);
+
+               if (GTK_SOURCE_IN_VIM_VISUAL (self))
+               {
+                       GtkSourceVimState *visual;
+
+                       visual = gtk_source_vim_state_get_ancestor (GTK_SOURCE_VIM_STATE (self),
+                                                                   GTK_SOURCE_TYPE_VIM_VISUAL);
+                       gtk_source_vim_visual_warp (GTK_SOURCE_VIM_VISUAL (visual), &match);
+                       gtk_source_vim_visual_ignore_command (GTK_SOURCE_VIM_VISUAL (visual));
+               }
+               else
+               {
+                       gtk_text_buffer_select_range (GTK_TEXT_BUFFER (buffer), &match, &match);
+               }
+
                gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (view), &match, 0.25, TRUE, 1.0, 0.0);
 
                self->ignore_mark = TRUE;
@@ -742,7 +757,21 @@ gtk_source_vim_command_search_reverse (GtkSourceVimCommand *self)
        if (gtk_source_search_context_backward (context, &iter, &match, NULL, NULL))
        {
                gtk_source_vim_state_push_jump (GTK_SOURCE_VIM_STATE (self), &iter);
-               gtk_text_buffer_select_range (GTK_TEXT_BUFFER (buffer), &match, &match);
+
+               if (GTK_SOURCE_IN_VIM_VISUAL (self))
+               {
+                       GtkSourceVimState *visual;
+
+                       visual = gtk_source_vim_state_get_ancestor (GTK_SOURCE_VIM_STATE (self),
+                                                                   GTK_SOURCE_TYPE_VIM_VISUAL);
+                       gtk_source_vim_visual_warp (GTK_SOURCE_VIM_VISUAL (visual), &match);
+                       gtk_source_vim_visual_ignore_command (GTK_SOURCE_VIM_VISUAL (visual));
+               }
+               else
+               {
+                       gtk_text_buffer_select_range (GTK_TEXT_BUFFER (buffer), &match, &match);
+               }
+
                gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (view), &match, 0.25, TRUE, 1.0, 0.0);
 
                self->ignore_mark = TRUE;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]