[gtksourceview/wip/chergert/vim: 171/363] ctrl e/y in visual mode
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/vim: 171/363] ctrl e/y in visual mode
- Date: Mon, 8 Nov 2021 19:53:49 +0000 (UTC)
commit eb898a2ab791db88325214b34c4ef1e2607b62e3
Author: Christian Hergert <chergert redhat com>
Date: Sat Oct 30 14:58:27 2021 -0700
ctrl e/y in visual mode
gtksourceview/vim/gtk-source-vim-motion.c | 74 +++++++++++++++++++++++++++++++
1 file changed, 74 insertions(+)
---
diff --git a/gtksourceview/vim/gtk-source-vim-motion.c b/gtksourceview/vim/gtk-source-vim-motion.c
index 56d8f8c3..a24e0ed0 100644
--- a/gtksourceview/vim/gtk-source-vim-motion.c
+++ b/gtksourceview/vim/gtk-source-vim-motion.c
@@ -1062,6 +1062,9 @@ motion_next_scroll_page (GtkTextIter *iter,
GtkTextBuffer *buffer = gtk_text_iter_get_buffer (iter);
GtkTextMark *insert = gtk_text_buffer_get_insert (buffer);
+ if (self->apply_count != 1)
+ return FALSE;
+
gtk_source_vim_state_scroll_page (GTK_SOURCE_VIM_STATE (self), count);
gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (buffer), iter, insert);
@@ -1076,8 +1079,73 @@ motion_prev_scroll_page (GtkTextIter *iter,
GtkTextBuffer *buffer = gtk_text_iter_get_buffer (iter);
GtkTextMark *insert = gtk_text_buffer_get_insert (buffer);
+ if (self->apply_count != 1)
+ return FALSE;
+
gtk_source_vim_state_scroll_page (GTK_SOURCE_VIM_STATE (self), -count);
gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (buffer), iter, insert);
+ return TRUE;
+}
+
+static gboolean
+motion_prev_scroll_line (GtkTextIter *iter,
+ GtkSourceVimMotion *self)
+{
+ int count = gtk_source_vim_state_get_count (GTK_SOURCE_VIM_STATE (self));
+ GtkTextBuffer *buffer = gtk_text_iter_get_buffer (iter);
+ GtkTextMark *insert = gtk_text_buffer_get_insert (buffer);
+ GtkSourceView *view = gtk_source_vim_state_get_view (GTK_SOURCE_VIM_STATE (self));
+ GtkTextIter loc;
+ GdkRectangle rect;
+
+ if (self->apply_count != 1)
+ return FALSE;
+
+ gtk_source_vim_state_scroll_line (GTK_SOURCE_VIM_STATE (self), -count);
+ gtk_text_view_get_visible_rect (GTK_TEXT_VIEW (view), &rect);
+ gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (buffer), iter, insert);
+ gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (view), &loc, rect.x + rect.width, rect.y +
rect.height);
+
+ if (gtk_text_iter_compare (&loc, iter) < 0)
+ {
+ gtk_text_iter_set_line (iter, gtk_text_iter_get_line (&loc));
+ }
+
+ return TRUE;
+}
+
+static gboolean
+motion_next_scroll_line (GtkTextIter *iter,
+ GtkSourceVimMotion *self)
+{
+ int count = gtk_source_vim_state_get_count (GTK_SOURCE_VIM_STATE (self));
+ GtkTextBuffer *buffer = gtk_text_iter_get_buffer (iter);
+ GtkTextMark *insert = gtk_text_buffer_get_insert (buffer);
+ GtkSourceView *view = gtk_source_vim_state_get_view (GTK_SOURCE_VIM_STATE (self));
+ GtkTextIter loc;
+ GdkRectangle rect;
+
+ if (self->apply_count != 1)
+ return FALSE;
+
+ gtk_source_vim_state_scroll_line (GTK_SOURCE_VIM_STATE (self), count);
+ gtk_text_view_get_visible_rect (GTK_TEXT_VIEW (view), &rect);
+ gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (buffer), iter, insert);
+ gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (view), &loc, rect.x, rect.y);
+
+ if (gtk_text_iter_compare (&loc, iter) > 0)
+ {
+ gtk_text_iter_set_line (iter, gtk_text_iter_get_line (&loc));
+
+ if (!gtk_text_iter_ends_line (iter))
+ {
+ gtk_text_iter_forward_to_line_end (iter);
+ }
+
+ if (gtk_text_iter_ends_line (iter) &&
+ !gtk_text_iter_starts_line (iter))
+ gtk_text_iter_backward_char (iter);
+ }
return TRUE;
}
@@ -1183,6 +1251,12 @@ gtk_source_vim_motion_handle_keypress (GtkSourceVimState *state,
case GDK_KEY_b:
return gtk_source_vim_motion_complete (self, motion_prev_scroll_page,
INCLUSIVE);
+ case GDK_KEY_e:
+ return gtk_source_vim_motion_complete (self, motion_next_scroll_line,
INCLUSIVE);
+
+ case GDK_KEY_y:
+ return gtk_source_vim_motion_complete (self, motion_prev_scroll_line,
INCLUSIVE);
+
default:
break;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]