Skip to content

Commit

Permalink
GUACAMOLE-1586: Don't add \n in clipboard if the line isn't finished.
Browse files Browse the repository at this point in the history
  • Loading branch information
corentin-soriano committed May 30, 2024
1 parent 7d004ce commit e70159a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
20 changes: 18 additions & 2 deletions src/terminal/select.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,17 +358,33 @@ void guac_terminal_select_end(guac_terminal* terminal) {
/* Otherwise, copy multiple rows */
else {

/* Get last char of the row */
guac_terminal_buffer_row* buffer_row = guac_terminal_buffer_get_row(terminal->buffer, start_row, 0);
int last_row_char = buffer_row->characters[buffer_row->length].value;

/* Store first row */
guac_terminal_clipboard_append_row(terminal, start_row, start_col, -1);

/* Store all middle rows */
for (int row = start_row + 1; row < end_row; row++) {
guac_common_clipboard_append(terminal->clipboard, "\n", 1);

/* Add new line only if the row above ended with a null character */
if (last_row_char == 0)
guac_common_clipboard_append(terminal->clipboard, "\n", 1);

/* Store middle row */
guac_terminal_clipboard_append_row(terminal, row, 0, -1);

/* Update to last char of current row */
buffer_row = guac_terminal_buffer_get_row(terminal->buffer, row, 0);
last_row_char = buffer_row->characters[buffer_row->length].value;
}

/* Add new line only if the row above ended with a null character */
if (last_row_char == 0)
guac_common_clipboard_append(terminal->clipboard, "\n", 1);

/* Store last row */
guac_common_clipboard_append(terminal->clipboard, "\n", 1);
guac_terminal_clipboard_append_row(terminal, end_row, 0, end_col);

}
Expand Down
7 changes: 7 additions & 0 deletions src/terminal/terminal-handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,13 @@ int guac_terminal_echo(guac_terminal* term, unsigned char c) {

/* Wrap if necessary */
if (term->cursor_col >= term->term_width) {

/* Assign 1 to the last column (out of screen) to avoid \n in clipboard */
guac_terminal_buffer_row* buffer_row =
guac_terminal_buffer_get_row(term->buffer, term->cursor_row, 0);
buffer_row->characters[buffer_row->length].value = 1;

/* New line */
term->cursor_col = 0;
guac_terminal_linefeed(term);
}
Expand Down
2 changes: 1 addition & 1 deletion src/terminal/terminal.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ void guac_terminal_reset(guac_terminal* term) {

/* Clear terminal */
for (row=0; row<term->term_height; row++)
guac_terminal_set_columns(term, row, 0, term->term_width, &(term->default_char));
guac_terminal_set_columns(term, row, 0, term->term_width-1, &(term->default_char));

}

Expand Down

0 comments on commit e70159a

Please sign in to comment.