[gtksourceview/wip/chergert/vim: 261/293] improve command positioning for charwise
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/vim: 261/293] improve command positioning for charwise
- Date: Fri, 5 Nov 2021 04:23:07 +0000 (UTC)
commit 212d68a0655ff0950b120590a05a461fea098093
Author: Christian Hergert <chergert redhat com>
Date: Wed Nov 3 14:57:29 2021 -0700
improve command positioning for charwise
gtksourceview/vim/gtk-source-vim-visual.c | 32 ++++++++++++++++++++++++-------
1 file changed, 25 insertions(+), 7 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-visual.c b/gtksourceview/vim/gtk-source-vim-visual.c
index 9cbf124e..5b110f3c 100644
--- a/gtksourceview/vim/gtk-source-vim-visual.c
+++ b/gtksourceview/vim/gtk-source-vim-visual.c
@@ -66,10 +66,13 @@ struct _GtkSourceVimVisual
typedef struct
{
GtkTextBuffer *buffer;
+ GtkTextMark *cursor;
+ GtkTextMark *started_at;
int cmp;
guint line;
guint line_offset;
guint start_line;
+ guint linewise : 1;
} CursorInfo;
static gboolean gtk_source_vim_visual_bail (GtkSourceVimVisual *self);
@@ -91,6 +94,8 @@ cursor_info_stash (GtkSourceVimVisual *self,
g_assert (GTK_SOURCE_IS_VIM_VISUAL (self));
info->buffer = gtk_text_mark_get_buffer (self->cursor);
+ info->cursor = self->cursor;
+ info->started_at = self->started_at;
gtk_text_buffer_get_iter_at_mark (info->buffer, &cursor, self->cursor);
gtk_text_buffer_get_iter_at_mark (info->buffer, &started_at, self->started_at);
@@ -99,24 +104,37 @@ cursor_info_stash (GtkSourceVimVisual *self,
info->line = gtk_text_iter_get_line (&cursor);
info->line_offset = gtk_text_iter_get_line_offset (&cursor);
info->start_line = MIN (gtk_text_iter_get_line (&started_at), info->line);
+ info->linewise = self->mode == GTK_SOURCE_VIM_VISUAL_LINE;
}
static void
cursor_info_restore (CursorInfo *info)
{
- if (info->cmp > 0)
+ if (info->linewise)
{
- GtkTextIter iter;
+ if (info->cmp > 0)
+ {
+ GtkTextIter iter;
+
+ gtk_text_buffer_get_iter_at_line (info->buffer, &iter, info->start_line);
+ gtk_text_buffer_select_range (info->buffer, &iter, &iter);
+ }
+ else
+ {
+ GtkTextIter iter;
- gtk_text_buffer_get_iter_at_line (info->buffer, &iter, info->start_line);
- gtk_text_buffer_select_range (info->buffer, &iter, &iter);
+ gtk_text_buffer_get_iter_at_line_offset (info->buffer, &iter, info->line,
info->line_offset);
+ gtk_text_buffer_select_range (info->buffer, &iter, &iter);
+ }
}
else
{
- GtkTextIter iter;
+ GtkTextIter cursor, started_at;
- gtk_text_buffer_get_iter_at_line_offset (info->buffer, &iter, info->line, info->line_offset);
- gtk_text_buffer_select_range (info->buffer, &iter, &iter);
+ gtk_text_buffer_get_iter_at_mark (info->buffer, &cursor, info->cursor);
+ gtk_text_buffer_get_iter_at_mark (info->buffer, &started_at, info->started_at);
+ gtk_text_iter_order (&cursor, &started_at);
+ gtk_text_buffer_select_range (info->buffer, &cursor, &cursor);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]