Merge pull request #674 from Warepire/vte-0.55.0-off-by-one

Fix off-by-one in select_text() on libvte >= 0.55.0
This commit is contained in:
jelle van der Waa 2019-05-10 15:41:58 +02:00 committed by GitHub
commit 0ea077c248
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 5 deletions

View File

@ -441,7 +441,7 @@ static void update_selection(VteTerminal *vte, const select_info *select) {
} }
const long n_columns = vte_terminal_get_column_count(vte); const long n_columns = vte_terminal_get_column_count(vte);
long cursor_col, cursor_row; long cursor_col, cursor_row, selection_x_end;
vte_terminal_get_cursor_position(vte, &cursor_col, &cursor_row); vte_terminal_get_cursor_position(vte, &cursor_col, &cursor_row);
vte_terminal_set_selection_block_mode(vte, select->mode == vi_mode::visual_block); vte_terminal_set_selection_block_mode(vte, select->mode == vi_mode::visual_block);
@ -450,22 +450,38 @@ static void update_selection(VteTerminal *vte, const select_info *select) {
const long begin = select->begin_row * n_columns + select->begin_col; const long begin = select->begin_row * n_columns + select->begin_col;
const long end = cursor_row * n_columns + cursor_col; const long end = cursor_row * n_columns + cursor_col;
if (begin < end) { if (begin < end) {
selection_x_end = cursor_col;
#if VTE_CHECK_VERSION(0, 55, 0)
selection_x_end += 1;
#endif
vte_terminal_select_text(vte, select->begin_col, select->begin_row, vte_terminal_select_text(vte, select->begin_col, select->begin_row,
cursor_col, cursor_row); selection_x_end, cursor_row);
} else { } else {
selection_x_end = select->begin_col;
#if VTE_CHECK_VERSION(0, 55, 0)
selection_x_end += 1;
#endif
vte_terminal_select_text(vte, cursor_col, cursor_row, vte_terminal_select_text(vte, cursor_col, cursor_row,
select->begin_col, select->begin_row); selection_x_end, select->begin_row);
} }
} else if (select->mode == vi_mode::visual_line) { } else if (select->mode == vi_mode::visual_line) {
selection_x_end = n_columns - 1;
#if VTE_CHECK_VERSION(0, 55, 0)
selection_x_end += 1;
#endif
vte_terminal_select_text(vte, 0, vte_terminal_select_text(vte, 0,
std::min(select->begin_row, cursor_row), std::min(select->begin_row, cursor_row),
n_columns - 1, selection_x_end,
std::max(select->begin_row, cursor_row)); std::max(select->begin_row, cursor_row));
} else if (select->mode == vi_mode::visual_block) { } else if (select->mode == vi_mode::visual_block) {
selection_x_end = std::max(select->begin_col, cursor_col);
#if VTE_CHECK_VERSION(0, 55, 0)
selection_x_end += 1;
#endif
vte_terminal_select_text(vte, vte_terminal_select_text(vte,
std::min(select->begin_col, cursor_col), std::min(select->begin_col, cursor_col),
std::min(select->begin_row, cursor_row), std::min(select->begin_row, cursor_row),
std::max(select->begin_col, cursor_col), selection_x_end,
std::max(select->begin_row, cursor_row)); std::max(select->begin_row, cursor_row));
} }