[gtksourceview] vim: preserve selections from mouse
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] vim: preserve selections from mouse
- Date: Mon, 13 Dec 2021 21:05:51 +0000 (UTC)
commit 091bf4a77f09daede4a2f1dcd02ac380378722af
Author: Christian Hergert <chergert redhat com>
Date: Mon Dec 13 13:05:46 2021 -0800
vim: preserve selections from mouse
If the user selects a new region while already in visual mode, we want to
try to use that selection rather than extending the current selection.
gtksourceview/vim/gtksourcevim.c | 4 ++--
gtksourceview/vim/gtksourcevimcommand.c | 4 ++--
gtksourceview/vim/gtksourcevimvisual.c | 12 ++++++++++--
gtksourceview/vim/gtksourcevimvisual.h | 3 ++-
4 files changed, 16 insertions(+), 7 deletions(-)
---
diff --git a/gtksourceview/vim/gtksourcevim.c b/gtksourceview/vim/gtksourcevim.c
index cf455135..0bc389ba 100644
--- a/gtksourceview/vim/gtksourcevim.c
+++ b/gtksourceview/vim/gtksourcevim.c
@@ -213,7 +213,7 @@ constrain_insert_source (gpointer data)
if (GTK_SOURCE_IS_VIM_VISUAL (current))
{
- gtk_source_vim_visual_warp (GTK_SOURCE_VIM_VISUAL (current), &iter);
+ gtk_source_vim_visual_warp (GTK_SOURCE_VIM_VISUAL (current), &iter, &selection);
}
else if (!GTK_SOURCE_IS_VIM_INSERT (current) &&
!GTK_SOURCE_IS_VIM_REPLACE (current) &&
@@ -238,7 +238,7 @@ constrain_insert_source (gpointer data)
gtk_text_buffer_select_range (GTK_TEXT_BUFFER (buffer), &selection, &selection);
visual = gtk_source_vim_visual_new (GTK_SOURCE_VIM_VISUAL_CHAR);
gtk_source_vim_state_push (current, visual);
- gtk_source_vim_visual_warp (GTK_SOURCE_VIM_VISUAL (visual), &iter);
+ gtk_source_vim_visual_warp (GTK_SOURCE_VIM_VISUAL (visual), &iter, &selection);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_COMMAND_TEXT]);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_COMMAND_BAR_TEXT]);
}
diff --git a/gtksourceview/vim/gtksourcevimcommand.c b/gtksourceview/vim/gtksourcevimcommand.c
index b91ea47d..5540da48 100644
--- a/gtksourceview/vim/gtksourcevimcommand.c
+++ b/gtksourceview/vim/gtksourcevimcommand.c
@@ -797,7 +797,7 @@ gtk_source_vim_command_search (GtkSourceVimCommand *self)
visual = gtk_source_vim_state_get_ancestor (GTK_SOURCE_VIM_STATE (self),
GTK_SOURCE_TYPE_VIM_VISUAL);
- gtk_source_vim_visual_warp (GTK_SOURCE_VIM_VISUAL (visual), &match);
+ gtk_source_vim_visual_warp (GTK_SOURCE_VIM_VISUAL (visual), &match, NULL);
gtk_source_vim_visual_ignore_command (GTK_SOURCE_VIM_VISUAL (visual));
}
else
@@ -862,7 +862,7 @@ gtk_source_vim_command_search_reverse (GtkSourceVimCommand *self)
visual = gtk_source_vim_state_get_ancestor (GTK_SOURCE_VIM_STATE (self),
GTK_SOURCE_TYPE_VIM_VISUAL);
- gtk_source_vim_visual_warp (GTK_SOURCE_VIM_VISUAL (visual), &match);
+ gtk_source_vim_visual_warp (GTK_SOURCE_VIM_VISUAL (visual), &match, NULL);
gtk_source_vim_visual_ignore_command (GTK_SOURCE_VIM_VISUAL (visual));
}
else
diff --git a/gtksourceview/vim/gtksourcevimvisual.c b/gtksourceview/vim/gtksourcevimvisual.c
index 6d3765fb..a6f81050 100644
--- a/gtksourceview/vim/gtksourcevimvisual.c
+++ b/gtksourceview/vim/gtksourcevimvisual.c
@@ -978,7 +978,8 @@ gtk_source_vim_visual_get_bounds (GtkSourceVimVisual *self,
void
gtk_source_vim_visual_warp (GtkSourceVimVisual *self,
- const GtkTextIter *iter)
+ const GtkTextIter *iter,
+ const GtkTextIter *selection)
{
GtkTextBuffer *buffer;
@@ -986,8 +987,15 @@ gtk_source_vim_visual_warp (GtkSourceVimVisual *self,
g_return_if_fail (iter != NULL);
buffer = gtk_text_mark_get_buffer (self->cursor);
- gtk_text_buffer_move_mark (buffer, self->cursor, iter);
+
+ if (iter != NULL)
+ gtk_text_buffer_move_mark (buffer, self->cursor, iter);
+
+ if (selection != NULL)
+ gtk_text_buffer_move_mark (buffer, self->started_at, selection);
+
gtk_source_vim_visual_track_motion (self);
+
update_cursor_visible (self);
}
diff --git a/gtksourceview/vim/gtksourcevimvisual.h b/gtksourceview/vim/gtksourcevimvisual.h
index 2167b596..5875aa0e 100644
--- a/gtksourceview/vim/gtksourcevimvisual.h
+++ b/gtksourceview/vim/gtksourcevimvisual.h
@@ -42,7 +42,8 @@ gboolean gtk_source_vim_visual_get_bounds (GtkSourceVimVisual
GtkTextIter *cursor,
GtkTextIter *started_at);
void gtk_source_vim_visual_warp (GtkSourceVimVisual *self,
- const GtkTextIter *iter);
+ const GtkTextIter *iter,
+ const GtkTextIter *selection);
void gtk_source_vim_visual_ignore_command (GtkSourceVimVisual *self);
static inline gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]