diff --git a/src/mathed/InsetMathMacroTemplate.cpp b/src/mathed/InsetMathMacroTemplate.cpp index 2a721833b0..cf830fbf3b 100644 --- a/src/mathed/InsetMathMacroTemplate.cpp +++ b/src/mathed/InsetMathMacroTemplate.cpp @@ -394,7 +394,7 @@ void InsetNameWrapper::draw(PainterInfo & pi, int x, int y) const InsetMathMacroTemplate::InsetMathMacroTemplate(Buffer * buf) - : InsetMathNest(buf, 3), numargs_(0), argsInLook_(0), optionals_(0), + : InsetMathNest(buf, 3), look_(buf), numargs_(0), argsInLook_(0), optionals_(0), type_(MacroTypeNewcommand), redefinition_(false), lookOutdated_(true), premetrics_(false), labelBoxAscent_(0), labelBoxDescent_(0) { @@ -405,8 +405,8 @@ InsetMathMacroTemplate::InsetMathMacroTemplate(Buffer * buf) InsetMathMacroTemplate::InsetMathMacroTemplate(Buffer * buf, docstring const & name, int numargs, int optionals, MacroType type, vector const & optionalValues, MathData const & def, MathData const & display) - : InsetMathNest(buf, optionals + 3), numargs_(numargs), argsInLook_(numargs), - optionals_(optionals), optionalValues_(optionalValues), + : InsetMathNest(buf, optionals + 3), look_(buf), numargs_(numargs), + argsInLook_(numargs), optionals_(optionals), optionalValues_(optionalValues), type_(type), redefinition_(false), lookOutdated_(true), premetrics_(false), labelBoxAscent_(0), labelBoxDescent_(0) { @@ -536,6 +536,8 @@ void InsetMathMacroTemplate::createLook(int args) const look_.push_back(MathAtom( new InsetDisplayLabelBox(buffer_, MathAtom( new InsetMathWrapper(&cell(displayIdx()))), _("LyX"), *this))); + + look_.setContentsBuffer(); } diff --git a/src/mathed/MathData.cpp b/src/mathed/MathData.cpp index 24b4d86fb9..4c33934828 100644 --- a/src/mathed/MathData.cpp +++ b/src/mathed/MathData.cpp @@ -52,11 +52,18 @@ MathData::MathData(Buffer * buf, const_iterator from, const_iterator to) {} +void MathData::setContentsBuffer() +{ + if (buffer_) + for (MathAtom & at : *this) + at.nucleus()->setBuffer(*buffer_); +} + + void MathData::setBuffer(Buffer & b) { buffer_ = &b; - for (MathAtom & at : *this) - at.nucleus()->setBuffer(b); + setContentsBuffer(); } @@ -78,6 +85,8 @@ void MathData::insert(size_type pos, MathAtom const & t) { LBUFERR(pos <= size()); base_type::insert(begin() + pos, t); + if (buffer_) + operator[](pos)->setBuffer(*buffer_); } @@ -85,6 +94,17 @@ void MathData::insert(size_type pos, MathData const & ar) { LBUFERR(pos <= size()); base_type::insert(begin() + pos, ar.begin(), ar.end()); + if (buffer_) + for (size_type i = 0 ; i < ar.size() ; ++i) + operator[](pos + i)->setBuffer(*buffer_); +} + + +void MathData::push_back(MathAtom const & t) +{ + base_type::push_back(t); + if (buffer_) + back()->setBuffer(*buffer_); } diff --git a/src/mathed/MathData.h b/src/mathed/MathData.h index 865742df4c..c2d731efcb 100644 --- a/src/mathed/MathData.h +++ b/src/mathed/MathData.h @@ -59,7 +59,6 @@ public: using base_type::clear; using base_type::begin; using base_type::end; - using base_type::push_back; using base_type::pop_back; using base_type::back; using base_type::front; @@ -85,6 +84,8 @@ public: void insert(size_type pos, MathAtom const & at); /// inserts multiple atoms at position pos void insert(size_type pos, MathData const & ar); + /// inserts single atom at end + void push_back(MathAtom const & at); /// erase range from pos1 to pos2 void erase(iterator pos1, iterator pos2); @@ -187,8 +188,10 @@ public: void updateMacros(Cursor * cur, MacroContext const & mc, UpdateType, int nesting); /// void updateBuffer(ParIterator const &, UpdateType, bool const deleted = false); - /// + /// Change associated buffer for this object and its contents void setBuffer(Buffer & b); + /// Update assiociated buffer for the contents of the object + void setContentsBuffer(); protected: /// cached values for super/subscript placement diff --git a/src/mathed/MathSupport.cpp b/src/mathed/MathSupport.cpp index 585320f11a..6987decea8 100644 --- a/src/mathed/MathSupport.cpp +++ b/src/mathed/MathSupport.cpp @@ -1102,6 +1102,9 @@ void asArray(docstring const & str, MathData & ar, Parse::flags pf) bool macro = pf & Parse::MACRODEF; if ((str.size() == 1 && quiet) || (!mathed_parse_cell(ar, str, pf) && quiet && !macro)) mathed_parse_cell(ar, str, pf | Parse::VERBATIM); + + // set the buffer of the MathData contents + ar.setContentsBuffer(); }