[gtksourceview/wip/chergert/vim: 243/293] add select linewise helper
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/vim: 243/293] add select linewise helper
- Date: Fri, 5 Nov 2021 04:23:07 +0000 (UTC)
commit b105db3c96ede7b40aefff9d61972d73e14e8cbb
Author: Christian Hergert <chergert redhat com>
Date: Wed Nov 3 10:25:29 2021 -0700
add select linewise helper
this will make it easier to apply linewise from other operations such
as commands later on.
gtksourceview/vim/gtk-source-vim-state.c | 44 +++++++++++++++++++++++++++++++
gtksourceview/vim/gtk-source-vim-state.h | 3 +++
gtksourceview/vim/gtk-source-vim-visual.c | 26 +-----------------
3 files changed, 48 insertions(+), 25 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-state.c b/gtksourceview/vim/gtk-source-vim-state.c
index 64fcb4a6..e2cc5456 100644
--- a/gtksourceview/vim/gtk-source-vim-state.c
+++ b/gtksourceview/vim/gtk-source-vim-state.c
@@ -1117,3 +1117,47 @@ gtk_source_vim_state_set_visual_column (GtkSourceVimState *self,
priv->column_set = TRUE;
}
+static void
+extend_lines (GtkTextIter *a,
+ GtkTextIter *b)
+{
+ if (gtk_text_iter_compare (a, b) <= 0)
+ {
+ gtk_text_iter_set_line_offset (a, 0);
+ if (!gtk_text_iter_ends_line (b))
+ gtk_text_iter_forward_to_line_end (b);
+ if (gtk_text_iter_ends_line (b) && !gtk_text_iter_is_end (b))
+ gtk_text_iter_forward_char (b);
+ }
+ else
+ {
+ gtk_text_iter_set_line_offset (b, 0);
+ if (!gtk_text_iter_ends_line (a))
+ gtk_text_iter_forward_to_line_end (a);
+ if (gtk_text_iter_ends_line (a) && !gtk_text_iter_is_end (a))
+ gtk_text_iter_forward_char (a);
+ }
+}
+
+void
+gtk_source_vim_state_select_linewise (GtkSourceVimState *self,
+ GtkTextIter *insert,
+ GtkTextIter *selection)
+{
+ GtkSourceBuffer *buffer;
+ GtkTextIter iter1, iter2;
+
+ g_return_if_fail (GTK_SOURCE_IS_VIM_STATE (self));
+
+ buffer = gtk_source_vim_state_get_buffer (self, &iter1, &iter2);
+
+ if (insert == NULL)
+ insert = &iter1;
+
+ if (selection == NULL)
+ selection = &iter2;
+
+ extend_lines (insert, selection);
+
+ gtk_text_buffer_select_range (GTK_TEXT_BUFFER (buffer), insert, selection);
+}
diff --git a/gtksourceview/vim/gtk-source-vim-state.h b/gtksourceview/vim/gtk-source-vim-state.h
index 8cde2813..51014eaf 100644
--- a/gtksourceview/vim/gtk-source-vim-state.h
+++ b/gtksourceview/vim/gtk-source-vim-state.h
@@ -123,6 +123,9 @@ void gtk_source_vim_state_keyval_unescaped (guint
guint gtk_source_vim_state_get_visual_column (GtkSourceVimState *self);
void gtk_source_vim_state_set_visual_column (GtkSourceVimState *self,
int visual_column);
+void gtk_source_vim_state_select_linewise (GtkSourceVimState *self,
+ GtkTextIter *insert,
+ GtkTextIter *selection);
static inline gboolean
gtk_source_vim_state_is_escape (guint keyval,
diff --git a/gtksourceview/vim/gtk-source-vim-visual.c b/gtksourceview/vim/gtk-source-vim-visual.c
index b1a90dcc..abb8db9c 100644
--- a/gtksourceview/vim/gtk-source-vim-visual.c
+++ b/gtksourceview/vim/gtk-source-vim-visual.c
@@ -111,28 +111,6 @@ gtk_source_vim_visual_bail (GtkSourceVimVisual *self)
return TRUE;
}
-static void
-extend_lines (GtkTextIter *a,
- GtkTextIter *b)
-{
- if (gtk_text_iter_compare (a, b) <= 0)
- {
- gtk_text_iter_set_line_offset (a, 0);
- if (!gtk_text_iter_ends_line (b))
- gtk_text_iter_forward_to_line_end (b);
- if (gtk_text_iter_ends_line (b) && !gtk_text_iter_is_end (b))
- gtk_text_iter_forward_char (b);
- }
- else
- {
- gtk_text_iter_set_line_offset (b, 0);
- if (!gtk_text_iter_ends_line (a))
- gtk_text_iter_forward_to_line_end (a);
- if (gtk_text_iter_ends_line (a) && !gtk_text_iter_is_end (a))
- gtk_text_iter_forward_char (a);
- }
-}
-
static void
gtk_source_vim_visual_track_char (GtkSourceVimVisual *self)
{
@@ -205,9 +183,7 @@ gtk_source_vim_visual_track_line (GtkSourceVimVisual *self)
gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (buffer), &cursor, self->cursor);
gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (buffer), &started_at, self->started_at);
- extend_lines (&cursor, &started_at);
-
- gtk_source_vim_state_select (GTK_SOURCE_VIM_STATE (self), &cursor, &started_at);
+ gtk_source_vim_state_select_linewise (GTK_SOURCE_VIM_STATE (self), &cursor, &started_at);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]