[gtksourceview/wip/chergert/vim] stub out entering/leaving visual mode
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/vim] stub out entering/leaving visual mode
- Date: Sat, 30 Oct 2021 00:43:04 +0000 (UTC)
commit 1234ad508f0156a99efd757139294bd6e8a4ec28
Author: Christian Hergert <chergert redhat com>
Date: Fri Oct 29 17:42:51 2021 -0700
stub out entering/leaving visual mode
gtksourceview/vim/gtk-source-vim-normal.c | 39 +++++++++++++++++++------------
gtksourceview/vim/gtk-source-vim-visual.c | 22 +++++++++++++++++
2 files changed, 46 insertions(+), 15 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-normal.c b/gtksourceview/vim/gtk-source-vim-normal.c
index 12f27d98..ee6681f9 100644
--- a/gtksourceview/vim/gtk-source-vim-normal.c
+++ b/gtksourceview/vim/gtk-source-vim-normal.c
@@ -29,6 +29,7 @@
#include "gtk-source-vim-motion.h"
#include "gtk-source-vim-normal.h"
#include "gtk-source-vim-replace.h"
+#include "gtk-source-vim-visual.h"
#define REPLAY(_block) do { _block; } while (--self->count > 0);
@@ -229,6 +230,23 @@ gtk_source_vim_normal_begin_command (GtkSourceVimNormal *self,
gtk_source_vim_state_pop (GTK_SOURCE_VIM_STATE (command));
}
+static void
+gtk_source_vim_normal_begin_visual (GtkSourceVimNormal *self,
+ GtkSourceVimVisualMode mode)
+{
+ GtkSourceVimState *visual;
+ int count;
+
+ g_assert (GTK_SOURCE_IS_VIM_NORMAL (self));
+
+ count = self->count, self->count = 0;
+
+ visual = gtk_source_vim_visual_new (mode);
+ gtk_source_vim_state_set_count (visual, count);
+
+ gtk_source_vim_state_push (GTK_SOURCE_VIM_STATE (self), visual);
+}
+
static void
go_backward_char (GtkSourceVimNormal *self)
{
@@ -672,18 +690,6 @@ key_handler_split (GtkSourceVimNormal *self,
return TRUE;
}
-static gboolean
-key_handler_visual (GtkSourceVimNormal *self,
- guint keyval,
- guint keycode,
- GdkModifierType mods,
- const char *string)
-{
- g_assert (GTK_SOURCE_IS_VIM_NORMAL (self));
-
- return TRUE;
-}
-
static gboolean
key_handler_increment (GtkSourceVimNormal *self,
guint keyval,
@@ -771,8 +777,8 @@ key_handler_initial (GtkSourceVimNormal *self,
break;
case GDK_KEY_v:
- self->handler = key_handler_visual;
- break;
+ gtk_source_vim_normal_begin_visual (self, GTK_SOURCE_VIM_VISUAL_BLOCK);
+ return TRUE;
case GDK_KEY_w:
self->handler = key_handler_split;
@@ -914,8 +920,11 @@ key_handler_initial (GtkSourceVimNormal *self,
return TRUE;
case GDK_KEY_v:
+ gtk_source_vim_normal_begin_visual (self, GTK_SOURCE_VIM_VISUAL_CHAR);
+ break;
+
case GDK_KEY_V:
- self->handler = key_handler_visual;
+ gtk_source_vim_normal_begin_visual (self, GTK_SOURCE_VIM_VISUAL_LINE);
break;
default:
diff --git a/gtksourceview/vim/gtk-source-vim-visual.c b/gtksourceview/vim/gtk-source-vim-visual.c
index 4190ad21..83bbca26 100644
--- a/gtksourceview/vim/gtk-source-vim-visual.c
+++ b/gtksourceview/vim/gtk-source-vim-visual.c
@@ -57,6 +57,27 @@ gtk_source_vim_visual_get_command_bar_text (GtkSourceVimState *state)
}
}
+static gboolean
+gtk_source_vim_visual_handle_keypress (GtkSourceVimState *state,
+ guint keyval,
+ guint keycode,
+ GdkModifierType mods,
+ const char *string)
+{
+ GtkSourceVimVisual *self = (GtkSourceVimVisual *)state;
+
+ g_assert (GTK_SOURCE_IS_VIM_VISUAL (state));
+
+ /* Leave insert mode if Escape/ctrl+[ was pressed */
+ if (gtk_source_vim_state_is_escape (keyval, mods))
+ {
+ gtk_source_vim_state_pop (GTK_SOURCE_VIM_STATE (self));
+ return TRUE;
+ }
+
+ return TRUE;
+}
+
static void
gtk_source_vim_visual_dispose (GObject *object)
{
@@ -72,6 +93,7 @@ gtk_source_vim_visual_class_init (GtkSourceVimVisualClass *klass)
object_class->dispose = gtk_source_vim_visual_dispose;
state_class->get_command_bar_text = gtk_source_vim_visual_get_command_bar_text;
+ state_class->handle_keypress = gtk_source_vim_visual_handle_keypress;
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]