[gtksourceview] vim: warp visual selection when cursor changes
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] vim: warp visual selection when cursor changes
- Date: Fri, 12 Nov 2021 20:04:50 +0000 (UTC)
commit f1ee3e34e7d4ad7907ad63cf852d4946124d3874
Author: Christian Hergert <chergert redhat com>
Date: Fri Nov 12 12:03:24 2021 -0800
vim: warp visual selection when cursor changes
If the user clicks somewhere in the view while we are in visual mode
then we want to update the selection to include that range. This should
make things a bit more like :set mouse=a.
gtksourceview/vim/gtksourcevim.c | 17 ++++++++++++++---
gtksourceview/vim/gtksourcevimvisual.c | 15 +++++++++++++++
gtksourceview/vim/gtksourcevimvisual.h | 2 ++
3 files changed, 31 insertions(+), 3 deletions(-)
---
diff --git a/gtksourceview/vim/gtksourcevim.c b/gtksourceview/vim/gtksourcevim.c
index b8a0be33..f741f2e5 100644
--- a/gtksourceview/vim/gtksourcevim.c
+++ b/gtksourceview/vim/gtksourcevim.c
@@ -111,14 +111,23 @@ constrain_insert_source (gpointer data)
GtkSourceBuffer *buffer;
GtkTextIter iter, selection;
+ g_assert (GTK_SOURCE_IS_VIM (self));
+ g_assert (self->in_handle_event == FALSE);
+
self->constrain_insert_source = 0;
buffer = gtk_source_vim_state_get_buffer (GTK_SOURCE_VIM_STATE (self), &iter, &selection);
current = gtk_source_vim_state_get_current (GTK_SOURCE_VIM_STATE (self));
- if (!GTK_SOURCE_IS_VIM_INSERT (current) &&
- !GTK_SOURCE_IS_VIM_REPLACE (current) &&
- !gtk_text_buffer_get_has_selection (GTK_TEXT_BUFFER (buffer)))
+ self->in_handle_event = TRUE;
+
+ if (GTK_SOURCE_IS_VIM_VISUAL (current))
+ {
+ gtk_source_vim_visual_warp (GTK_SOURCE_VIM_VISUAL (current), &iter);
+ }
+ else if (!GTK_SOURCE_IS_VIM_INSERT (current) &&
+ !GTK_SOURCE_IS_VIM_REPLACE (current) &&
+ !gtk_text_buffer_get_has_selection (GTK_TEXT_BUFFER (buffer)))
{
if (gtk_text_iter_ends_line (&iter) &&
!gtk_text_iter_starts_line (&iter))
@@ -139,6 +148,8 @@ constrain_insert_source (gpointer data)
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_COMMAND_BAR_TEXT]);
}
+ self->in_handle_event = FALSE;
+
return G_SOURCE_REMOVE;
}
diff --git a/gtksourceview/vim/gtksourcevimvisual.c b/gtksourceview/vim/gtksourcevimvisual.c
index 40f95ffb..fc2cac4b 100644
--- a/gtksourceview/vim/gtksourcevimvisual.c
+++ b/gtksourceview/vim/gtksourcevimvisual.c
@@ -892,6 +892,21 @@ gtk_source_vim_visual_get_bounds (GtkSourceVimVisual *self,
return TRUE;
}
+void
+gtk_source_vim_visual_warp (GtkSourceVimVisual *self,
+ const GtkTextIter *iter)
+{
+ GtkTextBuffer *buffer;
+
+ g_return_if_fail (GTK_SOURCE_IS_VIM_VISUAL (self));
+ g_return_if_fail (iter != NULL);
+
+ buffer = gtk_text_mark_get_buffer (self->cursor);
+ gtk_text_buffer_move_mark (buffer, self->cursor, iter);
+ gtk_source_vim_visual_track_motion (self);
+ update_cursor_visible (self);
+}
+
GtkSourceVimState *
gtk_source_vim_visual_clone (GtkSourceVimVisual *self)
{
diff --git a/gtksourceview/vim/gtksourcevimvisual.h b/gtksourceview/vim/gtksourcevimvisual.h
index 986f6211..d7b5a5f8 100644
--- a/gtksourceview/vim/gtksourcevimvisual.h
+++ b/gtksourceview/vim/gtksourcevimvisual.h
@@ -41,5 +41,7 @@ GtkSourceVimState *gtk_source_vim_visual_clone (GtkSourceVimVisual *sel
gboolean gtk_source_vim_visual_get_bounds (GtkSourceVimVisual *self,
GtkTextIter *cursor,
GtkTextIter *started_at);
+void gtk_source_vim_visual_warp (GtkSourceVimVisual *self,
+ const GtkTextIter *iter);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]