[vte/wip/egmont/bidi: 34/79] look back in scrollback to pass entire paragraphs to bidi



commit 6c1d468d55ae7254dbee929e4e95dfb2dba0d131
Author: Egmont Koblinger <egmont gmail com>
Date:   Thu Aug 23 21:38:05 2018 +0200

    look back in scrollback to pass entire paragraphs to bidi

 src/bidi.cc | 29 ++++++++++++++++++++++++++++-
 src/bidi.hh |  1 +
 2 files changed, 29 insertions(+), 1 deletion(-)
---
diff --git a/src/bidi.cc b/src/bidi.cc
index a11883a4..7fb67bae 100644
--- a/src/bidi.cc
+++ b/src/bidi.cc
@@ -102,8 +102,16 @@ void RingView::set_rows(long s, long l)
 void RingView::update()
 {
         long i = m_start;
+        const VteRowData *row_data = m_ring->index(m_start);
+
+        if (row_data->attr.bidi_flags & VTE_BIDI_IMPLICIT) {
+                i = find_paragraph(m_start);
+                if (i == -1) {
+                        i = explicit_paragraph(m_start, !!(row_data->attr.bidi_flags & VTE_BIDI_RTL));
+                }
+        }
         while (i < m_start + m_len) {
-                i = paragraph (i);
+                i = paragraph(i);
         }
 }
 
@@ -213,6 +221,25 @@ long RingView::explicit_paragraph(long row, bool rtl)
         return row;
 }
 
+/* For the given row, find the first row of its paragraph.
+ * Returns -1 if have to walk backwards too much. */
+/* FIXME this could be much cheaper, we don't need to read the actual rows (text_stream),
+ * we only need the soft_wrapped flag which is stored in row_stream. Needs method in ring. */
+long RingView::find_paragraph(long row)
+{
+        long row_stop = row - VTE_BIDI_PARAGRAPH_LENGTH_MAX;
+        const VteRowData *row_data;
+
+        while (row-- > row_stop) {
+                if (row == -1)
+                        return 0;
+                row_data = m_ring->index(row);
+                if (row_data == nullptr || !row_data->attr.soft_wrapped)
+                        return row + 1;
+        }
+        return -1;
+}
+
 /* Figure out the mapping for the paragraph starting at the given row.
  * Returns the row number after the paragraph or viewport (whichever ends first). */
 long RingView::paragraph(long row)
diff --git a/src/bidi.hh b/src/bidi.hh
index 09dfd079..ed53d472 100644
--- a/src/bidi.hh
+++ b/src/bidi.hh
@@ -75,6 +75,7 @@ private:
 
         void explicit_line(long row, bool rtl);
         long explicit_paragraph(long row, bool rtl);
+        long find_paragraph(long row);
         long paragraph(long row);
 };
 


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