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-1961: improve terminal selection #556

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
67 changes: 48 additions & 19 deletions src/terminal/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ void guac_terminal_display_dup(
}

void guac_terminal_display_select(guac_terminal_display* display,
int start_row, int start_col, int end_row, int end_col) {
int start_row, int start_col, int end_row, int end_col, bool rectangle) {

guac_socket* socket = display->client->socket;
guac_layer* select_layer = display->select_layer;
Expand Down Expand Up @@ -943,38 +943,67 @@ void guac_terminal_display_select(guac_terminal_display* display,
start_row = end_row;
end_row = temp;

/* Don't swap columns if it's a rectangular selection and start_col
* is less than end_col */
if (!rectangle || start_col > end_col) {
temp = start_col;
start_col = end_col;
end_col = temp;
}

}

/* Swap columns on rectangular selection to bottom-left direction */
else if (rectangle && start_col > end_col) {

int temp;

temp = start_col;
start_col = end_col;
end_col = temp;

}

/* First row */
guac_protocol_send_rect(socket, select_layer,
/* Multilines rectangular selection */
if (rectangle) {
guac_protocol_send_rect(socket, select_layer,

start_col * display->char_width,
start_row * display->char_height,
start_col * display->char_width,
start_row * display->char_height,

display->width * display->char_width,
display->char_height);
(end_col - start_col + 1) * display->char_width,
(end_row - start_row + 1) * display->char_height);
}

/* Middle */
guac_protocol_send_rect(socket, select_layer,
/* Multilines standard selection */
else {
/* First row */
guac_protocol_send_rect(socket, select_layer,

0,
(start_row + 1) * display->char_height,
start_col * display->char_width,
start_row * display->char_height,

display->width * display->char_width,
(end_row - start_row - 1) * display->char_height);
display->width * display->char_width,
display->char_height);

/* Last row */
guac_protocol_send_rect(socket, select_layer,
/* Middle */
guac_protocol_send_rect(socket, select_layer,

0,
end_row * display->char_height,
0,
(start_row + 1) * display->char_height,

(end_col + 1) * display->char_width,
display->char_height);
display->width * display->char_width,
(end_row - start_row - 1) * display->char_height);

/* Last row */
guac_protocol_send_rect(socket, select_layer,

0,
end_row * display->char_height,

(end_col + 1) * display->char_width,
display->char_height);
}

}

Expand Down
42 changes: 35 additions & 7 deletions src/terminal/select.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,38 @@
static void guac_terminal_select_normalized_range(guac_terminal* terminal,
int* start_row, int* start_col, int* end_row, int* end_col) {


/* Columns coordinates must be swapped when selecting to bottom-left direction
* on rectangular selection mode. */
if (terminal->rectangle_selection
&& terminal->selection_start_row < terminal->selection_end_row
&& terminal->selection_start_column > terminal->selection_end_column) {

*start_row = terminal->selection_start_row;
*end_col = terminal->selection_start_column + terminal->selection_start_width - 1;
*end_row = terminal->selection_end_row;
*start_col = terminal->selection_end_column;

}

/* Rows coordinates must be swapped when selecting to top-right direction
* on rectangular selection mode. */
else if (terminal->rectangle_selection
&& terminal->selection_start_row > terminal->selection_end_row
&& terminal->selection_start_column < terminal->selection_end_column) {

*end_row = terminal->selection_start_row;
*start_col = terminal->selection_start_column;
*start_row = terminal->selection_end_row;
*end_col = terminal->selection_end_column + terminal->selection_end_width - 1;

}

/* Pass through start/end coordinates if they are already in the expected
* order, adjusting only for final character width */
if (terminal->selection_start_row < terminal->selection_end_row
|| (terminal->selection_start_row == terminal->selection_end_row
&& terminal->selection_start_column < terminal->selection_end_column)) {
else if (terminal->selection_start_row < terminal->selection_end_row
|| (terminal->selection_start_row == terminal->selection_end_row
&& terminal->selection_start_column < terminal->selection_end_column)) {

*start_row = terminal->selection_start_row;
*start_col = terminal->selection_start_column;
Expand Down Expand Up @@ -109,7 +136,8 @@ void guac_terminal_select_redraw(guac_terminal* terminal) {
else
end_column += terminal->selection_end_width - 1;

guac_terminal_display_select(terminal->display, start_row, start_column, end_row, end_column);
guac_terminal_display_select(terminal->display, start_row,
start_column, end_row, end_column, terminal->rectangle_selection);

}

Expand Down Expand Up @@ -364,7 +392,7 @@ void guac_terminal_select_end(guac_terminal* terminal) {
for (int row = start_row; row <= end_row; row++) {

/* Add a newline only if the previous line was not wrapped */
if (!last_row_was_wrapped)
if (!last_row_was_wrapped || (terminal->rectangle_selection && row != start_row))
guac_common_clipboard_append(terminal->clipboard, "\n", 1);

/* Append next row from desired region, adjusting the start/end column
Expand All @@ -373,8 +401,8 @@ void guac_terminal_select_end(guac_terminal* terminal) {
* copied in their entirety. */
int length = guac_terminal_buffer_get_columns(terminal->current_buffer, &characters, &last_row_was_wrapped, row);
guac_terminal_clipboard_append_characters(terminal, characters, length,
(row == start_row) ? start_col : 0,
(row == end_row) ? end_col : length - 1);
(row == start_row || terminal->rectangle_selection) ? start_col : 0,
(row == end_row || terminal->rectangle_selection) ? end_col : length - 1);

}

Expand Down
Loading