commit 8f86ee74cddc6d3d9f8eea4d98ad4d4bab842411
Author: Enrico Forestieri <[email protected]>
Date:   Tue Sep 13 07:53:48 2016 +0200

    Make sure that math macros are updated at export time.
    
    The math macros system is quite complex. Macros are updated during
    metrics calculation, so a missing update is very likely to cause a
    crash. This commit tries to assure that they are updated at export
    time, which also happens when the table of contents is updated.
    Moreover, in order to circumvent a possible missing update, when
    a math macro is detected we try to avoid using the sym_ member
    of the MacroData class, as it may contain bogus values.
---
 src/BufferView.cpp       |    8 ++++++--
 src/mathed/MathMacro.cpp |    8 +++++---
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/BufferView.cpp b/src/BufferView.cpp
index 0212b16..dd18b25 100644
--- a/src/BufferView.cpp
+++ b/src/BufferView.cpp
@@ -495,7 +495,9 @@ void BufferView::processUpdateFlags(Update::flags flags)
 
        // updateMetrics() does not update paragraph position
        // This is done at draw() time. So we need a redraw!
-       buffer_.changed(false);
+       // We pass true so that metrics are computed for the sake
+       // of having MacroData updated.
+       buffer_.changed(true);
 
        if (needsFitCursor()) {
                // The cursor is off screen so ensure it is visible.
@@ -2181,7 +2183,9 @@ void BufferView::updateHoveredInset() const
 
                // This event (moving without mouse click) is not passed 
further.
                // This should be changed if it is further utilized.
-               buffer_.changed(false);
+               // We pass true so that metrics are computed for the sake
+               // of having MacroData updated.
+               buffer_.changed(true);
        }
 }
 
diff --git a/src/mathed/MathMacro.cpp b/src/mathed/MathMacro.cpp
index 4529cf9..cb853a3 100644
--- a/src/mathed/MathMacro.cpp
+++ b/src/mathed/MathMacro.cpp
@@ -614,7 +614,8 @@ void MathMacro::draw(PainterInfo & pi, int x, int y) const
                drawMarkers2(pi, expx, expy);
        } else {
                bool drawBox = lyxrc.macro_edit_style == 
LyXRC::MACRO_EDIT_INLINE_BOX;
-               bool upshape = d->macro_ && d->macro_->symbol()
+               bool user_macro = mathedWordList().find(name()) == 
mathedWordList().end();
+               bool upshape = user_macro ? false : d->macro_ && 
d->macro_->symbol()
                                && d->macro_->symbol()->extra == "textmode";
                Changer dummy = pi.base.font.changeShape(upshape ? UP_SHAPE
                                                        : pi.base.font.shape());
@@ -929,9 +930,10 @@ bool MathMacro::folded() const
 
 void MathMacro::write(WriteStream & os) const
 {
-       bool const textmode_macro = d->macro_ && d->macro_->symbol()
+       bool user_macro = mathedWordList().find(name()) == 
mathedWordList().end();
+       bool textmode_macro = user_macro ? false : d->macro_ && 
d->macro_->symbol()
                                && d->macro_->symbol()->extra == "textmode";
-       bool const needs_mathmode = d->macro_ && (!d->macro_->symbol()
+       bool needs_mathmode = user_macro ? bool(d->macro_) : d->macro_ && 
(!d->macro_->symbol()
                                || d->macro_->symbol()->extra != "textmode");
 
        MathEnsurer ensurer(os, needs_mathmode, true, textmode_macro);

Reply via email to