[gtksourceview/wip/chergert/vim] create mark for begin/end of range
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/vim] create mark for begin/end of range
- Date: Mon, 8 Nov 2021 22:16:36 +0000 (UTC)
commit 76d467158c577905ff024d411cc45770bb060777
Author: Christian Hergert <chergert redhat com>
Date: Mon Nov 8 14:16:32 2021 -0800
create mark for begin/end of range
the goal here is to use it in various commands like s&r
gtksourceview/vim/gtk-source-vim-command.c | 37 +++++++++++++++++++++++++++++-
1 file changed, 36 insertions(+), 1 deletion(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-command.c b/gtksourceview/vim/gtk-source-vim-command.c
index ea0b61d1..85d59cc0 100644
--- a/gtksourceview/vim/gtk-source-vim-command.c
+++ b/gtksourceview/vim/gtk-source-vim-command.c
@@ -44,6 +44,8 @@ struct _GtkSourceVimCommand
GtkSourceVimMotion *motion;
GtkSourceVimMotion *selection_motion;
GtkSourceVimTextObject *text_object;
+ GtkTextMark *mark_begin;
+ GtkTextMark *mark_end;
char *command;
char *options;
char char_pending[16];
@@ -901,6 +903,21 @@ static void
gtk_source_vim_command_dispose (GObject *object)
{
GtkSourceVimCommand *self = (GtkSourceVimCommand *)object;
+ GtkTextBuffer *buffer;
+
+ if (self->mark_begin)
+ {
+ if ((buffer = gtk_text_mark_get_buffer (self->mark_begin)))
+ gtk_text_buffer_delete_mark (buffer, self->mark_begin);
+ g_clear_weak_pointer (&self->mark_begin);
+ }
+
+ if (self->mark_end)
+ {
+ if ((buffer = gtk_text_mark_get_buffer (self->mark_end)))
+ gtk_text_buffer_delete_mark (buffer, self->mark_end);
+ g_clear_weak_pointer (&self->mark_end);
+ }
gtk_source_vim_state_release (&self->motion);
gtk_source_vim_state_release (&self->selection_motion);
@@ -1155,6 +1172,8 @@ gtk_source_vim_command_new_parsed (GtkSourceVimState *current,
{
GtkSourceVimCommand *ret = NULL;
GtkSourceVimCommandClass *klass;
+ GtkTextMark *mark_begin = NULL;
+ GtkTextMark *mark_end = NULL;
GtkTextIter begin;
GtkTextIter end;
int number;
@@ -1177,7 +1196,11 @@ gtk_source_vim_command_new_parsed (GtkSourceVimState *current,
if (parse_mark_range (current, &command_line, &begin, &end))
{
- g_print ("Working within a range\n");
+ GtkSourceBuffer *buffer;
+
+ buffer = gtk_source_vim_state_get_buffer (current, NULL, NULL);
+ mark_begin = gtk_text_buffer_create_mark (GTK_TEXT_BUFFER (buffer), NULL, &begin, TRUE);
+ mark_end = gtk_text_buffer_create_mark (GTK_TEXT_BUFFER (buffer), NULL, &end, FALSE);
}
if (*command_line == '/')
@@ -1230,6 +1253,18 @@ gtk_source_vim_command_new_parsed (GtkSourceVimState *current,
}
finish:
+
+ if (ret != NULL)
+ {
+ g_set_weak_pointer (&ret->mark_begin, mark_begin);
+ g_set_weak_pointer (&ret->mark_end, mark_end);
+ }
+ else if (mark_begin || mark_end)
+ {
+ gtk_text_buffer_delete_mark (gtk_text_mark_get_buffer (mark_begin), mark_begin);
+ gtk_text_buffer_delete_mark (gtk_text_mark_get_buffer (mark_end), mark_end);
+ }
+
g_type_class_unref (klass);
return GTK_SOURCE_VIM_STATE (ret);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]