]> git.lyx.org Git - features.git/commitdiff
Fix bug #4360: Instant preview does not render formulas which contain math-macro...
authorVincent van Ravesteijn <vfr@lyx.org>
Sun, 22 Nov 2009 20:50:35 +0000 (20:50 +0000)
committerVincent van Ravesteijn <vfr@lyx.org>
Sun, 22 Nov 2009 20:50:35 +0000 (20:50 +0000)
Patch from Stefan.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@32157 a592a061-630c-0410-9148-cb99ea01b6c8

15 files changed:
src/graphics/PreviewLoader.cpp
src/graphics/Previews.cpp
src/insets/Inset.h
src/insets/InsetExternal.cpp
src/insets/InsetExternal.h
src/insets/InsetInclude.cpp
src/insets/InsetInclude.h
src/insets/InsetTabular.cpp
src/insets/InsetTabular.h
src/insets/InsetText.cpp
src/insets/InsetText.h
src/mathed/InsetMathHull.cpp
src/mathed/InsetMathHull.h
src/mathed/MathMacroTemplate.cpp
src/mathed/MathMacroTemplate.h

index 82893ed11c54508cf9dc08957f0f4775bbe6acdf..453f36c91ac235ca8e8b62bbf432655d8c646709 100644 (file)
@@ -701,15 +701,6 @@ void PreviewLoader::Impl::dumpPreamble(odocstream & os) const
           << "\\def\\lyxlock{}\n"
           << "\n";
 
-       // Loop over the insets in the buffer and dump all the math-macros.
-       Inset & inset = buffer_.inset();
-       InsetIterator it = inset_iterator_begin(inset);
-       InsetIterator const end = inset_iterator_end(inset);
-
-       for (; it != end; ++it)
-               if (it->lyxCode() == MATHMACRO_CODE)
-                       it->latex(os, runparams);
-
        // All equation labels appear as "(#)" + preview.sty's rendering of
        // the label name
        if (lyxrc.preview_hashed_labels)
index b31292fc30132767244d2c6d3f82160a2c1b1832..7c50618a9a6fe99a313384d82b2740e66517cc21 100644 (file)
@@ -72,7 +72,7 @@ void Previews::generateBufferPreviews(Buffer const & buffer) const
        InsetIterator const end = inset_iterator_end(inset);
 
        for (; it != end; ++it)
-               it->addPreview(ploader);
+               it->addPreview(it, ploader);
 
        ploader.startLoading();
 }
index bb269f90e06d7d66287f6b5b89bb70e27effdafe..da160e447c8d6d045fa68a021a20bc2b714dbe26 100644 (file)
@@ -449,7 +449,8 @@ public:
         *  Most insets have no interest in this capability, so the method
         *  defaults to empty.
         */
