#include "FuncCode.h"
#include "FuncRequest.h"
#include "Language.h"
+#include "LyXAction.h"
#include "LyXFunc.h" // only for setMessage()
#include "LyXRC.h"
#include "Paragraph.h"
}
+bool Cursor::getStatus(FuncRequest const & cmd, FuncStatus & status) const
+{
+ Cursor cur = *this;
+
+ // Try to fix cursor in case it is broken.
+ cur.fixIfBroken();
+
+ // Is this a function that acts on inset at point?
+ Inset * inset = cur.nextInset();
+ if (lyxaction.funcHasFlag(cmd.action, LyXAction::AtPoint)
+ && inset && inset->getStatus(cur, cmd, status))
+ return true;
+
+ // This is, of course, a mess. Better create a new doc iterator and use
+ // this in Inset::getStatus. This might require an additional
+ // BufferView * arg, though (which should be avoided)
+ //Cursor safe = *this;
+ bool res = false;
+ for ( ; cur.depth(); cur.pop()) {
+ //lyxerr << "\nCursor::getStatus: cmd: " << cmd << endl << *this << endl;
+ LASSERT(cur.idx() <= cur.lastidx(), /**/);
+ LASSERT(cur.pit() <= cur.lastpit(), /**/);
+ LASSERT(cur.pos() <= cur.lastpos(), /**/);
+
+ // The inset's getStatus() will return 'true' if it made
+ // a definitive decision on whether it want to handle the
+ // request or not. The result of this decision is put into
+ // the 'status' parameter.
+ if (cur.inset().getStatus(cur, cmd, status)) {
+ res = true;
+ break;
+ }
+ }
+ return res;
+}
+
+
void Cursor::dispatch(FuncRequest const & cmd0)
{
LYXERR(Debug::DEBUG, "cmd: " << cmd0 << '\n' << *this);
buffer()->undo().beginUndoGroup();
+ // Is this a function that acts on inset at point?
+ if (lyxaction.funcHasFlag(cmd.action, LyXAction::AtPoint)
+ && nextInset()) {
+ result().dispatched(true);
+ result().update(Update::FitCursor | Update::Force);
+ FuncRequest tmpcmd = cmd;
+ LYXERR(Debug::DEBUG, "Cursor::dispatch: (AtPoint) cmd: "
+ << cmd0 << endl << *this);
+ nextInset()->dispatch(*this, tmpcmd);
+ if (result().dispatched())
+ return;
+ }
+
// store some values to be used inside of the handlers
beforeDispatchCursor_ = *this;
for (; depth(); pop(), boundary(false)) {
void Cursor::niceInsert(docstring const & t, Parse::flags f)
{
- MathData ar;
+ MathData ar(buffer());
asArray(t, ar, f);
if (ar.size() == 1)
niceInsert(ar[0]);
// push the clone, not the original
pushBackward(*nextInset());
// We may not use niceInsert here (recursion)
- MathData ar;
+ MathData ar(buffer());
asArray(safe, ar);
insert(ar);
}
return false;
InsetMathUnknown * p = activeMacro();
p->finalize();
- MathData selection;
+ MathData selection(buffer());
asArray(p->selection(), selection);
docstring const s = p->name();
--pos();
if (in && in->interpretString(*this, s))
return true;
MathAtom atom = buffer()->getMacro(name, *this, false) ?
- MathAtom(new MathMacro(name)) : createInsetMath(name);
+ MathAtom(new MathMacro(buffer(), name)) : createInsetMath(name, buffer());
// try to put argument into macro, if we just inserted a macro
bool macroArg = false;
}
top().pos() = min(tm.x2pos(pit(), next_row, xo), top().lastpos());
- boundary(tm.x2pos(pit(), next_row, xo)
- == tm.x2pos(pit(), next_row, tm.width()));
+ int const xpos = tm.x2pos(pit(), next_row, xo);
+ bool const at_end_row = xpos == tm.x2pos(pit(), next_row, tm.width());
+ bool const at_beg_row = xpos == tm.x2pos(pit(), next_row, 0);
+
+ if (at_end_row && at_beg_row)
+ // make sure the cursor ends up on this row
+ boundary(false);
+ else
+ boundary(at_end_row);
+
updateNeeded |= bv().checkDepm(*this, old);
}
} else {
// cursor in between. split cell
MathData::iterator bt = cell().begin();
- MathAtom at = createInsetMath(from_utf8(font));
- at.nucleus()->cell(0) = MathData(bt, bt + pos());
+ MathAtom at = createInsetMath(from_utf8(font), buffer());
+ at.nucleus()->cell(0) = MathData(buffer(), bt, bt + pos());
cell().erase(bt, bt + pos());
popBackward();
plainInsert(at);