[gtksourceview/wip/chergert/vim: 353/363] motion to move to marks
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/vim: 353/363] motion to move to marks
- Date: Mon, 8 Nov 2021 19:53:56 +0000 (UTC)
commit 801ae2211a28238adaab411d2ff20655d8164ff9
Author: Christian Hergert <chergert redhat com>
Date: Sun Nov 7 11:46:51 2021 -0800
motion to move to marks
gtksourceview/vim/gtk-source-vim-motion.c | 48 +++++++++++++++++++++++++++++++
gtksourceview/vim/gtk-source-vim-normal.c | 2 ++
2 files changed, 50 insertions(+)
---
diff --git a/gtksourceview/vim/gtk-source-vim-motion.c b/gtksourceview/vim/gtk-source-vim-motion.c
index 0eae6609..debec06d 100644
--- a/gtksourceview/vim/gtk-source-vim-motion.c
+++ b/gtksourceview/vim/gtk-source-vim-motion.c
@@ -111,6 +111,10 @@ struct _GtkSourceVimMotion
* as paragraph or sentence movements.
*/
MotionWise wise : 1;
+
+ /* Jumping to marks */
+ guint mark_charwise : 1;
+ guint mark_linewise : 1;
};
G_DEFINE_TYPE (GtkSourceVimMotion, gtk_source_vim_motion, GTK_SOURCE_TYPE_VIM_STATE)
@@ -1560,6 +1564,29 @@ motion_matching_char (GtkTextIter *iter,
return ret;
}
+static gboolean
+motion_mark (GtkTextIter *iter,
+ GtkSourceVimMotion *self)
+{
+ char str[8];
+
+ str[g_unichar_to_utf8 (self->f_char, str)] = 0;
+
+ if (gtk_source_vim_state_get_iter_at_mark (GTK_SOURCE_VIM_STATE (self), str, iter))
+ {
+ if (self->mark_linewise)
+ {
+ gtk_text_iter_set_line_offset (iter, 0);
+ while (!gtk_text_iter_ends_line (iter) && iter_isspace (iter))
+ gtk_text_iter_forward_char (iter);
+ }
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
static gboolean
gtk_source_vim_motion_handle_keypress (GtkSourceVimState *state,
guint keyval,
@@ -1635,6 +1662,19 @@ gtk_source_vim_motion_handle_keypress (GtkSourceVimState *state,
}
}
+ if (self->mark_linewise || self->mark_charwise)
+ {
+ if (!g_ascii_isalpha (string[0]))
+ return gtk_source_vim_motion_bail (self);
+
+ self->f_char = string[0];
+
+ if (self->mark_linewise)
+ return gtk_source_vim_motion_complete (self, motion_mark, INCLUSIVE, LINEWISE);
+ else
+ return gtk_source_vim_motion_complete (self, motion_mark, EXCLUSIVE, CHARWISE);
+ }
+
if (gtk_source_vim_state_get_count_set (state) && get_number (keyval, &n))
{
count = count * 10 + n;
@@ -1829,6 +1869,14 @@ gtk_source_vim_motion_handle_keypress (GtkSourceVimState *state,
case GDK_KEY_percent:
return gtk_source_vim_motion_complete (self, motion_matching_char, EXCLUSIVE,
CHARWISE);
+ case GDK_KEY_grave:
+ self->mark_charwise = TRUE;
+ return TRUE;
+
+ case GDK_KEY_apostrophe:
+ self->mark_linewise = TRUE;
+ return TRUE;
+
default:
return gtk_source_vim_motion_bail (self);
}
diff --git a/gtksourceview/vim/gtk-source-vim-normal.c b/gtksourceview/vim/gtk-source-vim-normal.c
index 7455121a..e192b11f 100644
--- a/gtksourceview/vim/gtk-source-vim-normal.c
+++ b/gtksourceview/vim/gtk-source-vim-normal.c
@@ -1093,6 +1093,7 @@ key_handler_initial (GtkSourceVimNormal *self,
{
case GDK_KEY_0:
case GDK_KEY_KP_0:
+ case GDK_KEY_apostrophe:
case GDK_KEY_asciicircum:
case GDK_KEY_asterisk:
case GDK_KEY_b:
@@ -1110,6 +1111,7 @@ key_handler_initial (GtkSourceVimNormal *self,
case GDK_KEY_End:
case GDK_KEY_f:
case GDK_KEY_F:
+ case GDK_KEY_grave:
case GDK_KEY_G:
case GDK_KEY_h:
case GDK_KEY_H:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]