[gnome-builder] vim: Implement exclusive-motions exceptions
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] vim: Implement exclusive-motions exceptions
- Date: Mon, 6 Oct 2014 05:55:54 +0000 (UTC)
commit 6f7ed754596cd04beb2bf5f9b5da368a8167e89e
Author: Florian Müllner <fmuellner gnome org>
Date: Mon Oct 6 02:06:39 2014 +0200
vim: Implement exclusive-motions exceptions
Commit 83e31754aa30b83 added basic support for exclusive motions, but
unfortunately vim's behavior is a bit more complicated than that:
Exclusive motions may become inclusive or linewise under certain
circumstances [0].
[0] http://vimdoc.sourceforge.net/htmldoc/motion.html#exclusive
https://bugzilla.gnome.org/show_bug.cgi?id=737971
src/editor/gb-editor-vim.c | 36 ++++++++++++++++++++++++++++++++++--
1 files changed, 34 insertions(+), 2 deletions(-)
---
diff --git a/src/editor/gb-editor-vim.c b/src/editor/gb-editor-vim.c
index a430262..e143d58 100644
--- a/src/editor/gb-editor-vim.c
+++ b/src/editor/gb-editor-vim.c
@@ -1235,9 +1235,41 @@ gb_editor_vim_apply_motion (GbEditorVim *vim,
gb_editor_vim_get_selection_bounds (vim, &iter, &selection);
if (gtk_text_iter_compare (&iter, &selection) < 0)
- gtk_text_iter_backward_char (&selection);
+ text_iter_swap (&iter, &selection);
+
+ /* From the docs:
+ * "If the motion is exclusive and the end of the motion is in column 1,
+ * the end of the motion is moved to the end of the previous line and
+ * the motion becomes inclusive."
+ */
+ if (gtk_text_iter_get_line_offset (&iter) == 0)
+ {
+ GtkTextIter tmp;
+ guint line;
+
+ gtk_text_iter_backward_char (&iter);
+
+ /* More docs:
+ * "If [as above] and the start of the motion was at or before
+ * the first non-blank in the line, the motion becomes linewise."
+ */
+ tmp = selection;
+ line = gtk_text_iter_get_line (&selection);
+
+ gtk_text_iter_backward_word_start (&tmp);
+ if (gtk_text_iter_is_start (&tmp) ||
+ gtk_text_iter_get_line (&tmp) < line)
+ {
+ while (!gtk_text_iter_starts_line (&selection))
+ gtk_text_iter_backward_char (&selection);
+ while (!gtk_text_iter_starts_line (&iter))
+ gtk_text_iter_forward_char (&iter);
+ }
+ }
else
- gtk_text_iter_backward_char (&iter);
+ {
+ gtk_text_iter_backward_char (&iter);
+ }
gb_editor_vim_select_range (vim, &iter, &selection);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]