[gnome-builder/gnome-builder-3-26] vim: fix de db dw
- From: Sébastien Lafargue <slafargue src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/gnome-builder-3-26] vim: fix de db dw
- Date: Fri, 29 Sep 2017 10:03:33 +0000 (UTC)
commit 07d340fd7145f0881de899482b03835a36b34e36
Author: Sebastien Lafargue <slafargue gnome org>
Date: Fri Sep 29 11:47:58 2017 +0200
vim: fix de db dw
data/keybindings/vim.css | 12 +-
libide/sourceview/ide-source-view-movements.c | 67 ++++++++-
libide/sourceview/ide-source-view.h | 9 ++
libide/sourceview/ide-text-iter.c | 178 ++++++++++++++++++++++--
libide/sourceview/ide-text-iter.h | 23 +++-
5 files changed, 254 insertions(+), 35 deletions(-)
---
diff --git a/data/keybindings/vim.css b/data/keybindings/vim.css
index 763266a..f3be20d 100644
--- a/data/keybindings/vim.css
+++ b/data/keybindings/vim.css
@@ -1281,34 +1281,34 @@
"clear-count" () };
bind "b" { "begin-macro" ()
- "movement" (previous-word-end, 1, 0, 1)
+ "movement" (previous-word-end-newline-stop, 1, 1, 1)
"copy-clipboard" ()
"delete-selection" ()
"end-macro" () };
bind "<shift>b" { "begin-macro" ()
- "movement" (previous-full-word-end, 1, 0, 1)
+ "movement" (previous-full-word-end-newline-stop, 1, 1, 1)
"copy-clipboard" ()
"delete-selection" ()
"end-macro" () };
bind "e" { "begin-macro" ()
- "movement" (next-word-end, 1, 0, 1)
+ "movement" (next-word-end-newline-stop, 1, 0, 1)
"copy-clipboard" ()
"delete-selection" ()
"end-macro" () };
bind "<shift>e" { "begin-macro" ()
- "movement" (next-full-word-end, 1, 0, 1)
+ "movement" (next-full-word-end-newline-stop, 1, 0, 1)
"copy-clipboard" ()
"delete-selection" ()
"end-macro" () };
bind "w" { "begin-macro" ()
- "movement" (next-word-start, 1, 1, 1)
+ "movement" (next-word-start-newline-stop, 1, 1, 1)
"copy-clipboard" ()
"delete-selection" ()
"end-macro" () };
bind "<shift>w" { "begin-macro" ()
- "movement" (next-full-word-start, 1, 1, 1)
+ "movement" (next-word-start-newline-stop, 1, 1, 1)
"copy-clipboard" ()
"delete-selection" ()
"end-macro" () };
diff --git a/libide/sourceview/ide-source-view-movements.c b/libide/sourceview/ide-source-view-movements.c
index 45150c1..f3f7dcc 100644
--- a/libide/sourceview/ide-source-view-movements.c
+++ b/libide/sourceview/ide-source-view-movements.c
@@ -53,6 +53,9 @@ typedef struct
gunichar command; /* Command that trigger some movements type. See , and
; in vim */
gunichar modifier; /* For forward/backward char search */
gunichar search_char; /* For forward/backward char search according to fFtT
vim modifier */
+ guint newline_stop : 1; /* Stop the movement at newline chararacter
+ * currently used by [previous|next]_[word|full_word]
functions
+ */
guint extend_selection : 1; /* If selection should be extended */
guint exclusive : 1; /* See ":help exclusive" in vim */
guint ignore_select : 1; /* Don't update selection after movement */
@@ -1495,7 +1498,7 @@ ide_source_view_movements_next_word_end (Movement *mv)
copy = mv->insert;
- _ide_text_iter_forward_word_end (&mv->insert);
+ _ide_text_iter_forward_word_end (&mv->insert, mv->newline_stop);
/* prefer an empty line before word */
text_iter_forward_to_empty_line (©, &mv->insert);
@@ -1513,7 +1516,7 @@ ide_source_view_movements_next_full_word_end (Movement *mv)
copy = mv->insert;
- _ide_text_iter_forward_WORD_end (&mv->insert);
+ _ide_text_iter_forward_WORD_end (&mv->insert, mv->newline_stop);
/* prefer an empty line before word */
text_iter_forward_to_empty_line (©, &mv->insert);
@@ -1531,7 +1534,7 @@ ide_source_view_movements_next_word_start (Movement *mv)
copy = mv->insert;
- _ide_text_iter_forward_word_start (&mv->insert);
+ _ide_text_iter_forward_word_start (&mv->insert, mv->newline_stop);
/* prefer an empty line before word */
text_iter_forward_to_empty_line (©, &mv->insert);
@@ -1549,7 +1552,7 @@ ide_source_view_movements_next_full_word_start (Movement *mv)
copy = mv->insert;
- _ide_text_iter_forward_WORD_start (&mv->insert);
+ _ide_text_iter_forward_WORD_start (&mv->insert, mv->newline_stop);
/* prefer an empty line before word */
text_iter_forward_to_empty_line (©, &mv->insert);
@@ -1567,7 +1570,7 @@ ide_source_view_movements_previous_word_start (Movement *mv)
copy = mv->insert;
- _ide_source_iter_backward_visible_word_start (&mv->insert);
+ _ide_text_iter_backward_word_start (&mv->insert, mv->newline_stop);
/*
* Vim treats an empty line as a word.
@@ -1587,7 +1590,7 @@ ide_source_view_movements_previous_full_word_start (Movement *mv)
copy = mv->insert;
- _ide_source_iter_backward_full_word_start (&mv->insert);
+ _ide_text_iter_backward_WORD_start (&mv->insert, mv->newline_stop);
/*
* Vim treats an empty line as a word.
@@ -1607,7 +1610,7 @@ ide_source_view_movements_previous_word_end (Movement *mv)
copy = mv->insert;
- _ide_text_iter_backward_word_end (&mv->insert);
+ _ide_text_iter_backward_word_end (&mv->insert, mv->newline_stop);
/*
* Vim treats an empty line as a word.
@@ -1631,7 +1634,7 @@ ide_source_view_movements_previous_full_word_end (Movement *mv)
copy = mv->insert;
- _ide_text_iter_backward_WORD_end (&mv->insert);
+ _ide_text_iter_backward_WORD_end (&mv->insert, mv->newline_stop);
/*
* Vim treats an empty line as a word.
@@ -2051,21 +2054,45 @@ _ide_source_view_apply_movement (IdeSourceView *self,
ide_source_view_movements_previous_full_word_start (&mv);
break;
+ case IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_FULL_WORD_START_NEWLINE_STOP:
+ mv.newline_stop = TRUE;
+ for (i = MAX (1, mv.count); i > 0; i--)
+ ide_source_view_movements_previous_full_word_start (&mv);
+ break;
+
case IDE_SOURCE_VIEW_MOVEMENT_NEXT_FULL_WORD_START:
for (i = MAX (1, mv.count); i > 0; i--)
ide_source_view_movements_next_full_word_start (&mv);
break;
+ case IDE_SOURCE_VIEW_MOVEMENT_NEXT_FULL_WORD_START_NEWLINE_STOP:
+ mv.newline_stop = TRUE;
+ for (i = MAX (1, mv.count); i > 0; i--)
+ ide_source_view_movements_next_full_word_start (&mv);
+ break;
+
case IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_FULL_WORD_END:
for (i = MAX (1, mv.count); i > 0; i--)
ide_source_view_movements_previous_full_word_end (&mv);
break;
+ case IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_FULL_WORD_END_NEWLINE_STOP:
+ mv.newline_stop = TRUE;
+ for (i = MAX (1, mv.count); i > 0; i--)
+ ide_source_view_movements_previous_full_word_end (&mv);
+ break;
+
case IDE_SOURCE_VIEW_MOVEMENT_NEXT_FULL_WORD_END:
for (i = MAX (1, mv.count); i > 0; i--)
ide_source_view_movements_next_full_word_end (&mv);
break;
+ case IDE_SOURCE_VIEW_MOVEMENT_NEXT_FULL_WORD_END_NEWLINE_STOP:
+ mv.newline_stop = TRUE;
+ for (i = MAX (1, mv.count); i > 0; i--)
+ ide_source_view_movements_next_full_word_end (&mv);
+ break;
+
case IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_SUB_WORD_START:
gtk_text_iter_backward_visible_word_starts (&mv.insert, MAX (1, mv.count));
break;
@@ -2080,21 +2107,45 @@ _ide_source_view_apply_movement (IdeSourceView *self,
ide_source_view_movements_previous_word_start (&mv);
break;
+ case IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_WORD_START_NEWLINE_STOP:
+ mv.newline_stop = TRUE;
+ for (i = MAX (1, mv.count); i > 0; i--)
+ ide_source_view_movements_previous_word_start (&mv);
+ break;
+
case IDE_SOURCE_VIEW_MOVEMENT_NEXT_WORD_START:
for (i = MAX (1, mv.count); i > 0; i--)
ide_source_view_movements_next_word_start (&mv);
break;
+ case IDE_SOURCE_VIEW_MOVEMENT_NEXT_WORD_START_NEWLINE_STOP:
+ mv.newline_stop = TRUE;
+ for (i = MAX (1, mv.count); i > 0; i--)
+ ide_source_view_movements_next_word_start (&mv);
+ break;
+
case IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_WORD_END:
for (i = MAX (1, mv.count); i > 0; i--)
ide_source_view_movements_previous_word_end (&mv);
break;
+ case IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_WORD_END_NEWLINE_STOP:
+ mv.newline_stop = TRUE;
+ for (i = MAX (1, mv.count); i > 0; i--)
+ ide_source_view_movements_previous_word_end (&mv);
+ break;
+
case IDE_SOURCE_VIEW_MOVEMENT_NEXT_WORD_END:
for (i = MAX (1, mv.count); i > 0; i--)
ide_source_view_movements_next_word_end (&mv);
break;
+ case IDE_SOURCE_VIEW_MOVEMENT_NEXT_WORD_END_NEWLINE_STOP:
+ mv.newline_stop = TRUE;
+ for (i = MAX (1, mv.count); i > 0; i--)
+ ide_source_view_movements_next_word_end (&mv);
+ break;
+
case IDE_SOURCE_VIEW_MOVEMENT_SENTENCE_START:
for (i = MAX (1, mv.count); i > 0; i--)
ide_source_view_movements_sentence_start (&mv);
diff --git a/libide/sourceview/ide-source-view.h b/libide/sourceview/ide-source-view.h
index fdac57a..d35abbb 100644
--- a/libide/sourceview/ide-source-view.h
+++ b/libide/sourceview/ide-source-view.h
@@ -158,6 +158,15 @@ typedef enum
IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_FULL_WORD_END,
IDE_SOURCE_VIEW_MOVEMENT_NEXT_WORD_END,
IDE_SOURCE_VIEW_MOVEMENT_NEXT_FULL_WORD_END,
+ IDE_SOURCE_VIEW_MOVEMENT_NEXT_WORD_START_NEWLINE_STOP,
+ IDE_SOURCE_VIEW_MOVEMENT_NEXT_FULL_WORD_START_NEWLINE_STOP,
+ IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_WORD_START_NEWLINE_STOP,
+ IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_FULL_WORD_START_NEWLINE_STOP,
+
+ IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_WORD_END_NEWLINE_STOP,
+ IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_FULL_WORD_END_NEWLINE_STOP,
+ IDE_SOURCE_VIEW_MOVEMENT_NEXT_WORD_END_NEWLINE_STOP,
+ IDE_SOURCE_VIEW_MOVEMENT_NEXT_FULL_WORD_END_NEWLINE_STOP,
IDE_SOURCE_VIEW_MOVEMENT_SENTENCE_START,
IDE_SOURCE_VIEW_MOVEMENT_SENTENCE_END,
diff --git a/libide/sourceview/ide-text-iter.c b/libide/sourceview/ide-text-iter.c
index aea3e83..1f8c9cc 100644
--- a/libide/sourceview/ide-text-iter.c
+++ b/libide/sourceview/ide-text-iter.c
@@ -37,6 +37,7 @@ typedef enum
enum
{
CLASS_0,
+ CLASS_NEWLINE,
CLASS_SPACE,
CLASS_SPECIAL,
CLASS_WORD,
@@ -70,6 +71,35 @@ _ide_text_word_classify (gunichar ch)
}
static int
+_ide_text_word_classify_newline_stop (gunichar ch)
+{
+ switch (ch)
+ {
+ case ' ':
+ case '\t':
+ return CLASS_SPACE;
+
+ case '\n':
+ return CLASS_NEWLINE;
+
+ case '"': case '\'':
+ case '(': case ')':
+ case '{': case '}':
+ case '[': case ']':
+ case '<': case '>':
+ case '-': case '+': case '*': case '/':
+ case '!': case '@': case '#': case '$': case '%':
+ case '^': case '&': case ':': case ';': case '?':
+ case '|': case '=': case '\\': case '.': case ',':
+ return CLASS_SPECIAL;
+
+ case '_':
+ default:
+ return CLASS_WORD;
+ }
+}
+
+static int
_ide_text_WORD_classify (gunichar ch)
{
if (g_unichar_isspace (ch))
@@ -77,6 +107,17 @@ _ide_text_WORD_classify (gunichar ch)
return CLASS_WORD;
}
+static int
+_ide_text_WORD_classify_newline_stop (gunichar ch)
+{
+ if (ch == '\n')
+ return CLASS_NEWLINE;
+
+ if (g_unichar_isspace (ch))
+ return CLASS_SPACE;
+ return CLASS_WORD;
+}
+
static gboolean
_ide_text_iter_line_is_empty (GtkTextIter *iter)
{
@@ -347,7 +388,7 @@ _ide_text_iter_forward_classified_start (GtkTextIter *iter,
continue;
}
- if (cur_class != begin_class)
+ if (cur_class != begin_class || cur_class == CLASS_NEWLINE)
return TRUE;
}
@@ -355,18 +396,26 @@ _ide_text_iter_forward_classified_start (GtkTextIter *iter,
}
gboolean
-_ide_text_iter_forward_word_start (GtkTextIter *iter)
+_ide_text_iter_forward_word_start (GtkTextIter *iter,
+ gboolean newline_stop)
{
- return _ide_text_iter_forward_classified_start (iter, _ide_text_word_classify);
+ if (newline_stop)
+ return _ide_text_iter_forward_classified_start (iter, _ide_text_word_classify_newline_stop);
+ else
+ return _ide_text_iter_forward_classified_start (iter, _ide_text_word_classify);
}
gboolean
-_ide_text_iter_forward_WORD_start (GtkTextIter *iter)
+_ide_text_iter_forward_WORD_start (GtkTextIter *iter,
+ gboolean newline_stop)
{
- return _ide_text_iter_forward_classified_start (iter, _ide_text_WORD_classify);
+ if (newline_stop)
+ return _ide_text_iter_forward_classified_start (iter, _ide_text_WORD_classify_newline_stop);
+ else
+ return _ide_text_iter_forward_classified_start (iter, _ide_text_WORD_classify);
}
-gboolean
+static gboolean
_ide_text_iter_forward_classified_end (GtkTextIter *iter,
gint (*classify) (gunichar))
{
@@ -388,6 +437,12 @@ _ide_text_iter_forward_classified_end (GtkTextIter *iter,
ch = gtk_text_iter_get_char (iter);
begin_class = classify (ch);
+ if (begin_class == CLASS_NEWLINE)
+ {
+ gtk_text_iter_backward_char (iter);
+ return TRUE;
+ }
+
for (;;)
{
if (!gtk_text_iter_forward_char (iter))
@@ -396,7 +451,7 @@ _ide_text_iter_forward_classified_end (GtkTextIter *iter,
ch = gtk_text_iter_get_char (iter);
cur_class = classify (ch);
- if (cur_class != begin_class)
+ if (cur_class != begin_class || cur_class == CLASS_NEWLINE)
{
gtk_text_iter_backward_char (iter);
return TRUE;
@@ -407,15 +462,23 @@ _ide_text_iter_forward_classified_end (GtkTextIter *iter,
}
gboolean
-_ide_text_iter_forward_word_end (GtkTextIter *iter)
+_ide_text_iter_forward_word_end (GtkTextIter *iter,
+ gboolean newline_stop)
{
- return _ide_text_iter_forward_classified_end (iter, _ide_text_word_classify);
+ if (newline_stop)
+ return _ide_text_iter_forward_classified_end (iter, _ide_text_word_classify_newline_stop);
+ else
+ return _ide_text_iter_forward_classified_end (iter, _ide_text_word_classify);
}
gboolean
-_ide_text_iter_forward_WORD_end (GtkTextIter *iter)
+_ide_text_iter_forward_WORD_end (GtkTextIter *iter,
+ gboolean newline_stop)
{
- return _ide_text_iter_forward_classified_end (iter, _ide_text_WORD_classify);
+ if (newline_stop)
+ return _ide_text_iter_forward_classified_end (iter, _ide_text_WORD_classify_newline_stop);
+ else
+ return _ide_text_iter_forward_classified_end (iter, _ide_text_WORD_classify);
}
static gboolean
@@ -431,6 +494,12 @@ _ide_text_iter_backward_classified_end (GtkTextIter *iter,
ch = gtk_text_iter_get_char (iter);
begin_class = classify (ch);
+ if (begin_class == CLASS_NEWLINE)
+ {
+ gtk_text_iter_forward_char (iter);
+ return TRUE;
+ }
+
for (;;)
{
if (!gtk_text_iter_backward_char (iter))
@@ -439,6 +508,12 @@ _ide_text_iter_backward_classified_end (GtkTextIter *iter,
ch = gtk_text_iter_get_char (iter);
cur_class = classify (ch);
+ if (cur_class == CLASS_NEWLINE)
+ {
+ gtk_text_iter_forward_char (iter);
+ return TRUE;
+ }
+
/* reset begin_class if we hit space, we can take anything after that */
if (cur_class == CLASS_SPACE)
begin_class = CLASS_SPACE;
@@ -451,15 +526,88 @@ _ide_text_iter_backward_classified_end (GtkTextIter *iter,
}
gboolean
-_ide_text_iter_backward_word_end (GtkTextIter *iter)
+_ide_text_iter_backward_word_end (GtkTextIter *iter,
+ gboolean newline_stop)
+{
+ if (newline_stop)
+ return _ide_text_iter_backward_classified_end (iter, _ide_text_word_classify_newline_stop);
+ else
+ return _ide_text_iter_backward_classified_end (iter, _ide_text_word_classify);
+}
+
+gboolean
+_ide_text_iter_backward_WORD_end (GtkTextIter *iter,
+ gboolean newline_stop)
+{
+ if (newline_stop)
+ return _ide_text_iter_backward_classified_end (iter, _ide_text_WORD_classify_newline_stop);
+ else
+ return _ide_text_iter_backward_classified_end (iter, _ide_text_WORD_classify);
+}
+
+static gboolean
+_ide_text_iter_backward_classified_start (GtkTextIter *iter,
+ gint (*classify) (gunichar))
+{
+ gunichar ch;
+ gint begin_class;
+ gint cur_class;
+
+ g_assert (iter);
+
+ if (!gtk_text_iter_backward_char (iter))
+ return FALSE;
+
+ /* If we are on space, walk to the end of the previous word. */
+ ch = gtk_text_iter_get_char (iter);
+ if (classify (ch) == CLASS_SPACE)
+ if (!_ide_text_iter_backward_classified_end (iter, classify))
+ return FALSE;
+
+ ch = gtk_text_iter_get_char (iter);
+ begin_class = classify (ch);
+ if (begin_class == CLASS_NEWLINE)
+ {
+ gtk_text_iter_forward_char (iter);
+ return TRUE;
+ }
+
+ for (;;)
+ {
+ if (!gtk_text_iter_backward_char (iter))
+ return FALSE;
+
+ ch = gtk_text_iter_get_char (iter);
+ cur_class = classify (ch);
+
+ if (cur_class != begin_class || cur_class == CLASS_NEWLINE)
+ {
+ gtk_text_iter_forward_char (iter);
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+gboolean
+_ide_text_iter_backward_word_start (GtkTextIter *iter,
+ gboolean newline_stop)
{
- return _ide_text_iter_backward_classified_end (iter, _ide_text_word_classify);
+ if (newline_stop)
+ return _ide_text_iter_backward_classified_start (iter, _ide_text_word_classify_newline_stop);
+ else
+ return _ide_text_iter_backward_classified_start (iter, _ide_text_word_classify);
}
gboolean
-_ide_text_iter_backward_WORD_end (GtkTextIter *iter)
+_ide_text_iter_backward_WORD_start (GtkTextIter *iter,
+ gboolean newline_stop)
{
- return _ide_text_iter_backward_classified_end (iter, _ide_text_WORD_classify);
+ if (newline_stop)
+ return _ide_text_iter_backward_classified_start (iter, _ide_text_WORD_classify_newline_stop);
+ else
+ return _ide_text_iter_backward_classified_start (iter, _ide_text_WORD_classify);
}
static gboolean
diff --git a/libide/sourceview/ide-text-iter.h b/libide/sourceview/ide-text-iter.h
index 0148fbb..f3479d0 100644
--- a/libide/sourceview/ide-text-iter.h
+++ b/libide/sourceview/ide-text-iter.h
@@ -19,6 +19,7 @@
#ifndef IDE_TEXT_ITER_H
#define IDE_TEXT_ITER_H
+
#include <gtk/gtk.h>
G_BEGIN_DECLS
@@ -35,16 +36,26 @@ gboolean _ide_text_iter_backward_find_char (GtkTextIter *iter
IdeTextIterCharPredicate pred,
gpointer user_data,
const GtkTextIter *limit);
-gboolean _ide_text_iter_forward_word_start (GtkTextIter *iter);
-gboolean _ide_text_iter_forward_WORD_start (GtkTextIter *iter);
-gboolean _ide_text_iter_forward_word_end (GtkTextIter *iter);
-gboolean _ide_text_iter_forward_WORD_end (GtkTextIter *iter);
+gboolean _ide_text_iter_forward_word_start (GtkTextIter *iter,
+ gboolean newline_stop);
+gboolean _ide_text_iter_forward_WORD_start (GtkTextIter *iter,
+ gboolean newline_stop);
+gboolean _ide_text_iter_forward_word_end (GtkTextIter *iter,
+ gboolean newline_stop);
+gboolean _ide_text_iter_forward_WORD_end (GtkTextIter *iter,
+ gboolean newline_stop);
gboolean _ide_text_iter_backward_paragraph_start (GtkTextIter *iter);
gboolean _ide_text_iter_forward_paragraph_end (GtkTextIter *iter);
gboolean _ide_text_iter_backward_sentence_start (GtkTextIter *iter);
gboolean _ide_text_iter_forward_sentence_end (GtkTextIter *iter);
-gboolean _ide_text_iter_backward_WORD_end (GtkTextIter *iter);
-gboolean _ide_text_iter_backward_word_end (GtkTextIter *iter);
+gboolean _ide_text_iter_backward_WORD_start (GtkTextIter *iter,
+ gboolean newline_stop);
+gboolean _ide_text_iter_backward_word_start (GtkTextIter *iter,
+ gboolean newline_stop);
+gboolean _ide_text_iter_backward_WORD_end (GtkTextIter *iter,
+ gboolean newline_stop);
+gboolean _ide_text_iter_backward_word_end (GtkTextIter *iter,
+ gboolean newline_stop);
gboolean _ide_text_iter_in_string (GtkTextIter *iter,
const gchar *str,
GtkTextIter *str_start,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]