[gnome-text-editor] view: keep cursor on first non-space char
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-text-editor] view: keep cursor on first non-space char
- Date: Fri, 12 Nov 2021 20:32:15 +0000 (UTC)
commit 4c22e38e7fc20c88439a3e3c0251cd2da2a90ed6
Author: Christian Hergert <chergert redhat com>
Date: Fri Nov 12 12:31:18 2021 -0800
view: keep cursor on first non-space char
When deleting lines using Ctrl+D we want to keep the cursor at the
beginning of the resulting line (but skip past space chars).
Related #215
src/editor-source-view.c | 7 +++++++
1 file changed, 7 insertions(+)
---
diff --git a/src/editor-source-view.c b/src/editor-source-view.c
index b83c63a..7a0556f 100644
--- a/src/editor-source-view.c
+++ b/src/editor-source-view.c
@@ -406,6 +406,13 @@ editor_source_view_action_delete_line (GtkWidget *widget,
text = gtk_text_iter_get_slice (&begin, &end);
gtk_text_buffer_delete (buffer, &begin, &end);
gtk_text_buffer_end_user_action (buffer);
+
+ /* now move the cursor to the beginning of the new line */
+ gtk_text_iter_set_line_offset (&begin, 0);
+ while (!gtk_text_iter_ends_line (&begin) &&
+ g_unichar_isspace (gtk_text_iter_get_char (&begin)))
+ gtk_text_iter_forward_char (&begin);
+ gtk_text_buffer_select_range (buffer, &begin, &begin);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]