From fe08c2cb995b5bef2632c2e1dcaea6dba6ee7acb Mon Sep 17 00:00:00 2001 From: Toni Ordning <176809438+Toni-Ordning@users.noreply.github.com> Date: Mon, 25 Nov 2024 13:00:16 +0200 Subject: [PATCH] Duplicate only current line when cursor is at the end of the line (#649) This fixes issue #643. When cursor is at the end of the line, old version would duplicate two lines: The line where the cursor is, and the line following it. This happened because the buffer that is being copied would include both lines and the newline separating them. This fix checks if there are multiple lines in the current buffer, and if so, moves buffers end iterator to the newline character, so that only the line where cursor is located is duplicated. --- xed/xed-view.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/xed/xed-view.c b/xed/xed-view.c index a037f3f8..8f698554 100644 --- a/xed/xed-view.c +++ b/xed/xed-view.c @@ -781,6 +781,16 @@ xed_view_duplicate (XedView *view) { gtk_text_iter_set_line_index (&start, 0); gtk_text_iter_forward_to_line_end (&end); + + if (gtk_text_buffer_get_line_count (buffer) > 1) + { + gtk_text_iter_assign (&end, &start); + while (gtk_text_iter_get_char (&end) != '\n' && + !gtk_text_iter_is_end (&end)) + { + gtk_text_iter_forward_char (&end); + } + } } gtk_text_iter_order (&start, &end);