[gnome-builder] vim: keep insert mark before character when selecting a single char
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] vim: keep insert mark before character when selecting a single char
- Date: Mon, 6 Oct 2014 09:13:53 +0000 (UTC)
commit 0d57bd6bb92fdb826142a083354dd2ebfcef66ce
Author: Christian Hergert <christian hergert me>
Date: Mon Oct 6 02:07:29 2014 -0700
vim: keep insert mark before character when selecting a single char
This makes things like jumping between matches easier (such as with %).
Otherwise, when you jump back to the original position, the insert mark
would be after the selected char causing the character under the cursor
to be different.
src/editor/gb-editor-vim.c | 14 ++++++++++++++
1 files changed, 14 insertions(+), 0 deletions(-)
---
diff --git a/src/editor/gb-editor-vim.c b/src/editor/gb-editor-vim.c
index d906b60..9879711 100644
--- a/src/editor/gb-editor-vim.c
+++ b/src/editor/gb-editor-vim.c
@@ -157,6 +157,8 @@ static GHashTable *gCommands;
static GParamSpec *gParamSpecs [LAST_PROP];
static guint gSignals [LAST_SIGNAL];
+static void text_iter_swap (GtkTextIter *a,
+ GtkTextIter *b);
static void gb_editor_vim_cmd_select_line (GbEditorVim *vim,
guint count,
gchar modifier);
@@ -582,6 +584,8 @@ gb_editor_vim_select_range (GbEditorVim *vim,
GtkTextBuffer *buffer;
GtkTextMark *insert;
GtkTextMark *selection;
+ gint insert_off;
+ gint selection_off;
g_assert (GB_IS_EDITOR_VIM (vim));
g_assert (insert_iter);
@@ -591,6 +595,16 @@ gb_editor_vim_select_range (GbEditorVim *vim,
insert = gtk_text_buffer_get_insert (buffer);
selection = gtk_text_buffer_get_selection_bound (buffer);
+ /*
+ * If the caller is requesting that we select a single character, we will
+ * keep the iter before that character. This more closely matches the visual
+ * mode in VIM.
+ */
+ insert_off = gtk_text_iter_get_offset (insert_iter);
+ selection_off = gtk_text_iter_get_offset (selection_iter);
+ if ((insert_off - selection_off) == 1)
+ text_iter_swap (insert_iter, selection_iter);
+
gtk_text_buffer_move_mark (buffer, insert, insert_iter);
gtk_text_buffer_move_mark (buffer, selection, selection_iter);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]