[gtksourceview/wip/chergert/vim: 224/293] restrict when cursor moves when leaving visual




commit e0d4828fc3cd9a11e3c38167c2538cc37e04624d
Author: Christian Hergert <chergert redhat com>
Date:   Tue Nov 2 14:05:08 2021 -0700

    restrict when cursor moves when leaving visual
    
    If there is no selection, there is nothing to update so ignore it.
    otherwise we risk messing up selections from commands.

 gtksourceview/vim/gtk-source-vim-visual.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-visual.c b/gtksourceview/vim/gtk-source-vim-visual.c
index 157a5012..2e828907 100644
--- a/gtksourceview/vim/gtk-source-vim-visual.c
+++ b/gtksourceview/vim/gtk-source-vim-visual.c
@@ -406,24 +406,28 @@ gtk_source_vim_visual_leave (GtkSourceVimState *state)
 {
        GtkSourceVimVisual *self = (GtkSourceVimVisual *)state;
        GtkSourceBuffer *buffer;
-       GtkSourceView *view;
        GtkTextIter iter;
        GtkTextIter selection;
 
        g_assert (GTK_SOURCE_IS_VIM_VISUAL (self));
 
        buffer = gtk_source_vim_state_get_buffer (state, &iter, &selection);
-       view = gtk_source_vim_state_get_view (state);
 
-       gtk_text_view_set_overwrite (GTK_TEXT_VIEW (view), TRUE);
+       if (gtk_text_buffer_get_has_selection (GTK_TEXT_BUFFER (buffer)))
+       {
+               gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (buffer),
+                                                 &iter, self->cursor);
 
-       gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (buffer), &iter, self->cursor);
-       if (gtk_text_iter_ends_line (&iter) && !gtk_text_iter_starts_line (&iter))
-               gtk_text_iter_backward_char (&iter);
+               if (gtk_text_iter_ends_line (&iter) &&
+                   !gtk_text_iter_starts_line (&iter))
+               {
+                       gtk_text_iter_backward_char (&iter);
+               }
 
-       gtk_text_mark_set_visible (self->cursor, FALSE);
+               gtk_source_vim_state_select (state, &iter, &iter);
+       }
 
-       gtk_source_vim_state_select (state, &iter, &iter);
+       gtk_text_mark_set_visible (self->cursor, FALSE);
 }
 
 static void


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