]> git.lyx.org Git - features.git/commitdiff
Fix crash when copying a macro with instant preview on
authorEnrico Forestieri <forenr@lyx.org>
Wed, 24 Jun 2015 21:38:53 +0000 (23:38 +0200)
committerEnrico Forestieri <forenr@lyx.org>
Wed, 24 Jun 2015 21:38:53 +0000 (23:38 +0200)
The MacroData pointer is updated by MathData::metrics() which is not
called when selecting a math inset with instant preview for math on.
Thus, we have to update it in the copy constructor otherwise a crash
is almost assured when hitting Ctrl+C.

src/mathed/MacroTable.h
src/mathed/MathMacro.cpp

index 3bd04ea917a54ccef6469b28e4c8271293ebf825..030e6f74caf43e90620d81e06bf8817a7388bfd4 100644 (file)
@@ -69,6 +69,8 @@ public:
        char const * MathMLtype() const;
        ///
        void setSymbol(latexkeys const * sym) { sym_ = sym; }
+       ///
+       DocIterator const & pos() { return pos_; }
 
        /// lock while being drawn to avoid recursions
        int lock() const { return ++lockCount_; }
index 24ebe776452ab574b0382417b3f6a0ec189d7569..8f2d15fefc79d59f81b82371eece5e3c6b34257e 100644 (file)
@@ -203,6 +203,14 @@ MathMacro::MathMacro(MathMacro const & that)
        : InsetMathNest(that), d(new Private(*that.d))
 {
        d->updateChildren(this);
+       if (d->macro_ && lyxrc.preview == LyXRC::PREVIEW_ON) {
+               // We need to update d->macro_ by ourselves because in this case
+               // MathData::metrics() is not called when selecting a math inset
+               DocIterator const & pos = d->macroBackup_.pos();
+               d->macro_ = pos.buffer()->getMacro(name(), pos);
+               if (!d->macro_)
+                       d->macro_ = &d->macroBackup_;
+       }
 }
 
 
@@ -213,6 +221,14 @@ MathMacro & MathMacro::operator=(MathMacro const & that)
        InsetMathNest::operator=(that);
        *d = *that.d;
        d->updateChildren(this);
+       if (d->macro_ && lyxrc.preview == LyXRC::PREVIEW_ON) {
+               // We need to update d->macro_ by ourselves because in this case
+               // MathData::metrics() is not called when selecting a math inset
+               DocIterator const & pos = d->macroBackup_.pos();
+               d->macro_ = pos.buffer()->getMacro(name(), pos);
+               if (!d->macro_)
+                       d->macro_ = &d->macroBackup_;
+       }
        return *this;
 }