[gtksourceview/wip/chergert/vim] update visual mode cursor visibility
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/vim] update visual mode cursor visibility
- Date: Tue, 2 Nov 2021 23:04:36 +0000 (UTC)
commit 051002163a20362333728b94b9f8da839a8a202e
Author: Christian Hergert <chergert redhat com>
Date: Tue Nov 2 16:01:02 2021 -0700
update visual mode cursor visibility
we only want this in visual-line mode and when there is not a child
state (such as insert mode).
additionally, update the value when we switch between visual and visual
line mode interactively.
gtksourceview/vim/gtk-source-vim-visual.c | 31 +++++++++++++++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-visual.c b/gtksourceview/vim/gtk-source-vim-visual.c
index 3f9f7342..f2c6f983 100644
--- a/gtksourceview/vim/gtk-source-vim-visual.c
+++ b/gtksourceview/vim/gtk-source-vim-visual.c
@@ -67,6 +67,15 @@ static gboolean key_handler_initial (GtkSourceVimVisual *self,
G_DEFINE_TYPE (GtkSourceVimVisual, gtk_source_vim_visual, GTK_SOURCE_TYPE_VIM_STATE)
+static void
+update_cursor_visible (GtkSourceVimVisual *self)
+{
+ GtkSourceVimState *child = gtk_source_vim_state_get_child (GTK_SOURCE_VIM_STATE (self));
+ gboolean is_line = self->mode == GTK_SOURCE_VIM_VISUAL_LINE;
+
+ gtk_text_mark_set_visible (self->cursor, child == NULL && is_line);
+}
+
static void
gtk_source_vim_visual_clear (GtkSourceVimVisual *self)
{
@@ -393,11 +402,13 @@ key_handler_initial (GtkSourceVimVisual *self,
case GDK_KEY_v:
self->mode = GTK_SOURCE_VIM_VISUAL_CHAR;
gtk_source_vim_visual_track_motion (self);
+ update_cursor_visible (self);
return TRUE;
case GDK_KEY_V:
self->mode = GTK_SOURCE_VIM_VISUAL_LINE;
gtk_source_vim_visual_track_motion (self);
+ update_cursor_visible (self);
return TRUE;
case GDK_KEY_U:
@@ -442,7 +453,7 @@ gtk_source_vim_visual_enter (GtkSourceVimState *state)
(gpointer *)&self->cursor);
}
- gtk_text_mark_set_visible (self->cursor, self->mode != GTK_SOURCE_VIM_VISUAL_CHAR);
+ update_cursor_visible (self);
gtk_source_vim_visual_track_motion (self);
}
@@ -485,6 +496,10 @@ gtk_source_vim_visual_resume (GtkSourceVimState *state,
g_assert (GTK_SOURCE_IS_VIM_VISUAL (self));
g_assert (GTK_SOURCE_IS_VIM_STATE (from));
+ self->handler = key_handler_initial;
+
+ update_cursor_visible (self);
+
if (GTK_SOURCE_IS_VIM_MOTION (from))
{
GtkSourceVimState *chained;
@@ -503,7 +518,18 @@ gtk_source_vim_visual_resume (GtkSourceVimState *state,
g_object_unref (chained);
}
- self->handler = key_handler_initial;
+}
+
+static void
+gtk_source_vim_visual_suspend (GtkSourceVimState *state,
+ GtkSourceVimState *to)
+{
+ GtkSourceVimVisual *self = (GtkSourceVimVisual *)state;
+
+ g_assert (GTK_SOURCE_IS_VIM_VISUAL (self));
+ g_assert (GTK_SOURCE_IS_VIM_STATE (to));
+
+ update_cursor_visible (self);
}
static void
@@ -605,6 +631,7 @@ gtk_source_vim_visual_class_init (GtkSourceVimVisualClass *klass)
state_class->enter = gtk_source_vim_visual_enter;
state_class->leave = gtk_source_vim_visual_leave;
state_class->resume = gtk_source_vim_visual_resume;
+ state_class->suspend = gtk_source_vim_visual_suspend;
state_class->repeat = gtk_source_vim_visual_repeat;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]