X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FCursor.cpp;h=a6d799ec9c81d5ba9efcf395b6f2e1dfe6e555ea;hb=05e2621a1782504d995f961f77edc604329ab1ee;hp=fd43dd74ebb45e09a71aa3b64433c07e0674d2be;hpb=4727e2becf6b69d79ead3df1708bfad95699ef6a;p=lyx.git diff --git a/src/Cursor.cpp b/src/Cursor.cpp index fd43dd74eb..a6d799ec9c 100644 --- a/src/Cursor.cpp +++ b/src/Cursor.cpp @@ -901,6 +901,31 @@ void Cursor::pushBackward(Inset & p) } +void Cursor::editInsertedInset() +{ + LASSERT(!empty(), return); + if (pos() == 0) + return; + + InsetMath &p = prevMath(); + if (!p.isActive()) + return; + + posBackward(); + push(p); + p.idxFirst(*this); + // this could be a while() loop, but only one cell is not empty in + // cases we are interested in. The cell is not empty because we + // have inserted the selection in there. + if (!cell().empty()) { + // if it is not empty, move to the next one. + if (!inset().idxNext(*this)) + // If there is no next one, exit the inset. + popForward(); + } +} + + bool Cursor::popBackward() { LASSERT(!empty(), return false); @@ -1521,14 +1546,9 @@ void Cursor::niceInsert(MathAtom const & t) plainInsert(t); // If possible, enter the new inset and move the contents of the selection if (t->isActive()) { - posBackward(); - // be careful here: don't use 'pushBackward(t)' as this we need to - // push the clone, not the original - pushBackward(*nextInset()); - // We may not use niceInsert here (recursion) - MathData ar(buffer()); - asArray(safe, ar); - insert(ar); + idx_type const idx = prevMath().asNestInset()->firstIdx(); + asArray(safe, prevMath().cell(idx)); + editInsertedInset(); } else if (t->asMacro() && !safe.empty()) { MathData ar(buffer()); asArray(safe, ar); @@ -1665,20 +1685,14 @@ bool Cursor::down() } -void Cursor::handleNest(MathAtom const & a, int c) +void Cursor::handleNest(MathAtom const & a) { - //lyxerr << "Cursor::handleNest: " << c << endl; + idx_type const idx = a.nucleus()->asNestInset()->firstIdx(); + //lyxerr << "Cursor::handleNest: " << idx << endl; MathAtom t = a; - asArray(cap::grabAndEraseSelection(*this), t.nucleus()->cell(c)); + asArray(cap::grabAndEraseSelection(*this), t.nucleus()->cell(idx)); insert(t); - posBackward(); - pushBackward(*nextInset()); -} - - -void Cursor::handleNest(MathAtom const & a) -{ - handleNest(a, a.nucleus()->asNestInset()->firstIdx()); + editInsertedInset(); }