Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate only current line when cursor is at the end of the line #649

Merged
merged 1 commit into from
Nov 25, 2024

Conversation

ghost
Copy link

@ghost ghost commented Jul 28, 2024

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.

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.
Copy link

@linewelder linewelder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, this could've been actually done more easily

Comment on lines 783 to +793
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);
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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);
}
}
if (gtk_text_iter_get_char (&end) != '\n' &&
gtk_text_iter_get_char (&end) != '\r')
{
gtk_text_iter_forward_to_line_end (&end);
}

@clefebvre clefebvre merged commit fe08c2c into linuxmint:master Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants