commit 2e8c9cfc832d876ff66e47ae7aadc30fe9328e9d
Author: Jean-Marc Lasgouttes <lasgout...@lyx.org>
Date:   Mon Jul 13 23:29:15 2020 +0200

    Fix paragraph position in TextMetrics::singleParUpdate()
    
    When running redoParagraph, it may happen that the ascent of the first
    row changes. Since the ParagraphMetrics position is actually the
    baseline of its first row, it may be necessary to update it.
    
    Fixes bug #11601.
---
 src/BufferView.cpp |   11 ++++++++---
 src/update_flags.h |    1 -
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/BufferView.cpp b/src/BufferView.cpp
index 769d1a9..24d811c 100644
--- a/src/BufferView.cpp
+++ b/src/BufferView.cpp
@@ -2777,7 +2777,7 @@ bool BufferView::singleParUpdate()
        Text & buftext = buffer_.text();
        pit_type const bottom_pit = d->cursor_.bottom().pit();
        TextMetrics & tm = textMetrics(&buftext);
-       int old_height = tm.parMetrics(bottom_pit).height();
+       Dimension const old_dim = tm.parMetrics(bottom_pit).dim();
 
        // make sure inline completion pointer is ok
        if (d->inlineCompletionPos_.fixIfBroken())
@@ -2788,11 +2788,16 @@ bool BufferView::singleParUpdate()
        // (if this paragraph contains insets etc., rebreaking will
        // recursively descend)
        tm.redoParagraph(bottom_pit);
-       ParagraphMetrics const & pm = tm.parMetrics(bottom_pit);
-       if (pm.height() != old_height)
+       ParagraphMetrics & pm = tm.par_metrics_[bottom_pit];
+       if (pm.height() != old_dim.height()) {
                // Paragraph height has changed so we cannot proceed to
                // the singlePar optimisation.
                return false;
+       }
+       // Since position() points to the baseline of the first row, we
+       // may have to update it. See ticket #11601 for an example where
+       // the height does not change but the ascent does.
+       pm.setPosition(pm.position() - old_dim.ascent() + pm.ascent());
 
        tm.updatePosCache(bottom_pit);
 
diff --git a/src/update_flags.h b/src/update_flags.h
index a40e88c..af71c0e 100644
--- a/src/update_flags.h
+++ b/src/update_flags.h
@@ -26,7 +26,6 @@ namespace Update {
                /// Force a full redraw (but no metrics computations)
                ForceDraw = 4,
                /// Try to rebreak only the current paragraph metrics.
-               /// (currently ignored!)
                SinglePar = 8,
                /// Only the inset decorations need to be redrawn, no text 
metrics
                /// update is needed.
-- 
lyx-cvs mailing list
lyx-cvs@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to