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

GUACAMOLE-1586: Don't add \n in clipboard if the line isn't finished. #512

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

corentin-soriano
Copy link

In the case of selecting multiple lines, do not add \n if the line is not really finished.

Copy link
Contributor

@necouchman necouchman left a comment

Choose a reason for hiding this comment

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

I'm wondering if this entire section, including the if statement immediately above here, could be simplified to something like this:

guac_terminal_select_normalized_range(terminal, &start_row, &start_col, &end_row, &end_col);
int row = start_row;

do {

  // Copy the current row.
  guac_terminal_clipboard_append_row(terminal, row, start_col, end_col);
  guac_terminal_buffer_row* buffer_row = guac_terminal_buffer_get_row(terminal->buffer, row, 0);
  int last_char = buffer_row->characters[terminal->term_width - 1].value;

  if (last_char == 0)
      guac_common_clipboard_append(terminal->clipboard, "\n", 1);

  // Increment row
  row++;
}
while (row <= end_row);

?

I haven't actually tested that block of code, but it works in my head :-). I'm not sure if there's some reason that the code needs the extra if...else blocks, plus the loop? Maybe there are some corner cases that don't work - like if the last line does or does not end with a line break??

@corentin-soriano
Copy link
Author

We must keep this existing logic :

  • first row = start_col to $
  • middle rows = ^ to $
  • last row = ^ to end_col

With guac_terminal_clipboard_append_row(terminal, row, start_col, end_col); for each row, we risk having a rectangular selection of this type :
image
We need to keep this selection format here :
image

However, I noticed that if we select a row that has exactly the same number of columns as the display, it will be missing a \n :
Example :
image
Content of clipboard :

[root@vm01 ~]# echo -e "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\ntest\ntest2"
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeetest
test2

This case is very rare but can exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants