[gtksourceview] vim: make registers shared between views
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] vim: make registers shared between views
- Date: Wed, 18 May 2022 10:45:01 +0000 (UTC)
commit 83bd6880fc06775faa7131dd015fd83b0d5cb7c3
Author: Christian Hergert <chergert redhat com>
Date: Wed May 18 03:43:54 2022 -0700
vim: make registers shared between views
These need to be shared so that you can yank/paste between views without
having to go to the system clipboard.
gtksourceview/vim/gtksourcevimstate.c | 26 ++++++++------------------
gtksourceview/vim/gtksourcevimstate.h | 2 +-
gtksourceview/vim/gtksourcevimtexthistory.c | 2 +-
testsuite/test-vim-input.c | 3 +++
4 files changed, 13 insertions(+), 20 deletions(-)
---
diff --git a/gtksourceview/vim/gtksourcevimstate.c b/gtksourceview/vim/gtksourcevimstate.c
index 530e50c0..50b1e005 100644
--- a/gtksourceview/vim/gtksourcevimstate.c
+++ b/gtksourceview/vim/gtksourcevimstate.c
@@ -36,8 +36,7 @@
typedef struct
{
- /* Owned reference to marks/registers (usually set low in the stack) */
- GtkSourceVimState *registers;
+ /* Owned reference to marks/etc (usually set low in the stack) */
GtkSourceVimState *marks;
GtkSourceVimState *jumplist;
@@ -94,6 +93,7 @@ enum {
};
static GParamSpec *properties [N_PROPS];
+static GtkSourceVimState *shared_registers;
void
gtk_source_vim_state_keyval_unescaped (guint keyval,
@@ -299,7 +299,6 @@ gtk_source_vim_state_dispose (GObject *object)
g_clear_object (&priv->search_context);
g_clear_object (&priv->search_settings);
- gtk_source_vim_state_release (&priv->registers);
gtk_source_vim_state_release (&priv->marks);
gtk_source_vim_state_release (&priv->jumplist);
@@ -1085,23 +1084,14 @@ gtk_source_vim_state_set_can_repeat (GtkSourceVimState *self,
}
GtkSourceVimState *
-gtk_source_vim_state_get_registers (GtkSourceVimState *self)
+gtk_source_vim_state_get_registers (void)
{
- GtkSourceVimStatePrivate *priv;
- GtkSourceVimState *root;
-
- g_return_val_if_fail (GTK_SOURCE_IS_VIM_STATE (self), NULL);
-
- root = gtk_source_vim_state_get_root (self);
- priv = gtk_source_vim_state_get_instance_private (root);
-
- if (priv->registers == NULL)
+ if (shared_registers == NULL)
{
- priv->registers = gtk_source_vim_registers_new ();
- gtk_source_vim_state_set_parent (priv->registers, GTK_SOURCE_VIM_STATE (root));
+ shared_registers = gtk_source_vim_registers_new ();
}
- return priv->registers;
+ return shared_registers;
}
const char *
@@ -1147,7 +1137,7 @@ gtk_source_vim_state_get_current_register_value (GtkSourceVimState *self)
g_return_val_if_fail (GTK_SOURCE_IS_VIM_STATE (self), NULL);
current_register = gtk_source_vim_state_get_current_register (self);
- registers = gtk_source_vim_state_get_registers (self);
+ registers = gtk_source_vim_state_get_registers ();
return gtk_source_vim_registers_get (GTK_SOURCE_VIM_REGISTERS (registers), current_register);
}
@@ -1162,7 +1152,7 @@ gtk_source_vim_state_set_current_register_value (GtkSourceVimState *self,
g_return_if_fail (GTK_SOURCE_IS_VIM_STATE (self));
current_register = gtk_source_vim_state_get_current_register (self);
- registers = gtk_source_vim_state_get_registers (self);
+ registers = gtk_source_vim_state_get_registers ();
if (!gtk_source_vim_register_is_read_only (current_register))
{
diff --git a/gtksourceview/vim/gtksourcevimstate.h b/gtksourceview/vim/gtksourcevimstate.h
index 6b12bde5..190fabfc 100644
--- a/gtksourceview/vim/gtksourcevimstate.h
+++ b/gtksourceview/vim/gtksourcevimstate.h
@@ -75,7 +75,7 @@ GtkSourceBuffer *gtk_source_vim_state_get_buffer (GtkSourceVim
GtkTextIter
*selection_bound);
GtkSourceVimState *gtk_source_vim_state_get_root (GtkSourceVimState *self);
GtkSourceVimState *gtk_source_vim_state_get_parent (GtkSourceVimState *self);
-GtkSourceVimState *gtk_source_vim_state_get_registers (GtkSourceVimState *self);
+GtkSourceVimState *gtk_source_vim_state_get_registers (void);
int gtk_source_vim_state_get_count (GtkSourceVimState *self);
gboolean gtk_source_vim_state_get_count_set (GtkSourceVimState *self);
void gtk_source_vim_state_set_count (GtkSourceVimState *self,
diff --git a/gtksourceview/vim/gtksourcevimtexthistory.c b/gtksourceview/vim/gtksourcevimtexthistory.c
index 3a546f6c..5a50b23d 100644
--- a/gtksourceview/vim/gtksourcevimtexthistory.c
+++ b/gtksourceview/vim/gtksourcevimtexthistory.c
@@ -287,7 +287,7 @@ gtk_source_vim_text_history_end (GtkSourceVimTextHistory *self)
}
}
- registers = gtk_source_vim_state_get_registers (GTK_SOURCE_VIM_STATE (self));
+ registers = gtk_source_vim_state_get_registers ();
gtk_source_vim_registers_set (GTK_SOURCE_VIM_REGISTERS (registers), ".", inserted->str);
g_string_free (inserted, TRUE);
}
diff --git a/testsuite/test-vim-input.c b/testsuite/test-vim-input.c
index 05703ee3..205080bc 100644
--- a/testsuite/test-vim-input.c
+++ b/testsuite/test-vim-input.c
@@ -26,6 +26,7 @@
#include <gtksourceview/vim/gtksourcevimcommand.h>
#include <gtksourceview/vim/gtksourceviminsert.h>
#include <gtksourceview/vim/gtksourcevimnormal.h>
+#include <gtksourceview/vim/gtksourcevimregisters.h>
#include <gtksourceview/vim/gtksourcevimstate.h>
static void
@@ -41,6 +42,8 @@ run_test (const char *text,
GtkTextIter begin, end;
char *ret;
+ gtk_source_vim_registers_reset (GTK_SOURCE_VIM_REGISTERS (gtk_source_vim_state_get_registers ()));
+
gtk_source_buffer_set_style_scheme (buffer, scheme);
gtk_text_buffer_set_text (GTK_TEXT_BUFFER (buffer), text, -1);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]