]> git.lyx.org Git - features.git/commitdiff
Store change bar information in row element
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Sat, 11 Nov 2017 10:57:39 +0000 (11:57 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 15 Feb 2018 11:29:25 +0000 (12:29 +0100)
It is wrong to compute this at paint time. In general, painting a row
should not require any access to a paragraph object, but we are far
from there now.

(cherry picked from commit 4858bb3bb68aac142815b530a017e3776d1c7c11)

src/Row.cpp
src/Row.h
src/RowPainter.cpp
src/TextMetrics.cpp

index db1bd2883cac54dd9acccfa50e9fa72496f41d2e..20ff63e22a41463ddd65efa4dc261cb8a9fb89d1 100644 (file)
@@ -164,7 +164,8 @@ Row::Row()
          begin_margin_sel(false), end_margin_sel(false),
          changed_(false), crc_(0),
          pit_(0), pos_(0), end_(0),
-         right_boundary_(false), flushed_(false), rtl_(false)
+         right_boundary_(false), flushed_(false), rtl_(false),
+         changebar_(false)
 {}
 
 
@@ -371,6 +372,8 @@ void Row::finalizeLast()
        if (elt.final)
                return;
        elt.final = true;
+       if (elt.change.changed())
+               changebar_ = true;
 
        if (elt.type == STRING) {
                dim_.wid -= elt.dim.wid;
index 498fd07d7f8f8ce5c08335171605061ed6269701..a2e77fbfb4b61b6336aa09c0c04eb4c9bb748059 100644 (file)
--- a/src/Row.h
+++ b/src/Row.h
@@ -266,6 +266,11 @@ public:
        void reverseRTL(bool rtl_par);
        ///
        bool isRTL() const { return rtl_; }
+       ///
+       bool needsChangeBar() const { return changebar_; }
+       ///
+       void needsChangeBar(bool ncb) { changebar_ = ncb; }
+
        /// Find row element that contains \c pos, and compute x offset.
        const_iterator const findElement(pos_type pos, bool boundary, double & x) const;
 
@@ -326,6 +331,8 @@ private:
        Dimension dim_;
        /// true when this row lives in a right-to-left paragraph
        bool rtl_;
+       /// true when a changebar should be drawn in the margin
+       bool changebar_;
 };
 
 
index c4b9034fb4299d9af764929524362a05226c2a28..38bcefadadecced50836681c69169c6979502475 100644 (file)
@@ -247,18 +247,6 @@ void RowPainter::paintChange(Row::Element const & e) const
 
 void RowPainter::paintChangeBar() const
 {
-       pos_type const start = row_.pos();
-       pos_type end = row_.endpos();
-
-       if (par_.size() == end) {
-               // this is the last row of the paragraph;
-               // thus, we must also consider the imaginary end-of-par character
-               end++;
-       }
-
-       if (start == end || !par_.isChanged(start, end))
-               return;
-
        int const height = tm_.isLastRow(row_)
                ? row_.ascent()
                : row_.height();
index 325b0b9c5a205ccc207eebe348d0e64941ce2577..cd33f7f190e44996f065f1c24aa751ce01c6581b 100644 (file)
@@ -964,6 +964,10 @@ bool TextMetrics::breakRow(Row & row, int const right_margin) const
                row.addVirtual(end, docstring(1, char_type(0x00B6)), f, Change());
        }
 
+       // Is there a end-of-paragaph change?
+       if (i == end && par.lookupChange(end).changed() && !need_new_row)
+               row.needsChangeBar(true);
+
        // if the row is too large, try to cut at last separator. In case
        // of success, reset indication that the row was broken abruptly.
        int const next_width = max_width_ - leftMargin(row.pit(), row.endpos())
@@ -1937,7 +1941,8 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type const pit, int const
                rp.paintSelection();
                rp.paintAppendix();
                rp.paintDepthBar();
-               rp.paintChangeBar();
+               if (row.needsChangeBar())
+                       rp.paintChangeBar();
                if (i == 0 && !row.isRTL())
                        rp.paintFirst();
                if (i == nrows - 1 && row.isRTL())