Improve structure of updateMacros

This commit is contained in:
Yuriy Skalko 2020-11-04 11:27:08 +02:00
parent 97ecf71016
commit 5a54ccfa87
2 changed files with 42 additions and 41 deletions

View File

@ -3730,10 +3730,11 @@ void Buffer::Impl::updateMacros(DocIterator & it, DocIterator & scope)
for (auto const & insit : par.insetList()) {
it.pos() = insit.pos;
switch (insit.inset->lyxCode()) {
// is it a nested text inset?
if (insit.inset->asInsetText()) {
// Inset needs its own scope?
case TEXT_CODE: {
InsetText const * itext = insit.inset->asInsetText();
// Inset needs its own scope?
bool newScope = itext->isMacroScope();
// scope which ends just behind the inset
@ -3744,10 +3745,9 @@ void Buffer::Impl::updateMacros(DocIterator & it, DocIterator & scope)
it.push_back(CursorSlice(*insit.inset));
updateMacros(it, newScope ? insetScope : scope);
it.pop_back();
continue;
break;
}
if (insit.inset->asInsetTabular()) {
case TABULAR_CODE: {
CursorSlice slice(*insit.inset);
size_t const numcells = slice.nargs();
for (; slice.idx() < numcells; slice.forwardIdx()) {
@ -3755,11 +3755,10 @@ void Buffer::Impl::updateMacros(DocIterator & it, DocIterator & scope)
updateMacros(it, scope);
it.pop_back();
}
continue;
break;
}
// is it an external file?
if (insit.inset->lyxCode() == INCLUDE_CODE) {
case INCLUDE_CODE: {
// get buffer of external file
InsetInclude const & incinset =
static_cast<InsetInclude const &>(*insit.inset);
@ -3767,7 +3766,7 @@ void Buffer::Impl::updateMacros(DocIterator & it, DocIterator & scope)
Buffer * child = incinset.loadIfNeeded();
macro_lock = false;
if (!child)
continue;
break;
// register its position, but only when it is
// included first in the buffer
@ -3775,19 +3774,16 @@ void Buffer::Impl::updateMacros(DocIterator & it, DocIterator & scope)
// register child with its scope
position_to_children[it] = Impl::ScopeBuffer(scope, child);
continue;
break;
}
InsetMath * im = insit.inset->asInsetMath();
if (doing_export && im) {
InsetMathHull * hull = im->asHullInset();
if (hull)
case MATH_HULL_CODE: {
if (!doing_export)
break;
InsetMathHull * hull = insit.inset->asInsetMath()->asHullInset();
hull->recordLocation(it);
break;
}
if (insit.inset->lyxCode() != MATHMACRO_CODE)
continue;
case MATHMACRO_CODE: {
// get macro data
InsetMathMacroTemplate & macroTemplate =
*insit.inset->asInsetMath()->asMacroTemplate();
@ -3800,13 +3796,18 @@ void Buffer::Impl::updateMacros(DocIterator & it, DocIterator & scope)
// then the BufferView's cursor will be invalid in
// some cases which leads to crashes.
if (!valid)
continue;
break;
// register macro
// FIXME (Abdel), I don't understand why we pass 'it' here
// instead of 'macroTemplate' defined above... is this correct?
macros[macroTemplate.name()][it] =
Impl::ScopeMacro(scope, MacroData(const_cast<Buffer *>(owner_), it));
break;
}
default:
break;
}
}
// next paragraph

View File

@ -403,8 +403,8 @@ void MathData::updateMacros(Cursor * cur, MacroContext const & mc,
{
// If we are editing a macro, we cannot update it immediately,
// otherwise wrong undo steps will be recorded (bug 6208).
InsetMath const * inmath = cur ? cur->inset().asInsetMath() : 0;
InsetMathMacro const * inmacro = inmath ? inmath->asMacro() : 0;
InsetMath const * inmath = cur ? cur->inset().asInsetMath() : nullptr;
InsetMathMacro const * inmacro = inmath ? inmath->asMacro() : nullptr;
docstring const edited_name = inmacro ? inmacro->name() : docstring();
// go over the array and look for macros