diff options
author | Egmont Koblinger <egmont@gmail.com> | 2018-11-26 00:38:13 +0100 |
---|---|---|
committer | Egmont Koblinger <egmont@gmail.com> | 2018-11-26 00:38:13 +0100 |
commit | e229ea34cadd21a5afcded56bc7b794e14e86649 (patch) | |
tree | 8fd7e828137e75ba8836efdff3d671c7ce88257d /src | |
parent | 7124ade774e73d9a4210607e8666dc98ab200acb (diff) | |
download | vte-e229ea34cadd21a5afcded56bc7b794e14e86649.tar.gz |
widget: Fix mouse selection to skip trailing unused cells
Regression from commit 4005f653ac7df5475066da7245b87d71f11e2c8b.
https://gitlab.gnome.org/GNOME/vte/issues/68
Diffstat (limited to 'src')
-rw-r--r-- | src/vte.cc | 16 | ||||
-rw-r--r-- | src/vterowdata.cc | 13 | ||||
-rw-r--r-- | src/vterowdata.hh | 1 |
3 files changed, 22 insertions, 8 deletions
@@ -5146,7 +5146,7 @@ Terminal::resolve_selection_endpoint(vte::grid::halfcoords const& rowcolhalf, bo } else { vte::grid::column_t char_begin, char_end; /* cell boundaries */ rowdata = find_row_data(row); - if (rowdata && col < rowdata->len) { + if (rowdata && col < _vte_row_data_nonempty_length(rowdata)) { /* Clicked over a used cell. Check for multi-cell characters. */ char_begin = col; while (char_begin > 0) { @@ -5169,7 +5169,7 @@ Terminal::resolve_selection_endpoint(vte::grid::halfcoords const& rowcolhalf, bo col = char_end; /* Maybe wrap to the beginning of the next line. */ - if (col > (rowdata ? rowdata->len : 0)) { + if (col > (rowdata ? _vte_row_data_nonempty_length(rowdata) : 0)) { col = 0; row++; } @@ -5188,7 +5188,7 @@ Terminal::resolve_selection_endpoint(vte::grid::halfcoords const& rowcolhalf, bo if (row > 0 && (rowdata = find_row_data(row - 1)) != nullptr && rowdata->attr.soft_wrapped && - (len = rowdata->len) > 0 && + (len = _vte_row_data_nonempty_length(rowdata)) > 0 && is_same_class(len - 1, row - 1, 0, row) /* invalidates rowdata! */) { if (!after) { col = len - 1; @@ -5201,7 +5201,7 @@ Terminal::resolve_selection_endpoint(vte::grid::halfcoords const& rowcolhalf, bo col = 0; /* end-exclusive */ break; /* done, don't expand any more */ } - } else if (col >= (rowdata ? rowdata->len : 0)) { + } else if (col >= (rowdata ? _vte_row_data_nonempty_length(rowdata) : 0)) { /* Clicked over the right margin, or right unused area. * - If within a word (that is, the last letter in this row, and the first * letter of the next row belong to the same word) then select the letter @@ -5212,7 +5212,7 @@ Terminal::resolve_selection_endpoint(vte::grid::halfcoords const& rowcolhalf, bo * - Otherwise select the newline only and stop. */ if (rowdata != nullptr && rowdata->attr.soft_wrapped) { - if ((len = rowdata->len) > 0 && + if ((len = _vte_row_data_nonempty_length(rowdata)) > 0 && is_same_class(len - 1, row, 0, row + 1) /* invalidates rowdata! */) { if (!after) { col = len - 1; @@ -5228,7 +5228,7 @@ Terminal::resolve_selection_endpoint(vte::grid::halfcoords const& rowcolhalf, bo } } else { if (!after) { - col = rowdata ? rowdata->len : 0; /* end-exclusive */ + col = rowdata ? _vte_row_data_nonempty_length(rowdata) : 0; /* end-exclusive */ } else { col = 0; /* end-exclusive */ row++; @@ -5261,7 +5261,7 @@ Terminal::resolve_selection_endpoint(vte::grid::halfcoords const& rowcolhalf, bo /* Reached a hard newline. */ break; } - len = rowdata->len; + len = _vte_row_data_nonempty_length(rowdata); /* len might be smaller than m_column_count if a CJK wrapped */ if (!is_same_class(len - 1, row - 1, col, row) /* invalidates rowdata! */) { break; @@ -5278,7 +5278,7 @@ Terminal::resolve_selection_endpoint(vte::grid::halfcoords const& rowcolhalf, bo if (!rowdata) { break; } - len = rowdata->len; + len = _vte_row_data_nonempty_length(rowdata); bool soft_wrapped = rowdata->attr.soft_wrapped; /* Move forward within the row. */ for (; col < len - 1; col++) { diff --git a/src/vterowdata.cc b/src/vterowdata.cc index 6b8efbdd..88edba1a 100644 --- a/src/vterowdata.cc +++ b/src/vterowdata.cc @@ -172,3 +172,16 @@ void _vte_row_data_shrink (VteRowData *row, gulong max_len) row->len = max_len; } +/* Get the length, ignoring trailing empty cells (with a custom background color). */ +guint16 _vte_row_data_nonempty_length (const VteRowData *row) +{ + guint16 len; + const VteCell *cell; + for (len = row->len; len > 0; len--) { + cell = &row->cells[len - 1]; + if (cell->attr.fragment() || cell->c != 0) + break; + } + return len; +} + diff --git a/src/vterowdata.hh b/src/vterowdata.hh index 4191cccb..9d4b2767 100644 --- a/src/vterowdata.hh +++ b/src/vterowdata.hh @@ -79,5 +79,6 @@ void _vte_row_data_append (VteRowData *row, const VteCell *cell); void _vte_row_data_remove (VteRowData *row, gulong col); void _vte_row_data_fill (VteRowData *row, const VteCell *cell, gulong len); void _vte_row_data_shrink (VteRowData *row, gulong max_len); +guint16 _vte_row_data_nonempty_length (const VteRowData *row); G_END_DECLS |