[gnome-builder] vim: fix 'de' 'db' 'dw'
- From: Sébastien Lafargue <slafargue src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] vim: fix 'de' 'db' 'dw'
- Date: Thu, 28 Sep 2017 21:16:15 +0000 (UTC)
commit e63490c38377463237d98633e90848cd9035a200
Author: Sebastien Lafargue <slafargue gnome org>
Date: Thu Sep 28 23:15:02 2017 +0200
vim: fix 'de' 'db' 'dw'
src/libide/keybindings/vim.css | 12 +-
src/libide/sourceview/ide-source-view-movements.c | 67 +++++++-
src/libide/sourceview/ide-source-view.h | 10 ++
src/libide/sourceview/ide-text-iter.c | 177 +++++++++++++++++++--
src/libide/sourceview/ide-text-iter.h | 22 ++-
5 files changed, 253 insertions(+), 35 deletions(-)
---
diff --git a/src/libide/keybindings/vim.css b/src/libide/keybindings/vim.css
index 361da9a..ed8aee6 100644
--- a/src/libide/keybindings/vim.css
+++ b/src/libide/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/src/libide/sourceview/ide-source-view-movements.c
b/src/libide/sourceview/ide-source-view-movements.c
index fa5365e..9ac0ad5 100644
--- a/src/libide/sourceview/ide-source-view-movements.c
+++ b/src/libide/sourceview/ide-source-view-movements.c
@@ -52,6 +52,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 */
@@ -1494,7 +1497,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);
@@ -1512,7 +1515,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);
@@ -1530,7 +1533,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);
@@ -1548,7 +1551,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);
@@ -1566,7 +1569,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.
@@ -1586,7 +1589,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.
@@ -1606,7 +1609,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.
@@ -1630,7 +1633,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.
@@ -2050,21 +2053,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;
@@ -2079,21 +2106,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/src/libide/sourceview/ide-source-view.h b/src/libide/sourceview/ide-source-view.h
index 13e4ee3..717931e 100644
--- a/src/libide/sourceview/ide-source-view.h
+++ b/src/libide/sourceview/ide-source-view.h
@@ -158,6 +158,16 @@ typedef enum
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/src/libide/sourceview/ide-text-iter.c b/src/libide/sourceview/ide-text-iter.c
index aea3e83..434bf0a 100644
--- a/src/libide/sourceview/ide-text-iter.c
+++ b/src/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,87 @@ _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)
{
- return _ide_text_iter_backward_classified_end (iter, _ide_text_word_classify);
+ 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)
+_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))
{
- return _ide_text_iter_backward_classified_end (iter, _ide_text_WORD_classify);
+ 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;
+
+ 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)
+{
+ 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_start (GtkTextIter *iter,
+ gboolean newline_stop)
+{
+ 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/src/libide/sourceview/ide-text-iter.h b/src/libide/sourceview/ide-text-iter.h
index 8bb9016..4123f67 100644
--- a/src/libide/sourceview/ide-text-iter.h
+++ b/src/libide/sourceview/ide-text-iter.h
@@ -34,16 +34,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]