[vte/wip/egmont/bidi: 4/73] vte-34-match-span-exclusive-v2.patch



commit 8523b14f51e09fe25258707e8c93d66d60a3a0c0
Author: Egmont Koblinger <egmont gmail com>
Date:   Wed Sep 19 10:26:39 2018 +0200

    vte-34-match-span-exclusive-v2.patch

 src/vte.cc            |  8 +++++---
 src/vte/vteterminal.h |  2 +-
 src/vtetypes.cc       | 27 ++++++++++++++-------------
 src/vtetypes.hh       |  9 +++++----
 4 files changed, 25 insertions(+), 21 deletions(-)
---
diff --git a/src/vte.cc b/src/vte.cc
index c8708048..4603238c 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -1023,7 +1023,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;
                }
        }
@@ -5492,7 +5492,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 */
@@ -5697,6 +5698,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) {
@@ -10616,7 +10618,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);
 
diff --git a/src/vte/vteterminal.h b/src/vte/vteterminal.h
index b7f1f563..26ac236e 100644
--- a/src/vte/vteterminal.h
+++ b/src/vte/vteterminal.h
@@ -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,
diff --git a/src/vtetypes.cc b/src/vtetypes.cc
index 92a9db28..367e5290 100644
--- a/src/vtetypes.cc
+++ b/src/vtetypes.cc
@@ -111,7 +111,9 @@ 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]",
+        // FIXME what's the best notation for start-inclusive end-exclusive intervals?
+        // ".." is typically used for both-inclusive.
+        g_snprintf(buf, DEBUG_STRING_SIZE, "grid[%ld,%ld .. %ld,%ld)",
                    start_row(), start_column(), end_row(), end_column());
         return buf;
 }
@@ -254,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)));
 
@@ -266,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);
@@ -277,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
 }
 
diff --git a/src/vtetypes.hh b/src/vtetypes.hh
index 54d9f42d..e1bb775d 100644
--- a/src/vtetypes.hh
+++ b/src/vtetypes.hh
@@ -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)); }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]