#include <config.h>
+#include "math_cursor.h"
#include "lyxrc.h"
#include "support/limited_stack.h"
+#include "dispatchresult.h"
#include "debug.h"
#include "support/std_sstream.h"
-#include "math_cursor.h"
#include "formulabase.h"
#include "funcrequest.h"
#include "math_braceinset.h"
//#define FILEDEBUG 1
+using std::string;
using std::endl;
+#ifndef CXX_GLOBAL_CSTD
using std::isalpha;
+#endif
using std::min;
using std::swap;
}
}
- --pos();
- plainErase();
+ if (hasPrevAtom() && prevAtom()->nargs() > 0) {
+ // let's require two backspaces for 'big stuff' and
+ // highlight on the first
+ left(true);
+ } else {
+ --pos();
+ plainErase();
+ }
return true;
}
}
-void MathCursor::handleNest(MathAtom const & a)
+void MathCursor::handleNest(MathAtom const & a, int c)
{
MathAtom at = a;
- asArray(grabAndEraseSelection(), at.nucleus()->cell(0));
+ asArray(grabAndEraseSelection(), at.nucleus()->cell(c));
insert(at);
pushRight(prevAtom());
}
}
if (c == '{' || c == '}' || c == '#' || c == '&' || c == '$') {
- createMathInset(string(1, c));
+ niceInsert(createMathInset(string(1, c)));
return true;
}
}
-dispatch_result MathCursor::dispatch(FuncRequest const & cmd)
+DispatchResult MathCursor::dispatch(FuncRequest const & cmd)
{
// mouse clicks are somewhat special
// check
case LFUN_MOUSE_RELEASE:
case LFUN_MOUSE_DOUBLE: {
CursorPos & pos = Cursor_.back();
- dispatch_result res = UNDISPATCHED;
- int x = 0, y = 0;
+ int x = 0;
+ int y = 0;
getPos(x, y);
if (x < cmd.x && hasPrevAtom()) {
- res = prevAtom().nucleus()->dispatch(cmd, pos.idx_, pos.pos_);
- if (res != UNDISPATCHED)
+ DispatchResult const res =
+ prevAtom().nucleus()->dispatch(cmd, pos.idx_, pos.pos_);
+ if (res.dispatched())
return res;
}
if (x > cmd.x && hasNextAtom()) {
- res = nextAtom().nucleus()->dispatch(cmd, pos.idx_, pos.pos_);
- if (res != UNDISPATCHED)
+ DispatchResult const res =
+ nextAtom().nucleus()->dispatch(cmd, pos.idx_, pos.pos_);
+ if (res.dispatched())
return res;
}
}
for (int i = Cursor_.size() - 1; i >= 0; --i) {
CursorPos & pos = Cursor_[i];
- dispatch_result res = pos.inset_->dispatch(cmd, pos.idx_, pos.pos_);
- if (res != UNDISPATCHED) {
- if (res == DISPATCHED_POP) {
+ DispatchResult const res =
+ pos.inset_->dispatch(cmd, pos.idx_, pos.pos_);
+ if (res.dispatched()) {
+ if (res.val() == FINISHED) {
Cursor_.shrink(i + 1);
selClear();
}
return res;
}
}
- return UNDISPATCHED;
+ return DispatchResult(false);
}