X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FCursor.cpp;h=ad46e8c50567e61af367f7b1c90e26133393086d;hb=313d9fa4d056ed213607500076c1bd391a563b6d;hp=ee54ace608a3c31a0a297af01c2f6fd6150a563a;hpb=a877cdb1963f01d27b4bd0d194de928223cb5ae5;p=lyx.git diff --git a/src/Cursor.cpp b/src/Cursor.cpp index ee54ace608..ad46e8c505 100644 --- a/src/Cursor.cpp +++ b/src/Cursor.cpp @@ -38,6 +38,7 @@ #include "support/gettext.h" #include "support/lassert.h" +#include "insets/InsetLayout.h" #include "insets/InsetTabular.h" #include "mathed/InsetMath.h" @@ -1593,9 +1594,20 @@ bool Cursor::backspace(bool const force) // [|], can not delete from inside return false; } else { - if (inMathed()) - pullArg(); - else + if (inMathed()) { + switch (inset().asInsetMath()->getType()) { + case hullEqnArray: + case hullAlign: + case hullFlAlign: { + FuncRequest cmd(LFUN_CHAR_BACKWARD); + this->dispatch(cmd); + break; + } + default: + pullArg(); + break; + } + } else popBackward(); return true; } @@ -1700,8 +1712,11 @@ void Cursor::handleNest(MathAtom const & a) { idx_type const idx = a.nucleus()->asNestInset()->firstIdx(); //lyxerr << "Cursor::handleNest: " << idx << endl; + InsetMath const * im = selectionBegin().inset().asInsetMath(); + Parse::flags const f = im && im->currentMode() != InsetMath::MATH_MODE + ? Parse::TEXTMODE : Parse::NORMAL; MathAtom t = a; - asArray(cap::grabAndEraseSelection(*this), t.nucleus()->cell(idx)); + asArray(cap::grabAndEraseSelection(*this), t.nucleus()->cell(idx), f); insert(t); editInsertedInset(); } @@ -1878,7 +1893,7 @@ void Cursor::normalize() << " in atom: '"; odocstringstream os; otexrowstream ots(os); - WriteStream wi(ots, false, true, WriteStream::wsDefault); + TeXMathStream wi(ots, false, true, TeXMathStream::wsDefault); inset().asInsetMath()->write(wi); lyxerr << to_utf8(os.str()) << endl; pos() = lastpos(); @@ -2025,20 +2040,39 @@ bool Cursor::mathForward(bool word) posForward(); while (pos() < lastpos() && mc == nextMath().mathClass()); } else if (openable(nextAtom())) { + InsetMathScript const * n = nextMath().asScriptInset(); + bool to_brace_deco = n && !n->nuc().empty() + && n->nuc().back()->lyxCode() == MATH_DECORATION_CODE + && n->nuc().back()->mathClass() == MC_OP; // single step: try to enter the next inset pushBackward(nextMath()); inset().idxFirst(*this); + // Make sure the cursor moves directly to an + // \overbrace or \underbrace inset (bug 2264) + if (to_brace_deco) { + pushBackward(nextMath()); + inset().idxFirst(*this); + } } else posForward(); return true; } if (inset().idxForward(*this)) return true; + InsetMath const * m = inset().asInsetMath(); + bool from_brace_deco = m + && m->lyxCode() == MATH_DECORATION_CODE + && m->mathClass() == MC_OP; // try to pop forwards --- but don't pop out of math! leave that to // the FINISH lfuns int s = depth() - 2; - if (s >= 0 && operator[](s).inset().asInsetMath()) - return popForward(); + if (s >= 0 && operator[](s).inset().asInsetMath() && popForward()) { + // Make sure the cursor moves directly to an + // \overbrace or \underbrace inset (bug 2264) + bool to_script = inset().asInsetMath() + && inset().asInsetMath()->asScriptInset(); + return from_brace_deco && to_script ? mathForward(word) : true; + } return false; } @@ -2060,21 +2094,41 @@ bool Cursor::mathBackward(bool word) while (pos() > 0 && mc == prevMath().mathClass()); } } else if (openable(prevAtom())) { + InsetMathScript const * p = prevMath().asScriptInset(); + bool to_brace_deco = p && !p->nuc().empty() + && p->nuc().back()->lyxCode() == MATH_DECORATION_CODE + && p->nuc().back()->mathClass() == MC_OP; // single step: try to enter the preceding inset posBackward(); push(nextMath()); inset().idxLast(*this); + // Make sure the cursor moves directly to an + // \overbrace or \underbrace inset (bug 2264) + if (to_brace_deco) { + posBackward(); + push(nextMath()); + inset().idxLast(*this); + } } else posBackward(); return true; } if (inset().idxBackward(*this)) return true; + InsetMath const * m = inset().asInsetMath(); + bool from_brace_deco = m + && m->lyxCode() == MATH_DECORATION_CODE + && m->mathClass() == MC_OP; // try to pop backwards --- but don't pop out of math! leave that to // the FINISH lfuns int s = depth() - 2; - if (s >= 0 && operator[](s).inset().asInsetMath()) - return popBackward(); + if (s >= 0 && operator[](s).inset().asInsetMath() && popBackward()) { + // Make sure the cursor moves directly to an + // \overbrace or \underbrace inset (bug 2264) + bool to_script = inset().asInsetMath() + && inset().asInsetMath()->asScriptInset(); + return from_brace_deco && to_script ? mathBackward(word) : true; + } return false; } @@ -2470,6 +2524,9 @@ void Cursor::setCurrentFont() void Cursor::checkBufferStructure() { + if (buffer()->isInternal()) + return; + Buffer const * master = buffer()->masterBuffer(); master->tocBackend().updateItem(*this); if (master != buffer() && !master->hasGuiDelegate())