commit cb4d5a48606028c09dce24229f1b19220aa47898
Author: Jean-Marc Lasgouttes <[email protected]>
Date:   Fri Nov 6 17:20:55 2026 +0100

    Fix handling of change bars
    
    The code was in an incoherent state after the introduction of the
    TextMetrics::tokenizeParagraph() method that creates a so-called big row.
    
    Add new Row::checkChangeBar() method that sets the Row::needsChangeBar()
    value for the change bar when required.
    
    Remove code that explicitly set the change bar when there was an
    end-of-paragraph change, since this is handled by the fact that a
    changed pilcrow sign is added to the row.
    
    Simplify accordingly Row::finalizeLast().
    
    Fixes bug #13003.
---
 src/Row.cpp         | 22 ++++++++++++++--------
 src/Row.h           |  4 ++--
 src/TextMetrics.cpp |  7 ++-----
 3 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/src/Row.cpp b/src/Row.cpp
index 550071db24..dd8aa64fb8 100644
--- a/src/Row.cpp
+++ b/src/Row.cpp
@@ -508,17 +508,24 @@ bool Row::sameString(Font const & f, bool rtl, Change 
const & ch) const
 }
 
 
-// FIXME: remove this and move the changebar update to Row::push_back()
+// FIXME: remove this when strings are added by batch
 void Row::finalizeLast()
 {
        if (elements_.empty())
                return;
-       Element & elt = elements_.back();
-       if (elt.final)
-               return;
-       elt.final = true;
-       if (elt.change.changed())
-               changebar_ = true;
+       elements_.back().final = true;
+}
+
+
+void Row::checkChangeBar()
+{
+       changebar_ = false;
+       for (auto const & elt : elements_)
+               if (elt.change.changed()
+                    || (elt.type == INSET && elt.inset->isChanged())) {
+                       changebar_ = true;
+                       break;
+               }
 }
 
 
@@ -530,7 +537,6 @@ void Row::addInset(pos_type const pos, Inset const * ins,
        e.inset = ins;
        e.row_flags = ins->rowFlags();
        elements_.push_back(e);
-       changebar_ |= ins->isChanged();
 }
 
 
diff --git a/src/Row.h b/src/Row.h
index fea8503f3d..a64eefe235 100644
--- a/src/Row.h
+++ b/src/Row.h
@@ -260,8 +260,8 @@ public:
        void setRTL(bool rtl) { rtl_ = rtl; }
        ///
        bool needsChangeBar() const { return changebar_; }
-       ///
-       void needsChangeBar(bool ncb) { changebar_ = ncb; }
+       /// Inspect the contents of the row and set a changebar if needed
+       void checkChangeBar();
 
        /// The offset of the left-most cursor position on the row
        int left_x() const;
diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp
index 8f1d8224f1..76ba0ea346 100644
--- a/src/TextMetrics.cpp
+++ b/src/TextMetrics.cpp
@@ -974,8 +974,6 @@ Row TextMetrics::tokenizeParagraph(pit_type const pit) const
        // same as in redoParagraph, remember keep them in sync.
        ParagraphList const & pars = text_->paragraphs();
        Change const & endchange = par.lookupChange(end);
-       if (endchange.changed())
-               row.needsChangeBar(true);
        if ((lyxrc.paragraph_markers || endchange.changed())
            && size_type(pit + 1) < pars.size()) {
                // add a virtual element for the end-of-paragraph
@@ -1273,16 +1271,15 @@ Rows TextMetrics::breakParagraph(Row const & bigrow) 
const
                // Last row in paragraph is flushed
                rows.back().flushed(true);
                cleanupRow(rows.back(), true);
-               // Is there an end-of-paragraph change?
-               if (bigrow.needsChangeBar())
-                       rows.back().needsChangeBar(true);
        }
 
        // Set start_boundary to be equal to the previous row's end boundary
+       // Set change bar on rows that need it
        bool sb = false;
        for (auto & row : rows) {
                row.start_boundary(sb);
                sb = row.end_boundary();
+               row.checkChangeBar();
        }
 
        return rows;
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to