-       virtual void addPreview(graphics::PreviewLoader &) const {}
+       virtual void addPreview(DocIterator const & insetPos,
+               graphics::PreviewLoader &) const {}
 
        /** Classifies the unicode characters appearing in a math inset
         *  depending on whether they are to be translated as latex
index d86a78d313ddcccb218cf22aa5c008d9021bbce9..058b4be3218c6071e1b16b53ba3aa16ab6af75b1 100644 (file)
@@ -757,7 +757,8 @@ void InsetExternal::validate(LaTeXFeatures & features) const
 }
 
 
-void InsetExternal::addPreview(graphics::PreviewLoader & ploader) const
+void InsetExternal::addPreview(DocIterator const & /*inset_pos*/,
+       graphics::PreviewLoader & ploader) const        
 {
        RenderMonitoredPreview * const ptr = renderer_->asMonitoredPreview();
        if (!ptr)
index a04f64cb66ae5e16e0412a190aa90489485effce..22c909b0e27b1d62afd176c3447124794c62ad5e 100644 (file)
@@ -139,7 +139,7 @@ private:
        /// Update needed features for this inset.
        void validate(LaTeXFeatures & features) const;
        ///
-       void addPreview(graphics::PreviewLoader &) const;
+       void addPreview(DocIterator const &, graphics::PreviewLoader &) const;
        ///
        bool showInsetDialog(BufferView * bv) const;
        ///
index 2c2b230ba69df2a25fff4cd16b93fdef96530cf3..efc80a21ac1e871b49975a3f1f87485edbebfd7b 100644 (file)
@@ -949,7 +949,8 @@ void add_preview(RenderMonitoredPreview & renderer, InsetInclude const & inset,
 } // namespace anon
 
 
-void InsetInclude::addPreview(graphics::PreviewLoader & ploader) const
+void InsetInclude::addPreview(DocIterator const & /*inset_pos*/,
+       graphics::PreviewLoader & ploader) const
 {
        Buffer const & buffer = ploader.buffer();
        if (!preview_wanted(params(), buffer))
index 11e5ac2389cb642e27a8ad12b65f6f61d47cf7d8..208c79ee6afb83859db6b23491651799d655570b 100644 (file)
@@ -84,7 +84,7 @@ public:
        ///
        void validate(LaTeXFeatures &) const;
        ///
-       void addPreview(graphics::PreviewLoader &) const;
+       void addPreview(DocIterator const &, graphics::PreviewLoader &) const;
        ///
        void addToToc(DocIterator const &);
        ///
index 9b0abc9690dd2f0ca0941f64170925bdfcdb47e2..e149c1d810aa13e05074bdf0c238ed8c2542aab2 100644 (file)
@@ -5289,13 +5289,19 @@ bool InsetTabular::insertPlaintextString(BufferView & bv, docstring const & buf,
 }
 
 
-void InsetTabular::addPreview(PreviewLoader & loader) const
+void InsetTabular::addPreview(DocIterator const & inset_pos,
+       PreviewLoader & loader) const
 {
        row_type const rows = tabular.row_info.size();
        col_type const columns = tabular.column_info.size();
+       DocIterator cell_pos = inset_pos;
+
+       cell_pos.push_back(CursorSlice(*const_cast<InsetTabular *>(this)));
        for (row_type i = 0; i < rows; ++i) {
-               for (col_type j = 0; j < columns; ++j)
-                       tabular.cellInset(i, j)->addPreview(loader);
+               for (col_type j = 0; j < columns; ++j) {
+                       cell_pos.top().idx() = index(i, j);
+                       tabular.cellInset(i, j)->addPreview(cell_pos, loader);
+               }
        }
 }
 
index c8a9b3940ef5329ac45244dfd64fb69d9bd1bdb6..902a1e1f7088b33b3e571dd937bd129b0e69bce2 100644 (file)
@@ -813,7 +813,8 @@ public:
        ///
        virtual bool forcePlainLayout(idx_type cell = 0) const;
        ///
-       void addPreview(graphics::PreviewLoader &) const;
+       void addPreview(DocIterator const & inset_pos,
+               graphics::PreviewLoader &) const;
 
        /// lock cell with given index
        void edit(Cursor & cur, bool front, EntryDirection entry_from);
index 7da34f699d7ff1dae738f7fbe462a021118c902e..1d57c843a919a33e29216c14f41681f61848aa78 100644 (file)
@@ -641,16 +641,24 @@ void InsetText::appendParagraphs(ParagraphList & plist)
 }
 
 
-void InsetText::addPreview(PreviewLoader & loader) const
+void InsetText::addPreview(DocIterator const & text_inset_pos,
+       PreviewLoader & loader) const
 {
        ParagraphList::const_iterator pit = paragraphs().begin();
        ParagraphList::const_iterator pend = paragraphs().end();
+       int pidx = 0;
 
-       for (; pit != pend; ++pit) {
+       DocIterator inset_pos = text_inset_pos;
+       inset_pos.push_back(CursorSlice(*const_cast<InsetText *>(this)));
+
+       for (; pit != pend; ++pit, ++pidx) {
                InsetList::const_iterator it  = pit->insetList().begin();
                InsetList::const_iterator end = pit->insetList().end();
-               for (; it != end; ++it)
-                       it->inset->addPreview(loader);
+               inset_pos.pit() = pidx;
+               for (; it != end; ++it) {
+                       inset_pos.pos() = it->pos;
+                       it->inset->addPreview(inset_pos, loader);
+               }
        }
 }
 
index bf72bcf1f78cbbe40f194c50f4036d1e5d6649f8..fb1fb0a6ba9e7a1d91abe9dacee8c885bb4bdbad 100644 (file)
@@ -137,7 +137,7 @@ public:
        void appendParagraphs(ParagraphList &);
 
        ///
-       void addPreview(graphics::PreviewLoader &) const;
+       void addPreview(DocIterator const &, graphics::PreviewLoader &) const;
 
        ///
        void edit(Cursor & cur, bool front, EntryDirection entry_from);
index 0142885559e6307eb89d0916af5e3a033ebe7fdb..f54e1a7dfb2603a5b2c70bd69d3a2cb17d4d67d3 100644 (file)
@@ -28,6 +28,7 @@
 #include "FuncStatus.h"
 #include "LaTeXFeatures.h"
 #include "LyXRC.h"
+#include "MacroTable.h"
 #include "sgml.h"
 #include "TextPainter.h"
 #include "TocBackend.h"
@@ -456,22 +457,44 @@ void InsetMathHull::initUnicodeMath() const
 }
 
 
-void InsetMathHull::addPreview(graphics::PreviewLoader & ploader) const
+void InsetMathHull::addPreview(DocIterator const & insetPos,
+       graphics::PreviewLoader & /*ploader*/) const
 {
        if (RenderPreview::status() == LyXRC::PREVIEW_ON) {
-               docstring const snippet = latexString(*this);
-               preview_->addPreview(snippet, ploader);
+               reloadPreview(insetPos);
        }
 }
 
 
-bool InsetMathHull::notifyCursorLeaves(Cursor const & /*old*/, Cursor & cur)
+void InsetMathHull::reloadPreview(DocIterator const & pos) const  
+{  
+       Buffer const * buffer = pos.buffer();  
+
+       // collect macros at this position  
+       MacroNameSet macros;  
+       buffer->listMacroNames(macros);  
+       MacroNameSet::iterator it = macros.begin();  
+       MacroNameSet::iterator end = macros.end();  
+       odocstringstream macro_preamble;  
+       for (; it != end; ++it) {  
+               MacroData const * data = buffer->getMacro(*it, pos, true);  
+               if (data) {  
+                       data->write(macro_preamble, true);  
+                       macro_preamble << endl;  
+               }
+       }  
+
+       // start preview  
+       docstring const snippet = macro_preamble.str() + latexString(*this);  
+       LYXERR(Debug::MACROS, "Preview snippet: " << snippet);  
+       preview_->addPreview(snippet, *buffer);  
+       preview_->startLoading(*buffer);  
+}  
+
+bool InsetMathHull::notifyCursorLeaves(Cursor const & old, Cursor & cur)
 {
        if (RenderPreview::status() == LyXRC::PREVIEW_ON) {
-               Buffer const * buffer = cur.buffer();
-               docstring const snippet = latexString(*this);
-               preview_->addPreview(snippet, *buffer);
-               preview_->startLoading(*buffer);
+               reloadPreview(old);
                cur.updateFlags(Update::Force);
        }
        return false;
index db4ea41770013ef8bccdead9057d36f83463c563..001b2e3ee479a78771a1a18970247cc3d68218cf 100644 (file)
@@ -132,7 +132,10 @@ public:
        ///
        //bool insetAllowed(InsetCode code) const;
        ///
-       void addPreview(graphics::PreviewLoader &) const;
+       void addPreview(DocIterator const & insetPos,
+               graphics::PreviewLoader &) const;
+       /// Recreate the preview if preview is enabled.
+       void reloadPreview(DocIterator const & pos) const;
        ///
        void initUnicodeMath() const;
 
index 8e809e3b2143f93adc68cf4ca027980362ec6640..2d74457040e46ef01a314252f614402144a80585 100644 (file)
@@ -17,6 +17,7 @@
 #include "LaTeXFeatures.h"
 #include "InsetMathBrace.h"
 #include "InsetMathChar.h"
+#include "InsetMathHull.h"
 #include "InsetMathSqrt.h"
 #include "MathMacro.h"
 #include "MathMacroArgument.h"
 #include "FuncRequest.h"
 #include "FuncStatus.h"
 #include "Lexer.h"
+#include "LyXRC.h" 
 #include "Undo.h"
 
 #include "frontends/Painter.h"
 
+#include "insets/RenderPreview.h"
+
 #include "support/lassert.h"
 #include "support/convert.h"
 #include "support/debug.h"
@@ -619,20 +623,15 @@ void MathMacroTemplate::edit(Cursor & cur, bool front, EntryDirection entry_from
 
 bool MathMacroTemplate::notifyCursorLeaves(Cursor const & old, Cursor & cur)
 {
-       // find this in cursor old
-       Cursor insetCur = old;
-       int scriptSlice = insetCur.find(this);
-       LASSERT(scriptSlice != -1, /**/);
-       insetCur.cutOff(scriptSlice);
-       
-       commitEditChanges(insetCur);
+       commitEditChanges(cur, old);
        updateLook();
        cur.updateFlags(Update::Force);
        return InsetMathNest::notifyCursorLeaves(old, cur);
 }
 
 
-void MathMacroTemplate::removeArguments(Cursor & cur, int from, int to)
+void MathMacroTemplate::removeArguments(Cursor & cur,
+       DocIterator const & /*insetPos*/, int from, int to)
 {
        for (DocIterator it = doc_iterator_begin(&buffer(), this); it; it.forwardChar()) {
                if (!it.nextInset())
@@ -716,68 +715,98 @@ void MathMacroTemplate::insertMissingArguments(int maxArg)
 }
 
 
-void MathMacroTemplate::changeArity(Cursor & cur, int newNumArg)
+void MathMacroTemplate::changeArity(Cursor & cur,
+       DocIterator const & insetPos, int newNumArg)
 {
        // remove parameter which do not appear anymore in the definition
        for (int i = numargs_; i > newNumArg; --i)
-               removeParameter(cur, numargs_ - 1, false);
+               removeParameter(cur, insetPos, numargs_ - 1, false);
        
        // add missing parameter
        for (int i = numargs_; i < newNumArg; ++i)
-               insertParameter(cur, numargs_, false, false);
+               insertParameter(cur, insetPos, numargs_, false, false);
 }
 
 
-void MathMacroTemplate::commitEditChanges(Cursor & cur)
+///
+class AddRemoveMacroInstanceFix
 {
-       int argsInDef = maxArgumentInDefinition();
-       if (argsInDef != numargs_) {
-               cur.recordUndoFullDocument();
-               changeArity(cur, argsInDef);
+public:
+       ///
+       AddRemoveMacroInstanceFix(int n, bool insert) : n_(n), insert_(insert) {}
+       ///
+       void operator()(MathMacro * macro) {
+               if (macro->folded()) {
+                       if (insert_)
+                               macro->insertArgument(n_);
+                       else
+                               macro->removeArgument(n_);
+               }
        }
-       insertMissingArguments(argsInDef);
-}
 
+private:
+       ///
+       int n_;
+       ///
+       bool insert_;
+};
 
-// FIXME: factorize those functions here with a functional style, maybe using Boost's function
-// objects?
 
-void fixMacroInstancesAddRemove(Cursor const & from, docstring const & name, int n, bool insert) {
-       Cursor dit = from;
+///
+class OptionalsMacroInstanceFix
+{
+public:
+       ///
+       OptionalsMacroInstanceFix(int optionals) : optionals_(optionals) {}
+       ///
+       void operator()(MathMacro * macro) {
+               macro->setOptionals(optionals_);
+       }
 
-       for (; dit; dit.forwardPos()) {
-               // only until a macro is redefined
-               if (dit.inset().lyxCode() == MATHMACRO_CODE) {
-                       MathMacroTemplate const & macroTemplate
-                       = static_cast<MathMacroTemplate const &>(dit.inset());
-                       if (macroTemplate.name() == name)
-                               break;
-               }
+private:
+       ///
+       int optionals_;
+};
 
-               // in front of macro instance?
-               Inset * inset = dit.nextInset();
-               if (!inset)
-                       continue;
-               InsetMath * insetMath = inset->asInsetMath();
-               if (!insetMath)
-                       continue;
 
-               MathMacro * macro = insetMath->asMacro();
-               if (macro && macro->name() == name && macro->folded()) {
-                       // found macro instance
-                       if (insert)
-                               macro->insertArgument(n);
-                       else
-                               macro->removeArgument(n);
-               }
-       }
-}
+///
+class NullMacroInstanceFix
+{
+public:
+       ///
+       void operator()(MathMacro * macro) {}
+};
 
 
-void fixMacroInstancesOptional(Cursor const & from, docstring const & name, int optionals) {
-       Cursor dit = from;
+template<class F>
+void fixMacroInstances(Cursor & cur, DocIterator const & inset_pos,
+       docstring const & name, F & fix)
+{
+       // goto position behind macro template
+       DocIterator dit = inset_pos;
+       dit.pop_back();
+       dit.top().forwardPos();
 
+       // remember hull to trigger preview reload
+       DocIterator hull(dit.buffer());
+       bool preview_reload_needed = false;
+
+       // iterate over all positions until macro is redefined
        for (; dit; dit.forwardPos()) {
+               // left the outer hull?
+               if (!hull.empty() && dit.depth() == hull.depth()) {
+                       // reload the preview if necessary 
+                       if (preview_reload_needed) {
+                               InsetMathHull * inset_hull =
+                                       hull.nextInset()->asInsetMath()->asHullInset();
+                               LASSERT(inset_hull, /**/);
+                               inset_hull->reloadPreview(hull);
+                               cur.updateFlags(Update::Force);
+                               preview_reload_needed = false;
+                       }
+                       hull.clear();
+               }
+
                // only until a macro is redefined
                if (dit.inset().lyxCode() == MATHMACRO_CODE) {
                        MathMacroTemplate const & macroTemplate
@@ -793,44 +822,42 @@ void fixMacroInstancesOptional(Cursor const & from, docstring const & name, int
                InsetMath * insetMath = inset->asInsetMath();
                if (!insetMath)
                        continue;
+
+               // in front of outer hull?
+               InsetMathHull * inset_hull = insetMath->asHullInset();
+               if (inset_hull && hull.empty()) {
+                       // remember this for later preview reload
+                       hull = dit;
+               }
+
                MathMacro * macro = insetMath->asMacro();
                if (macro && macro->name() == name && macro->folded()) {
-                       // found macro instance
-                       macro->setOptionals(optionals);
+                       fix(macro);
+                       if (RenderPreview::status() == LyXRC::PREVIEW_ON)
+                               preview_reload_needed = true;
                }
        }
 }
 
 
-template<class F>
-void fixMacroInstancesFunctional(Cursor const & from,
-       docstring const & name, F & fix) {
-       Cursor dit = from;
-
-       for (; dit; dit.forwardPos()) {
-               // only until a macro is redefined
-               if (dit.inset().lyxCode() == MATHMACRO_CODE) {
-                       MathMacroTemplate const & macroTemplate
-                       = static_cast<MathMacroTemplate const &>(dit.inset());
-                       if (macroTemplate.name() == name)
-                               break;
-               }
-
-               // in front of macro instance?
-               Inset * inset = dit.nextInset();
-               if (!inset)
-                       continue;
-               InsetMath * insetMath = inset->asInsetMath();
-               if (!insetMath)
-                       continue;
-               MathMacro * macro = insetMath->asMacro();
-               if (macro && macro->name() == name && macro->folded())
-                       F(macro);
+void MathMacroTemplate::commitEditChanges(Cursor & cur,
+       DocIterator const & inset_pos)
+{
+       int args_in_def = maxArgumentInDefinition();
+       if (args_in_def != numargs_) {
+               cur.recordUndoFullDocument();
+               changeArity(cur, inset_pos, args_in_def);
        }
+       insertMissingArguments(args_in_def);
+
+       // make sure the preview are up to date
+       NullMacroInstanceFix fix;
+       fixMacroInstances(cur, inset_pos, name(), fix);
 }
 
 
-void MathMacroTemplate::insertParameter(Cursor & cur, int pos, bool greedy, bool addarg)
+void MathMacroTemplate::insertParameter(Cursor & cur,
+       DocIterator const & inset_pos, int pos, bool greedy, bool addarg)
 {
        if (pos <= numargs_ && pos >= optionals_ && numargs_ < 9) {
                ++numargs_;
@@ -845,13 +872,9 @@ void MathMacroTemplate::insertParameter(Cursor & cur, int pos, bool greedy, bool
                }
 
                if (!greedy) {
-                       Cursor dit = cur;
-                       dit.leaveInset(*this);
-                       // TODO: this was dit.forwardPosNoDescend before. Check that this is the same
-                       dit.top().forwardPos();
-
                        // fix macro instances
-                       fixMacroInstancesAddRemove(dit, name(), pos, true);
+                       AddRemoveMacroInstanceFix fix(pos, true);
+                       fixMacroInstances(cur, inset_pos, name(), fix);
                }
        }
 
@@ -859,11 +882,12 @@ void MathMacroTemplate::insertParameter(Cursor & cur, int pos, bool greedy, bool
 }
 
 
-void MathMacroTemplate::removeParameter(Cursor & cur, int pos, bool greedy)
+void MathMacroTemplate::removeParameter(Cursor & cur,
+       DocIterator const & inset_pos, int pos, bool greedy)
 {
        if (pos < numargs_ && pos >= 0) {
                --numargs_;
-               removeArguments(cur, pos, pos);
+               removeArguments(cur, inset_pos, pos, pos);
                shiftArguments(pos + 1, -1);
 
                // removed optional parameter?
@@ -886,13 +910,8 @@ void MathMacroTemplate::removeParameter(Cursor & cur, int pos, bool greedy)
 
                if (!greedy) {
                        // fix macro instances
-                       //boost::function<void(MathMacro *)> fix = _1->insertArgument(n);
-                       //fixMacroInstancesFunctional(dit, name(), fix);
-                       Cursor dit = cur;
-                       dit.leaveInset(*this);
-                       // TODO: this was dit.forwardPosNoDescend before. Check that this is the same
-                       dit.top().forwardPos();
-                       fixMacroInstancesAddRemove(dit, name(), pos, false);
+                       AddRemoveMacroInstanceFix fix(pos, false);
+                       fixMacroInstances(cur, inset_pos, name(), fix);
                }
        }
 
@@ -900,7 +919,9 @@ void MathMacroTemplate::removeParameter(Cursor & cur, int pos, bool greedy)
 }
 
 
-void MathMacroTemplate::makeOptional(Cursor & cur) {
+void MathMacroTemplate::makeOptional(Cursor & cur,
+       DocIterator const & inset_pos)
+{
        if (numargs_ > 0 && optionals_ < numargs_) {
                ++optionals_;
                cells_.insert(cells_.begin() + optIdx(optionals_ - 1), optionalValues_[optionals_ - 1]);
@@ -910,18 +931,17 @@ void MathMacroTemplate::makeOptional(Cursor & cur) {
                        ++cur[macroSlice].idx();
 
                // fix macro instances
-               Cursor dit = cur;
-               dit.leaveInset(*this);
-               // TODO: this was dit.forwardPosNoDescend before. Check that this is the same
-               dit.top().forwardPos();
-               fixMacroInstancesOptional(dit, name(), optionals_);
+               OptionalsMacroInstanceFix fix(optionals_);
+               fixMacroInstances(cur, inset_pos, name(), fix);
        }
 
        updateLook();
 }
 
 
-void MathMacroTemplate::makeNonOptional(Cursor & cur) {
+void MathMacroTemplate::makeNonOptional(Cursor & cur,
+       DocIterator const & inset_pos)
+{
        if (numargs_ > 0 && optionals_ > 0) {
                --optionals_;
 
@@ -942,11 +962,8 @@ void MathMacroTemplate::makeNonOptional(Cursor & cur) {
                }
 
                // fix macro instances
-               Cursor dit = cur;
-               dit.leaveInset(*this);
-               // TODO: this was dit.forwardPosNoDescend before. Check that this is the same
-               dit.top().forwardPos();
-               fixMacroInstancesOptional(dit, name(), optionals_);
+               OptionalsMacroInstanceFix fix(optionals_);
+               fixMacroInstances(cur, inset_pos, name(), fix);
        }
 
        updateLook();
@@ -960,77 +977,77 @@ void MathMacroTemplate::doDispatch(Cursor & cur, FuncRequest & cmd)
 
        case LFUN_MATH_MACRO_ADD_PARAM:
                if (numargs_ < 9) {
-                       commitEditChanges(cur);
+                       commitEditChanges(cur, cur);
                        cur.recordUndoFullDocument();
                        size_t pos = numargs_;
                        if (arg.size() != 0)
                                pos = (size_t)convert<int>(arg) - 1; // it is checked for >=0 in getStatus
-                       insertParameter(cur, pos);
+                       insertParameter(cur, cur, pos);
                }
                break;
 
 
        case LFUN_MATH_MACRO_REMOVE_PARAM:
                if (numargs_ > 0) {
-                       commitEditChanges(cur);
+                       commitEditChanges(cur, cur);
                        cur.recordUndoFullDocument();
                        size_t pos = numargs_ - 1;
                        if (arg.size() != 0)
                                pos = (size_t)convert<int>(arg) - 1; // it is checked for >=0 in getStatus
-                       removeParameter(cur, pos);
+                       removeParameter(cur, cur, pos);
                }
                break;
 
        case LFUN_MATH_MACRO_APPEND_GREEDY_PARAM:
                if (numargs_ < 9) {
-                       commitEditChanges(cur);
+                       commitEditChanges(cur, cur);
                        cur.recordUndoFullDocument();
-                       insertParameter(cur, numargs_, true);
+                       insertParameter(cur, cur, numargs_, true);
                }
                break;
 
        case LFUN_MATH_MACRO_REMOVE_GREEDY_PARAM:
                if (numargs_ > 0) {
-                       commitEditChanges(cur);
+                       commitEditChanges(cur, cur);
                        cur.recordUndoFullDocument();
-                       removeParameter(cur, numargs_ - 1, true);
+                       removeParameter(cur, cur, numargs_ - 1, true);
                }
                break;
 
        case LFUN_MATH_MACRO_MAKE_OPTIONAL:
-               commitEditChanges(cur);
+               commitEditChanges(cur, cur);
                cur.recordUndoFullDocument();
-               makeOptional(cur);
+               makeOptional(cur, cur);
                break;
 
        case LFUN_MATH_MACRO_MAKE_NONOPTIONAL:
-               commitEditChanges(cur);
+               commitEditChanges(cur, cur);
                cur.recordUndoFullDocument();
-               makeNonOptional(cur);
+               makeNonOptional(cur, cur);
                break;
 
        case LFUN_MATH_MACRO_ADD_OPTIONAL_PARAM:
                if (numargs_ < 9) {
-                       commitEditChanges(cur);
+                       commitEditChanges(cur, cur);
                        cur.recordUndoFullDocument();
-                       insertParameter(cur, optionals_);
-                       makeOptional(cur);
+                       insertParameter(cur, cur, optionals_);
+                       makeOptional(cur, cur);
                }
                break;
 
        case LFUN_MATH_MACRO_REMOVE_OPTIONAL_PARAM:
                if (optionals_ > 0) {
-                       commitEditChanges(cur);
+                       commitEditChanges(cur, cur);
                        cur.recordUndoFullDocument();
-                       removeParameter(cur, optionals_ - 1);
+                       removeParameter(cur, cur, optionals_ - 1);
                } break;
 
        case LFUN_MATH_MACRO_ADD_GREEDY_OPTIONAL_PARAM:
                if (numargs_ == optionals_) {
-                       commitEditChanges(cur);
+                       commitEditChanges(cur, cur);
                        cur.recordUndoFullDocument();
-                       insertParameter(cur, 0, true);
-                       makeOptional(cur);
+                       insertParameter(cur, cur, 0, true);
+                       makeOptional(cur, cur);
                }
                break;
 
index f6ac948d87e51330baf372c4d7c7c0b18063ed53..4a496e0857f967c9ea5fa8b2081e9abca2a2a22b 100644 (file)
@@ -115,17 +115,20 @@ private:
        virtual Inset * clone() const;
 
        /// remove #n with from<=n<=to
-       void removeArguments(Cursor & cur, int from, int to);
+       void removeArguments(Cursor & cur, DocIterator const & inset_pos,
+               int from, int to);
        /// shift every #n with from<=n, i.e. #n -> #(n-by)
        void shiftArguments(size_t from, int by);
        ///
-       void insertParameter(Cursor & cur, int pos, bool greedy = false, bool addarg = true);
+       void insertParameter(Cursor & cur, DocIterator const & inset_pos,
+               int pos, bool greedy = false, bool addarg = true); 
        ///
-       void removeParameter(Cursor & cur, int pos, bool greedy = false);
+       void removeParameter(Cursor & cur, DocIterator const & inset_pos,
+               int pos, bool greedy = false);
        ///
-       void makeOptional(Cursor & cur);
+       void makeOptional(Cursor & cur, DocIterator const & inset_pos);
        ///
-       void makeNonOptional(Cursor & cur);
+       void makeNonOptional(Cursor & cur, DocIterator const & inset_pos);
        ///
        idx_type defIdx() const { return optionals_ + 1; }
        /// index of default value cell of optional parameter (#1 -> n=0)
@@ -139,9 +142,10 @@ private:
        /// add missing #n arguments up to \c maxArg
        void insertMissingArguments(int maxArg);
        /// change the arity
-       void changeArity(Cursor & cur, int newNumArg);
+       void changeArity(Cursor & cur, DocIterator const & inset_pos,
+               int newNumArg);
        /// find arguments in definition and adapt the arity accordingly
-       void commitEditChanges(Cursor & cur);
+       void commitEditChanges(Cursor & cur, DocIterator const & inset_pos);
        /// The representation of the macro template, with some holes to edit
        mutable MathData look_;
        ///