[gnome-builder] libide: leave cursor on proper line when joining lines
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] libide: leave cursor on proper line when joining lines
- Date: Tue, 24 Mar 2015 00:05:17 +0000 (UTC)
commit 845af0a0b1163008f591158e6b7134563b79dfe7
Author: Christian Hergert <christian hergert me>
Date: Fri Mar 6 17:59:36 2015 -0800
libide: leave cursor on proper line when joining lines
This fixes the situation that you join lines and the trailing line
(which has an iter at offset zero) is not empty. We put the insertion
mark back on the same line. Bindings can use this to place the cursor
wherever they want on the line that was actually joined.
libide/ide-source-view.c | 15 +++++++++++++++
1 files changed, 15 insertions(+), 0 deletions(-)
---
diff --git a/libide/ide-source-view.c b/libide/ide-source-view.c
index 204b013..640af1e 100644
--- a/libide/ide-source-view.c
+++ b/libide/ide-source-view.c
@@ -1869,14 +1869,29 @@ ide_source_view_real_join_lines (IdeSourceView *self)
GtkTextBuffer *buffer;
GtkTextIter begin;
GtkTextIter end;
+ guint line;
g_assert (IDE_IS_SOURCE_VIEW (self));
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (self));
gtk_text_buffer_get_selection_bounds (buffer, &begin, &end);
+ if (gtk_text_iter_equal (&begin, &end))
+ return;
+
+ gtk_text_iter_order (&begin, &end);
+
+ line = gtk_text_iter_get_line (&begin);
+
+ if (gtk_text_iter_starts_line (&end) && !gtk_text_iter_ends_line (&end))
+ gtk_text_iter_backward_char (&end);
+
if (GTK_SOURCE_IS_BUFFER (buffer))
gtk_source_buffer_join_lines (GTK_SOURCE_BUFFER (buffer), &begin, &end);
+
+ gtk_text_buffer_get_selection_bounds (buffer, &begin, &end);
+ gtk_text_iter_set_line (&begin, line);
+ gtk_text_buffer_select_range (buffer, &begin, &begin);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]