[gnome-builder] vim: Add 'r' replace command
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] vim: Add 'r' replace command
- Date: Sun, 12 Oct 2014 22:15:31 +0000 (UTC)
commit 1f7082446343bc1e329686c8ffc57fe21ab92c59
Author: Hashem Nasarat <hashem riseup net>
Date: Sun Oct 12 18:07:23 2014 -0400
vim: Add 'r' replace command
This replaces the character under the cursor with the modifier.
Unfortunately getting the cursor to be centered over the new character
(in all cases, especially at the end of a line) was rather convoluted.
https://bugzilla.gnome.org/show_bug.cgi?id=738419
src/editor/gb-editor-vim.c | 41 +++++++++++++++++++++++++++++++++++++++++
1 files changed, 41 insertions(+), 0 deletions(-)
---
diff --git a/src/editor/gb-editor-vim.c b/src/editor/gb-editor-vim.c
index 088a5f9..44385de 100644
--- a/src/editor/gb-editor-vim.c
+++ b/src/editor/gb-editor-vim.c
@@ -4149,6 +4149,43 @@ gb_editor_vim_cmd_overwrite (GbEditorVim *vim,
}
static void
+gb_editor_vim_cmd_replace (GbEditorVim *vim,
+ guint count,
+ gchar modifier)
+{
+ GtkTextBuffer *buffer;
+ GtkTextIter begin, end;
+ gboolean at_end;
+
+ g_assert (GB_IS_EDITOR_VIM (vim));
+
+ buffer = gtk_text_view_get_buffer (vim->priv->text_view);
+
+ gtk_text_buffer_begin_user_action (buffer);
+ gb_editor_vim_delete_selection (vim);
+
+ gtk_text_buffer_get_selection_bounds (buffer, &begin, &end);
+ gtk_text_iter_forward_char (&begin);
+ if (gtk_text_iter_ends_line (&begin))
+ {
+ at_end = TRUE;
+ }
+ else
+ {
+ gtk_text_iter_backward_char (&begin);
+ at_end = FALSE;
+ }
+
+ gtk_text_buffer_insert (buffer, &begin, &modifier, 1);
+ if (at_end)
+ gb_editor_vim_move_forward (vim);
+ else
+ gb_editor_vim_move_backward (vim);
+
+ gtk_text_buffer_end_user_action (buffer);
+}
+
+static void
gb_editor_vim_cmd_substitute (GbEditorVim *vim,
guint count,
gchar modifier)
@@ -4628,6 +4665,10 @@ gb_editor_vim_class_init (GbEditorVimClass *klass)
GB_EDITOR_VIM_COMMAND_FLAG_NONE,
GB_EDITOR_VIM_COMMAND_CHANGE,
gb_editor_vim_cmd_overwrite);
+ gb_editor_vim_class_register_command (klass, 'r',
+ GB_EDITOR_VIM_COMMAND_FLAG_REQUIRES_MODIFIER,
+ GB_EDITOR_VIM_COMMAND_CHANGE,
+ gb_editor_vim_cmd_replace);
gb_editor_vim_class_register_command (klass, 's',
GB_EDITOR_VIM_COMMAND_FLAG_NONE,
GB_EDITOR_VIM_COMMAND_CHANGE,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]