[gtksourceview/wip/chergert/vim: 23/73] start on insert w/ literal input
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/vim: 23/73] start on insert w/ literal input
- Date: Tue, 26 Oct 2021 23:20:36 +0000 (UTC)
commit b443594334b676e3b8eb319d09f51809f8d1d762
Author: Christian Hergert <chergert redhat com>
Date: Thu Oct 21 17:01:50 2021 -0700
start on insert w/ literal input
gtksourceview/vim/gtk-source-vim-insert.c | 134 ++++++++++++++++++++++++++++++
gtksourceview/vim/gtk-source-vim-insert.h | 2 +-
gtksourceview/vim/meson.build | 1 +
3 files changed, 136 insertions(+), 1 deletion(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-insert.c b/gtksourceview/vim/gtk-source-vim-insert.c
new file mode 100644
index 00000000..5e699ec5
--- /dev/null
+++ b/gtksourceview/vim/gtk-source-vim-insert.c
@@ -0,0 +1,134 @@
+/*
+ * This file is part of GtkSourceView
+ *
+ * Copyright 2021 Christian Hergert <chergert redhat com>
+ *
+ * GtkSourceView is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * GtkSourceView is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#include "config.h"
+
+#include "gtk-source-vim-insert.h"
+
+struct _GtkSourceVimInsert
+{
+ GtkSourceVimState parent_instance;
+ guint insert_literal : 1;
+};
+
+G_DEFINE_TYPE (GtkSourceVimInsert, gtk_source_vim_insert, GTK_SOURCE_TYPE_VIM_STATE)
+
+GtkSourceVimState *
+gtk_source_vim_insert_new (void)
+{
+ return g_object_new (GTK_SOURCE_TYPE_VIM_INSERT, NULL);
+}
+
+static gboolean
+gtk_source_vim_insert_literal (GtkSourceVimInsert *self,
+ const char *string)
+{
+ g_assert (GTK_SOURCE_IS_VIM_INSERT (self));
+ g_assert (string != NULL);
+
+ /* TODO */
+
+ return TRUE;
+}
+
+static gboolean
+gtk_source_vim_insert_handle_event (GtkSourceVimState *state,
+ GdkEvent *event)
+{
+ GtkSourceVimInsert *self = (GtkSourceVimInsert *)state;
+ GtkSourceView *view;
+ GdkModifierType mods;
+ guint keyval;
+
+ g_assert (GTK_SOURCE_IS_VIM_INSERT (self));
+ g_assert (event != NULL);
+
+ /* TODO: Eventually we'll need to stash these events for replay */
+
+ if (!(view = gtk_source_vim_state_get_view (state)))
+ return FALSE;
+
+ keyval = gdk_key_event_get_keyval (event);
+ mods = gdk_key_event_get_consumed_modifiers (event);
+
+ if (self->insert_literal)
+ {
+ self->insert_literal = FALSE;
+
+ switch (keyval)
+ {
+ case GDK_KEY_Return:
+ case GDK_KEY_KP_Enter:
+ return gtk_source_vim_insert_literal (self, "\n");
+
+ case GDK_KEY_BackSpace:
+ return gtk_source_vim_insert_literal (self, "\b");
+
+ case GDK_KEY_Tab:
+ return gtk_source_vim_insert_literal (self, "\t");
+
+ case GDK_KEY_Escape:
+ return gtk_source_vim_insert_literal (self, "\e");
+
+ default:
+ break;
+ }
+ }
+
+ /* Allow input methods to complete */
+ if (gtk_text_view_im_context_filter_keypress (GTK_TEXT_VIEW (view), event))
+ return TRUE;
+
+ /* ctrl+v to begin insert literal */
+ if (self->insert_literal == FALSE &&
+ keyval == GDK_KEY_v &&
+ ((mods & GDK_CONTROL_MASK) != 0))
+ {
+ self->insert_literal = TRUE;
+ return TRUE;
+ }
+
+ /* Pass-through to the next controller */
+
+ return FALSE;
+}
+
+static void
+gtk_source_vim_insert_dispose (GObject *object)
+{
+ G_OBJECT_CLASS (gtk_source_vim_insert_parent_class)->dispose (object);
+}
+
+static void
+gtk_source_vim_insert_class_init (GtkSourceVimInsertClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkSourceVimStateClass *state_class = GTK_SOURCE_VIM_STATE_CLASS (klass);
+
+ object_class->dispose = gtk_source_vim_insert_dispose;
+
+ state_class->handle_event = gtk_source_vim_insert_handle_event;
+}
+
+static void
+gtk_source_vim_insert_init (GtkSourceVimInsert *self)
+{
+}
diff --git a/gtksourceview/vim/gtk-source-vim-insert.h b/gtksourceview/vim/gtk-source-vim-insert.h
index 49ed3459..66749541 100644
--- a/gtksourceview/vim/gtk-source-vim-insert.h
+++ b/gtksourceview/vim/gtk-source-vim-insert.h
@@ -29,6 +29,6 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (GtkSourceVimInsert, gtk_source_vim_insert, GTK_SOURCE, VIM_INSERT, GtkSourceVimState)
-GtkSourceVimInsert *gtk_source_vim_insert_new (void);
+GtkSourceVimState *gtk_source_vim_insert_new (void);
G_END_DECLS
diff --git a/gtksourceview/vim/meson.build b/gtksourceview/vim/meson.build
index a0eb2858..9a132b33 100644
--- a/gtksourceview/vim/meson.build
+++ b/gtksourceview/vim/meson.build
@@ -2,5 +2,6 @@ vim_sources = files([
'gtk-source-vim.c',
'gtk-source-vim-command-bar.c',
'gtk-source-vim-normal.c',
+ 'gtk-source-vim-insert.c',
'gtk-source-vim-state.c',
])
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]