}
+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);
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);
}
-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();
}
void push(Inset & inset);
/// add a new cursor slice, place cursor at front (move backwards)
void pushBackward(Inset & inset);
+ /// try to put cursor in inset before it in entry cell, or next one
+ /// if it is not empty, or exit the slice if there is no next one.
+ void editInsertedInset();
+
/// pop one level off the cursor
void pop();
/// pop one slice off the cursor stack and go backwards
/// the name of the macro we are currently inputting
docstring macroName();
-
/// replace selected stuff with at, placing the former
// selection in entry cell of atom
void handleNest(MathAtom const & at);
- /// replace selected stuff with at, placing the former
- // selection in given cell of atom
- void handleNest(MathAtom const & at, int cell);
/// make sure cursor position is valid
/// FIXME: It does a subset of fixIfBroken. Maybe merge them?
// via macro mode, we want to put the cursor inside it
// if relevant. Think typing "\frac<space>".
if (c == ' '
- && cur.inMacroMode() && cur.macroName() != "\\"
- && cur.macroModeClose() && cur.pos() > 0) {
- MathAtom const atom = cur.prevAtom();
- if (atom->asNestInset() && atom->isActive()) {
- cur.posBackward();
- cur.pushBackward(*cur.nextInset());
- }
- } else if (!interpretChar(cur, c)) {
+ && cur.inMacroMode() && cur.macroName() != "\\"
+ && cur.macroModeClose() && cur.pos() > 0)
+ cur.editInsertedInset();
+ else if (!interpretChar(cur, c)) {
cmd = FuncRequest(LFUN_FINISHED_FORWARD);
cur.undispatched();
// FIXME: can we avoid skipping the end of the string?