[gnome-text-editor] sourceview: add ctrl+l to select current line
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-text-editor] sourceview: add ctrl+l to select current line
- Date: Thu, 14 Oct 2021 22:19:53 +0000 (UTC)
commit 7a5b6825663ac6acd77a29fb8bbba0f4bf8b415d
Author: Christian Hergert <chergert redhat com>
Date: Thu Oct 14 15:16:44 2021 -0700
sourceview: add ctrl+l to select current line
It appears that ctrl+l is fairly common select current line functionality,
so we can go ahead and follow suit.
Additionally, you can repeatedly press ctrl+l to select an additional
line. Furthermore, the current selection is extended to boundaries so you
can take a word selection and expand it to the whole line w/ ctrl+l.
Fixes #191
src/editor-source-view.c | 38 ++++++++++++++++++++++++++++++++++++++
src/help-overlay.ui | 6 ++++++
2 files changed, 44 insertions(+)
---
diff --git a/src/editor-source-view.c b/src/editor-source-view.c
index 0d45f17..5a353ef 100644
--- a/src/editor-source-view.c
+++ b/src/editor-source-view.c
@@ -342,6 +342,42 @@ editor_source_view_action_zoom (GtkWidget *widget,
editor_source_view_update_css (self);
}
+static void
+editor_source_view_action_select_line (GtkWidget *widget,
+ const char *action_name,
+ GVariant *param)
+{
+ EditorSourceView *self = (EditorSourceView *)widget;
+ GtkTextBuffer *buffer;
+ GtkTextIter begin, end;
+
+ g_assert (EDITOR_IS_SOURCE_VIEW (self));
+
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (self));
+ gtk_text_buffer_get_selection_bounds (buffer, &begin, &end);
+ gtk_text_iter_order (&begin, &end);
+
+ /* Move beginning of selection/cursor to position 0 of first */
+ if (!gtk_text_iter_starts_line (&begin))
+ gtk_text_iter_set_line_offset (&begin, 0);
+
+ /* Move end of selection/cursor to end of line */
+ if (!gtk_text_iter_ends_line (&end))
+ gtk_text_iter_forward_to_line_end (&end);
+
+ /* Swallow the \n with the selection */
+ if (!gtk_text_iter_is_end (&end))
+ gtk_text_iter_forward_char (&end);
+
+ gtk_text_buffer_select_range (buffer, &begin, &end);
+
+ /* NOTE: This shouldn't be needed, but due to some invalidation issues in
+ * the line display cache, seems to improve chances we get proper
+ * invalidation lines within cache.
+ */
+ gtk_widget_queue_draw (widget);
+}
+
static void
editor_source_view_constructed (GObject *object)
{
@@ -428,12 +464,14 @@ editor_source_view_class_init (EditorSourceViewClass *klass)
gtk_widget_class_install_action (widget_class, "spelling.add", NULL,
editor_source_view_action_spelling_add);
gtk_widget_class_install_action (widget_class, "spelling.ignore", NULL,
editor_source_view_action_spelling_ignore);
gtk_widget_class_install_action (widget_class, "spelling.correct", "s",
editor_source_view_action_spelling_correct);
+ gtk_widget_class_install_action (widget_class, "buffer.select-line", NULL,
editor_source_view_action_select_line);
gtk_widget_class_add_binding_action (widget_class, GDK_KEY_plus, GDK_CONTROL_MASK, "page.zoom-in", NULL);
gtk_widget_class_add_binding_action (widget_class, GDK_KEY_KP_Add, GDK_CONTROL_MASK, "page.zoom-in", NULL);
gtk_widget_class_add_binding_action (widget_class, GDK_KEY_minus, GDK_CONTROL_MASK, "page.zoom-out", NULL);
gtk_widget_class_add_binding_action (widget_class, GDK_KEY_KP_Subtract, GDK_CONTROL_MASK, "page.zoom-out",
NULL);
gtk_widget_class_add_binding_action (widget_class, GDK_KEY_0, GDK_CONTROL_MASK, "page.zoom-one", NULL);
+ gtk_widget_class_add_binding_action (widget_class, GDK_KEY_l, GDK_CONTROL_MASK, "buffer.select-line",
NULL);
gtk_widget_class_add_binding_signal (widget_class,
GDK_KEY_d, GDK_CONTROL_MASK,
diff --git a/src/help-overlay.ui b/src/help-overlay.ui
index e6f56ef..d958f19 100644
--- a/src/help-overlay.ui
+++ b/src/help-overlay.ui
@@ -225,6 +225,12 @@
<property name="title" translatable="yes" context="shortcut window">Unselect all</property>
</object>
</child>
+ <child>
+ <object class="GtkShortcutsShortcut">
+ <property name="accelerator"><ctrl>l</property>
+ <property name="title" translatable="yes" context="shortcut window">Select current
line</property>
+ </object>
+ </child>
</object>
</child>
<child>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]