[gtksourceview/wip/chergert/vim] implement toggle case
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/vim] implement toggle case
- Date: Fri, 29 Oct 2021 23:06:11 +0000 (UTC)
commit 4fe72df35bde696d272252509a3cc4dc610f2f39
Author: Christian Hergert <chergert redhat com>
Date: Fri Oct 29 16:06:02 2021 -0700
implement toggle case
and cleanup some other internal names. we'll use : for public ones that
we want to expose similar to VIM.
gtksourceview/vim/gtk-source-vim-command.c | 30 ++++++++++++++++++++++++++++--
gtksourceview/vim/gtk-source-vim-normal.c | 10 ++++++++--
2 files changed, 36 insertions(+), 4 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-command.c b/gtksourceview/vim/gtk-source-vim-command.c
index 4428842f..5279c704 100644
--- a/gtksourceview/vim/gtk-source-vim-command.c
+++ b/gtksourceview/vim/gtk-source-vim-command.c
@@ -214,6 +214,31 @@ gtk_source_vim_command_paste_before (GtkSourceVimCommand *self)
gtk_source_vim_state_end_user_action (GTK_SOURCE_VIM_STATE (self));
}
+static void
+gtk_source_vim_command_toggle_case (GtkSourceVimCommand *self)
+{
+ GtkSourceBuffer *buffer;
+ GtkTextIter iter;
+ GtkTextIter selection;
+
+ buffer = gtk_source_vim_state_get_buffer (GTK_SOURCE_VIM_STATE (self), &iter, &selection);
+
+ gtk_source_vim_state_begin_user_action (GTK_SOURCE_VIM_STATE (self));
+ gtk_source_buffer_change_case (buffer, GTK_SOURCE_CHANGE_CASE_TOGGLE, &iter, &selection);
+ gtk_source_vim_state_end_user_action (GTK_SOURCE_VIM_STATE (self));
+
+ if (gtk_text_iter_ends_line (&iter) &&
+ !gtk_text_iter_starts_line (&iter))
+ {
+ gtk_text_iter_backward_char (&iter);
+ gtk_source_vim_state_select (GTK_SOURCE_VIM_STATE (self), &iter, &iter);
+ }
+
+ gtk_source_vim_state_set_can_repeat (GTK_SOURCE_VIM_STATE (self), TRUE);
+
+ self->ignore_mark = TRUE;
+}
+
static void
gtk_source_vim_command_undo (GtkSourceVimCommand *self)
{
@@ -432,8 +457,9 @@ gtk_source_vim_command_class_init (GtkSourceVimCommandClass *klass)
ADD_COMMAND (":redo", gtk_source_vim_command_redo);
ADD_COMMAND (":yank", gtk_source_vim_command_yank);
ADD_COMMAND (":y", gtk_source_vim_command_yank);
- ADD_COMMAND (":_paste_after", gtk_source_vim_command_paste_after);
- ADD_COMMAND (":_paste_before", gtk_source_vim_command_paste_before);
+ ADD_COMMAND ("paste-after", gtk_source_vim_command_paste_after);
+ ADD_COMMAND ("paste-before", gtk_source_vim_command_paste_before);
+ ADD_COMMAND ("toggle-case", gtk_source_vim_command_toggle_case);
#undef ADD_COMMAND
}
diff --git a/gtksourceview/vim/gtk-source-vim-normal.c b/gtksourceview/vim/gtk-source-vim-normal.c
index 15c5a91f..ee03ef99 100644
--- a/gtksourceview/vim/gtk-source-vim-normal.c
+++ b/gtksourceview/vim/gtk-source-vim-normal.c
@@ -417,14 +417,20 @@ key_handler_command (GtkSourceVimNormal *self,
return TRUE;
case GDK_KEY_p:
- gtk_source_vim_normal_begin_command (self, NULL, NULL, ":_paste_after");
+ gtk_source_vim_normal_begin_command (self, NULL, NULL, "paste-after");
return TRUE;
case GDK_KEY_P:
- gtk_source_vim_normal_begin_command (self, NULL, NULL, ":_paste_before");
+ gtk_source_vim_normal_begin_command (self, NULL, NULL, "paste-before");
return TRUE;
case GDK_KEY_asciitilde:
+ gtk_source_vim_normal_begin_command (self,
+ gtk_source_vim_motion_new_forward_char (),
+ NULL,
+ "toggle-case");
+ return TRUE;
+
case GDK_KEY_equal:
case GDK_KEY_plus:
default:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]