[gtksourceview/wip/chergert/vim] fix commands from visual
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/vim] fix commands from visual
- Date: Tue, 9 Nov 2021 01:29:10 +0000 (UTC)
commit 7fe11837363d7adeef64f9cdfbd419e0d9d8a16a
Author: Christian Hergert <chergert redhat com>
Date: Mon Nov 8 17:29:05 2021 -0800
fix commands from visual
gtksourceview/vim/gtk-source-vim-command-bar.c | 25 +++++++++++++++++++++++--
gtksourceview/vim/gtk-source-vim-command-bar.h | 9 +++++----
gtksourceview/vim/gtk-source-vim-visual.c | 15 ++++++++++++++-
gtksourceview/vim/gtk-source-vim.c | 26 +-------------------------
4 files changed, 43 insertions(+), 32 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-command-bar.c b/gtksourceview/vim/gtk-source-vim-command-bar.c
index e3bb5973..98d70465 100644
--- a/gtksourceview/vim/gtk-source-vim-command-bar.c
+++ b/gtksourceview/vim/gtk-source-vim-command-bar.c
@@ -22,6 +22,7 @@
#include "config.h"
#include "gtk-source-vim.h"
+#include "gtk-source-vim-command.h"
#include "gtk-source-vim-command-bar.h"
#define MAX_HISTORY 25
@@ -29,7 +30,7 @@
struct _GtkSourceVimCommandBar
{
GtkSourceVimState parent_instance;
- GPtrArray *history;
+ GtkSourceVimCommand *command;
GString *buffer;
int history_pos;
};
@@ -44,6 +45,14 @@ gtk_source_vim_command_bar_new (void)
return g_object_new (GTK_SOURCE_TYPE_VIM_COMMAND_BAR, NULL);
}
+GtkSourceVimState *
+gtk_source_vim_command_bar_take_command (GtkSourceVimCommandBar *self)
+{
+ g_return_val_if_fail (GTK_SOURCE_IS_VIM_COMMAND_BAR (self), NULL);
+
+ return GTK_SOURCE_VIM_STATE (g_steal_pointer (&self->command));
+}
+
static void
gtk_source_vim_command_bar_dispose (GObject *object)
{
@@ -129,6 +138,7 @@ do_execute (GtkSourceVimCommandBar *self,
const char *command)
{
GtkSourceVimState *root;
+ GtkSourceVimState *new_state;
g_assert (GTK_SOURCE_IS_VIM_COMMAND_BAR (self));
g_assert (command != NULL);
@@ -141,8 +151,19 @@ do_execute (GtkSourceVimCommandBar *self,
g_ptr_array_add (history, g_strdup (command));
root = gtk_source_vim_state_get_root (GTK_SOURCE_VIM_STATE (self));
+
if (GTK_SOURCE_IS_VIM (root))
- gtk_source_vim_emit_execute_command (GTK_SOURCE_VIM (root), command);
+ {
+ if (gtk_source_vim_emit_execute_command (GTK_SOURCE_VIM (root), command))
+ return;
+ }
+
+ if (!(new_state = gtk_source_vim_command_new_parsed (GTK_SOURCE_VIM_STATE (self), command)))
+ return;
+
+ gtk_source_vim_state_reparent (new_state, self, &self->command);
+ gtk_source_vim_state_repeat (new_state);
+ g_object_unref (new_state);
}
static gboolean
diff --git a/gtksourceview/vim/gtk-source-vim-command-bar.h b/gtksourceview/vim/gtk-source-vim-command-bar.h
index 739cccbb..d486851d 100644
--- a/gtksourceview/vim/gtk-source-vim-command-bar.h
+++ b/gtksourceview/vim/gtk-source-vim-command-bar.h
@@ -29,9 +29,10 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (GtkSourceVimCommandBar, gtk_source_vim_command_bar, GTK_SOURCE, VIM_COMMAND_BAR,
GtkSourceVimState)
-GtkSourceVimState *gtk_source_vim_command_bar_new (void);
-const char *gtk_source_vim_command_bar_get_text (GtkSourceVimCommandBar *self);
-void gtk_source_vim_command_bar_set_text (GtkSourceVimCommandBar *self,
- const char *text);
+GtkSourceVimState *gtk_source_vim_command_bar_new (void);
+GtkSourceVimState *gtk_source_vim_command_bar_take_command (GtkSourceVimCommandBar *self);
+const char *gtk_source_vim_command_bar_get_text (GtkSourceVimCommandBar *self);
+void gtk_source_vim_command_bar_set_text (GtkSourceVimCommandBar *self,
+ const char *text);
G_END_DECLS
diff --git a/gtksourceview/vim/gtk-source-vim-visual.c b/gtksourceview/vim/gtk-source-vim-visual.c
index 29128479..31f66e49 100644
--- a/gtksourceview/vim/gtk-source-vim-visual.c
+++ b/gtksourceview/vim/gtk-source-vim-visual.c
@@ -709,7 +709,20 @@ gtk_source_vim_visual_resume (GtkSourceVimState *state,
update_cursor_visible (self);
- if (from == self->command)
+ if (GTK_SOURCE_IS_VIM_COMMAND_BAR (from))
+ {
+ GtkSourceVimState *command = gtk_source_vim_command_bar_take_command
(GTK_SOURCE_VIM_COMMAND_BAR (from));
+
+ if (command != NULL)
+ {
+ gtk_source_vim_state_reparent (command, self, &self->command);
+ g_object_unref (command);
+ }
+
+ gtk_source_vim_state_unparent (from);
+ gtk_source_vim_state_pop (state);
+ }
+ else if (from == self->command)
{
gtk_source_vim_state_pop (state);
}
diff --git a/gtksourceview/vim/gtk-source-vim.c b/gtksourceview/vim/gtk-source-vim.c
index 0bcc4566..ad1cdc0c 100644
--- a/gtksourceview/vim/gtk-source-vim.c
+++ b/gtksourceview/vim/gtk-source-vim.c
@@ -71,30 +71,6 @@ gtk_source_vim_new (GtkSourceView *view)
NULL);
}
-static gboolean
-gtk_source_vim_real_execute_command (GtkSourceVim *self,
- const char *command)
-{
- GtkSourceVimState *new_state;
- GtkSourceVimState *current;
-
- g_assert (GTK_SOURCE_IS_VIM (self));
- g_assert (command != NULL);
-
- current = gtk_source_vim_state_get_current (GTK_SOURCE_VIM_STATE (self));
- new_state = gtk_source_vim_command_new_parsed (current, command);
-
- if (new_state != NULL)
- {
- gtk_source_vim_state_set_parent (new_state, current);
- gtk_source_vim_state_repeat (new_state);
- gtk_source_vim_state_unparent (new_state);
- return TRUE;
- }
-
- return FALSE;
-}
-
static gboolean
gtk_source_vim_handle_event (GtkSourceVimState *state,
GdkEvent *event)
@@ -327,7 +303,7 @@ gtk_source_vim_class_init (GtkSourceVimClass *klass)
g_signal_new_class_handler ("execute-command",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
- G_CALLBACK (gtk_source_vim_real_execute_command),
+ NULL,
g_signal_accumulator_true_handled, NULL,
NULL,
G_TYPE_BOOLEAN,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]