From 04f893b3f600bdf278273a6ba333b164e081bcc5 Mon Sep 17 00:00:00 2001 From: Richard Kimberly Heck Date: Thu, 12 Nov 2020 16:33:28 -0500 Subject: [PATCH] Move some processing from the loop into the main InsetText routine. --- src/insets/Inset.h | 3 +++ src/insets/InsetText.cpp | 27 +++++++++++---------------- src/insets/InsetText.h | 2 +- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/insets/Inset.h b/src/insets/Inset.h index c6fbfdb2c0..7885046ad7 100644 --- a/src/insets/Inset.h +++ b/src/insets/Inset.h @@ -571,6 +571,9 @@ public: /// The boolean indicates whether we are preparing for output, e.g., /// of XHTML. virtual void updateBuffer(ParIterator const &, UpdateType, bool const) {} + /// Note that \param us is expected to be a DocIterator pointing at this inset. + /// We will assert otherwise. + virtual void updateMacros(DocIterator const & /* us */, DocIterator const & /* scope */) {} /// Updates the inset's dialog virtual Buffer const * updateFrontend() const; diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index 2a99b109be..fb581f2ddc 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -913,8 +913,13 @@ void InsetText::updateMacros(DocIterator const & us, DocIterator const & scope) { LBUFERR(us.nextInset() == this); DocIterator it = us; - pit_type const lastpit = it.lastpit(); + DocIterator ourscope = scope; + if (!producesOutput()) { + ourscope = us; + ++ourscope.pos(); + } + pit_type const lastpit = it.lastpit(); // look for macros in each paragraph while (it.pit() <= lastpit) { Paragraph & par = it.paragraph(); @@ -923,20 +928,10 @@ void InsetText::updateMacros(DocIterator const & us, DocIterator const & scope) for (auto const & insit : par.insetList()) { it.pos() = insit.pos; - if (InsetText const * itext = insit.inset->asInsetText()) { + if (InsetText * itext = insit.inset->asInsetText()) { // collect macros in inset it.push_back(CursorSlice(*insit.inset)); - if (itext->producesOutput()) { - // the simple case - updateMacros(it, scope); - } else { - // We don't want macros declared in notes, comments, etc, - // to affect anything outside them. - // New scope which ends just behind the inset - DocIterator new_scope = it; - ++new_scope.pos(); - updateMacros(it, new_scope); - } + itext->updateMacros(it, ourscope); it.pop_back(); continue; } @@ -946,7 +941,7 @@ void InsetText::updateMacros(DocIterator const & us, DocIterator const & scope) size_t const numcells = slice.nargs(); for (; slice.idx() < numcells; slice.forwardIdx()) { it.push_back(slice); - updateMacros(it, scope); + updateMacros(it, ourscope); it.pop_back(); } continue; @@ -962,7 +957,7 @@ void InsetText::updateMacros(DocIterator const & us, DocIterator const & scope) buffer().clearMacroLock(); if (!child) continue; - buffer().registerChild(child, it, scope); + buffer().registerChild(child, it, ourscope); continue; } @@ -991,7 +986,7 @@ void InsetText::updateMacros(DocIterator const & us, DocIterator const & scope) continue; // register macro - buffer().registerMacro(macroTemplate.name(), it, scope); + buffer().registerMacro(macroTemplate.name(), it, ourscope); } // next paragraph diff --git a/src/insets/InsetText.h b/src/insets/InsetText.h index 9fdfb6fdfe..079d0f4ae5 100644 --- a/src/insets/InsetText.h +++ b/src/insets/InsetText.h @@ -173,7 +173,7 @@ public: /// Update the counters of this inset and of its contents void updateBuffer(ParIterator const &, UpdateType, bool const deleted = false) override; /// - void updateMacros(DocIterator const & us, DocIterator const & scope); + void updateMacros(DocIterator const & us, DocIterator const & scope) override; /// void setMacrocontextPositionRecursive(DocIterator const & pos); /// -- 2.39.5