Commit 58f451a5 authored by Egmont Koblinger's avatar Egmont Koblinger

widget: Convert vte::grid::span to end-exclusive

Also fix highlighting when the last character of a match is of double width.

#34
parent 79f74ded
......@@ -1006,7 +1006,7 @@ Terminal::match_rowcol_to_offset(vte::grid::column_t column,
eattr = offset;
}
if (row == attr->row &&
column == attr->column) {
column >= attr->column && column < attr->column + attr->columns) {
break;
}
}
......@@ -5473,7 +5473,8 @@ Terminal::match_hilite_update()
struct _VteCharAttributes,
end);
m_match_span = vte::grid::span(sa->row, sa->column, ea->row, ea->column);
/* convert from inclusive to exclusive (a.k.a. boundary) ending, taking a possible last CJK character into account */
m_match_span = vte::grid::span(sa->row, sa->column, ea->row, ea->column + ea->columns);
}
g_assert(!m_match); /* from match_hilite_clear() above */
......@@ -5678,6 +5679,7 @@ Terminal::get_text(vte::grid::row_t start_row,
attr.back.blue = back.blue;
attr.underline = (pcell->attr.underline() == 1);
attr.strikethrough = pcell->attr.strikethrough();
attr.columns = pcell->attr.columns();
/* Store the cell string */
if (pcell->c == 0) {
......@@ -10606,7 +10608,7 @@ Terminal::search_rows(pcre2_match_context_8 *match_context,
start_col = ca->column;
ca = &g_array_index (attrs, VteCharAttributes, end - 1);
end_row = ca->row;
end_col = ca->column;
end_col = ca->column + ca->columns - 1 /* select_text is end-inclusive */;
g_string_free (row_text, TRUE);
......
......@@ -115,7 +115,7 @@ struct _VteCharAttributes {
/*< private >*/
long row, column;
PangoColor fore, back;
guint underline:1, strikethrough:1;
guint underline:1, strikethrough:1, columns:4;
};
typedef gboolean (*VteSelectionFunc)(VteTerminal *terminal,
......
......@@ -111,7 +111,7 @@ vte::grid::span::to_string() const
return "grid[empty]";
char *buf = debug_get_buf();
g_snprintf(buf, DEBUG_STRING_SIZE, "grid[%ld,%ld .. %ld,%ld]",
g_snprintf(buf, DEBUG_STRING_SIZE, "grid[(%ld,%ld), (%ld,%ld))",
start_row(), start_column(), end_row(), end_column());
return buf;
}
......@@ -256,8 +256,7 @@ test_grid_span (void)
g_assert_false(s6.contains(coords(16, 15)));
g_assert_true (s6.contains(coords(16, 16)));
g_assert_true (s6.contains(coords(16, 31)));
g_assert_true (s6.contains(coords(16, 32)));
g_assert_false(s6.contains(coords(16, 33)));
g_assert_false(s6.contains(coords(16, 32)));
g_assert_false(s6.contains(coords(17, 15)));
g_assert_false(s6.contains(coords(17, 16)));
......@@ -268,8 +267,8 @@ test_grid_span (void)
g_assert_true (s7.contains(coords(16, 42)));
g_assert_true (s7.contains(coords(17, 42)));
g_assert_true (s7.contains(coords(31, 100)));
g_assert_true (s7.contains(coords(32, 8)));
g_assert_false(s7.contains(coords(32, 9)));
g_assert_true (s7.contains(coords(32, 7)));
g_assert_false(s7.contains(coords(32, 8)));
g_assert_false(s7.contains(coords(33, 2)));
span s8(16, 16, 32, 32);
......@@ -279,25 +278,25 @@ test_grid_span (void)
g_assert_false(s8.box_contains(coords(16, 15)));
g_assert_true (s8.box_contains(coords(16, 16)));
g_assert_true (s8.box_contains(coords(16, 24)));
g_assert_true (s8.box_contains(coords(16, 32)));
g_assert_false(s8.box_contains(coords(16, 33)));
g_assert_true (s8.box_contains(coords(16, 31)));
g_assert_false(s8.box_contains(coords(16, 32)));
g_assert_false(s8.box_contains(coords(24, 15)));
g_assert_true (s8.box_contains(coords(24, 16)));
g_assert_true (s8.box_contains(coords(24, 24)));
g_assert_true (s8.box_contains(coords(24, 32)));
g_assert_false(s8.box_contains(coords(24, 33)));
g_assert_true (s8.box_contains(coords(24, 31)));
g_assert_false(s8.box_contains(coords(24, 32)));
g_assert_false(s8.box_contains(coords(32, 15)));
g_assert_true (s8.box_contains(coords(32, 16)));
g_assert_true (s8.box_contains(coords(32, 24)));
g_assert_true (s8.box_contains(coords(32, 32)));
g_assert_false(s8.box_contains(coords(32, 33)));
g_assert_true (s8.box_contains(coords(32, 31)));
g_assert_false(s8.box_contains(coords(32, 32)));
g_assert_false(s8.box_contains(coords(33, 15)));
g_assert_false(s8.box_contains(coords(33, 24)));
g_assert_false(s8.box_contains(coords(3, 42)));
g_assert_false(s8.box_contains(coords(33, 42)));
#ifdef VTE_DEBUG
/* to_string() */
g_assert_cmpstr(vte::grid::span(17, 42, 18, 3).to_string(), ==, "grid[17,42 .. 18,3]");
g_assert_cmpstr(vte::grid::span(17, 42, 18, 3).to_string(), ==, "grid[(17,42), (18,3))");
#endif
}
......
......@@ -63,6 +63,7 @@ namespace grid {
column_t m_column;
};
/* end is exclusive (or: start and end point to boundaries between cells) */
struct span {
public:
span() = default;
......@@ -83,13 +84,13 @@ namespace grid {
inline column_t start_column() const { return m_start.column(); }
inline column_t end_column() const { return m_end.column(); }
inline void clear() { m_start = coords(-1, -1); m_end = coords(-2, -2); }
inline bool empty() const { return m_start > m_end; }
inline void clear() { m_start = coords(-1, -1); m_end = coords(-1, -1); }
inline bool empty() const { return m_start >= m_end; }
inline explicit operator bool() const { return !empty(); }
inline bool contains(coords const& p) const { return m_start <= p && p <= m_end; }
inline bool contains(coords const& p) const { return m_start <= p && p < m_end; }
inline bool box_contains(coords const& p) const { return m_start.row() <= p.row() && p.row() <= m_end.row() &&
m_start.column() <= p.column() && p.column() <= m_end.column(); }
m_start.column() <= p.column() && p.column() < m_end.column(); }
inline bool contains(row_t row, column_t column) { return contains(coords(row, column)); }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment