3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Alejandro Aguilar Sierra
9 * Full author contact details are available in file CREDITS.
16 #include "support/LAssert.h"
17 #include "support/limited_stack.h"
19 #include "support/std_sstream.h"
20 #include "math_cursor.h"
21 #include "formulabase.h"
22 #include "funcrequest.h"
23 #include "math_braceinset.h"
24 #include "math_commentinset.h"
25 #include "math_charinset.h"
26 #include "math_factory.h"
27 #include "math_gridinset.h"
28 #include "math_macroarg.h"
29 #include "math_macrotemplate.h"
30 #include "math_mathmlstream.h"
31 #include "math_scriptinset.h"
32 #include "math_spaceinset.h"
33 #include "math_support.h"
34 #include "math_unknowninset.h"
39 using namespace lyx::support;
46 using std::ostringstream;
49 // matheds own cut buffer
50 limited_stack<string> theCutBuffer;
53 MathCursor::MathCursor(InsetFormulaBase * formula, bool front)
54 : formula_(formula), autocorrect_(false), selection_(false), targetx_(-1)
56 front ? first() : last();
61 MathCursor::~MathCursor()
63 // ensure that 'notifyCursorLeave' is called
69 void MathCursor::push(MathAtom & t)
71 Cursor_.push_back(CursorPos(t.nucleus()));
75 void MathCursor::pushLeft(MathAtom & t)
77 //lyxerr << "Entering atom " << t << " left" << endl;
79 t->idxFirst(idx(), pos());
83 void MathCursor::pushRight(MathAtom & t)
85 //lyxerr << "Entering atom " << t << " right" << endl;
88 t->idxLast(idx(), pos());
92 bool MathCursor::popLeft()
94 //lyxerr << "Leaving atom to the left" << endl;
97 inset()->notifyCursorLeaves(idx());
100 inset()->notifyCursorLeaves(idx());
106 bool MathCursor::popRight()
108 //lyxerr << "Leaving atom "; inset()->write(cerr, false); cerr << " right" << endl;
111 inset()->notifyCursorLeaves(idx());
114 inset()->notifyCursorLeaves(idx());
123 void MathCursor::dump(char const * what) const
125 lyxerr << "MC: " << what << endl;
126 lyxerr << " Cursor: " << depth() << endl;
127 for (unsigned i = 0; i < depth(); ++i)
128 lyxerr << " i: " << i << ' ' << Cursor_[i] << endl;
129 lyxerr << " Anchor: " << Anchor_.size() << endl;
130 for (unsigned i = 0; i < Anchor_.size(); ++i)
131 lyxerr << " i: " << i << ' ' << Anchor_[i] << endl;
132 lyxerr << " sel: " << selection_ << endl;
135 void MathCursor::dump(char const *) const {}
139 bool MathCursor::isInside(MathInset const * p) const
141 for (unsigned i = 0; i < depth(); ++i)
142 if (Cursor_[i].inset_ == p)
148 bool MathCursor::openable(MathAtom const & t, bool sel) const
157 // we can't move into anything new during selection
158 if (depth() == Anchor_.size())
160 if (t.operator->() != Anchor_[depth()].inset_)
167 bool MathCursor::inNucleus() const
169 return inset()->asScriptInset() && idx() == 2;
173 bool MathCursor::posLeft()
182 bool MathCursor::posRight()
191 bool MathCursor::left(bool sel)
194 autocorrect_ = false;
195 targetx_ = -1; // "no target"
202 if (hasPrevAtom() && openable(prevAtom(), sel)) {
203 pushRight(prevAtom());
207 return posLeft() || idxLeft() || popLeft() || selection_;
211 bool MathCursor::right(bool sel)
214 autocorrect_ = false;
215 targetx_ = -1; // "no target"
222 if (hasNextAtom() && openable(nextAtom(), sel)) {
223 pushLeft(nextAtom());
227 return posRight() || idxRight() || popRight() || selection_;
231 void MathCursor::first()
234 push(formula_->par());
235 inset()->idxFirst(idx(), pos());
239 void MathCursor::last()
242 push(formula_->par());
243 inset()->idxLast(idx(), pos());
248 (MathIterator const & cursor, MathIterator const & anchor)
250 // avoid deeper nested insets when selecting
251 if (cursor.size() > anchor.size())
254 // anchor might be deeper, should have same path then
255 for (MathIterator::size_type i = 0; i < cursor.size(); ++i)
256 if (cursor[i].inset_ != anchor[i].inset_)
259 // position should be ok.
264 void MathCursor::setPos(int x, int y)
267 bool res = bruteFind(x, y,
268 formula()->xlow(), formula()->xhigh(),
269 formula()->ylow(), formula()->yhigh());
271 // this can happen on creation of "math-display"
275 targetx_ = -1; // "no target"
281 bool MathCursor::home(bool sel)
284 autocorrect_ = false;
287 if (!inset()->idxHome(idx(), pos()))
290 targetx_ = -1; // "no target"
295 bool MathCursor::end(bool sel)
298 autocorrect_ = false;
301 if (!inset()->idxEnd(idx(), pos()))
304 targetx_ = -1; // "no target"
309 void MathCursor::plainErase()
311 array().erase(pos());
315 void MathCursor::markInsert()
317 //lyxerr << "inserting mark" << endl;
318 array().insert(pos(), MathAtom(new MathCharInset(0)));
322 void MathCursor::markErase()
324 //lyxerr << "deleting mark" << endl;
325 array().erase(pos());
329 void MathCursor::plainInsert(MathAtom const & t)
332 array().insert(pos(), t);
337 void MathCursor::insert2(string const & str)
345 void MathCursor::insert(string const & str)
347 //lyxerr << "inserting '" << str << "'" << endl;
349 for (string::const_iterator it = str.begin(); it != str.end(); ++it)
350 plainInsert(MathAtom(new MathCharInset(*it)));
354 void MathCursor::insert(char c)
356 //lyxerr << "inserting '" << c << "'" << endl;
358 plainInsert(MathAtom(new MathCharInset(c)));
362 void MathCursor::insert(MathAtom const & t)
370 void MathCursor::niceInsert(string const & t)
381 void MathCursor::niceInsert(MathAtom const & t)
384 string safe = grabAndEraseSelection();
386 // enter the new inset and move the contents of the selection if possible
389 pushLeft(nextAtom());
395 void MathCursor::insert(MathArray const & ar)
400 array().insert(pos(), ar);
405 void MathCursor::paste(string const & data)
407 dispatch(FuncRequest(LFUN_PASTE, data));
411 bool MathCursor::backspace()
413 autocorrect_ = false;
421 if (inset()->ncols() == 1 &&
422 inset()->nrows() == 1 &&
431 MathUnknownInset * p = activeMacro();
432 if (p->name().size() > 1) {
433 p->setName(p->name().substr(0, p->name().size() - 1));
444 bool MathCursor::erase()
446 autocorrect_ = false;
455 // delete empty cells if possible
457 if (inset()->idxDelete(idx()))
460 // old behaviour when in last position of cell
461 if (pos() == size()) {
462 if (inset()->ncols() == 1 && inset()->nrows() == 1 && depth() == 1 && size() == 0)
465 inset()->idxGlue(idx());
475 bool MathCursor::up(bool sel)
480 MathIterator save = Cursor_;
484 autocorrect_ = false;
489 bool MathCursor::down(bool sel)
494 MathIterator save = Cursor_;
498 autocorrect_ = false;
503 void MathCursor::macroModeClose()
507 MathUnknownInset * p = activeMacro();
509 string s = p->name();
511 array().erase(pos());
513 // do nothing if the macro name is empty
517 string const name = s.substr(1);
519 // prevent entering of recursive macros
520 if (formula()->lyxCode() == InsetOld::MATHMACRO_CODE
521 && formula()->getInsetName() == name)
522 lyxerr << "can't enter recursive macro" << endl;
524 niceInsert(createMathInset(name));
528 string MathCursor::macroName() const
530 return inMacroMode() ? activeMacro()->name() : string();
534 void MathCursor::selClear()
541 void MathCursor::selCopy()
545 theCutBuffer.push(grabSelection());
548 //theCutBuffer.erase();
553 void MathCursor::selCut()
556 theCutBuffer.push(grabAndEraseSelection());
560 void MathCursor::selDel()
570 void MathCursor::selPaste(size_t n)
574 if (n < theCutBuffer.size())
575 paste(theCutBuffer[n]);
581 void MathCursor::selHandle(bool sel)
583 if (sel == selection_)
591 void MathCursor::selStart()
601 void MathCursor::selClearOrDel()
603 if (lyxrc.auto_region_delete)
610 void MathCursor::drawSelection(PainterInfo & pi) const
616 getSelection(i1, i2);
617 i1.inset_->drawSelection(pi, i1.idx_, i1.pos_, i2.idx_, i2.pos_);
621 void MathCursor::handleNest(MathAtom const & a)
624 asArray(grabAndEraseSelection(), at.nucleus()->cell(0));
626 pushRight(prevAtom());
630 void MathCursor::getPos(int & x, int & y) const
632 inset()->getPos(idx(), pos(), x, y);
636 int MathCursor::targetX() const
646 MathInset * MathCursor::inset() const
648 return cursor().inset_;
652 InsetFormulaBase * MathCursor::formula() const
658 MathCursor::idx_type MathCursor::idx() const
660 return cursor().idx_;
664 MathCursor::idx_type & MathCursor::idx()
666 return cursor().idx_;
670 MathCursor::pos_type MathCursor::pos() const
672 return cursor().pos_;
676 void MathCursor::adjust(pos_type from, difference_type diff)
678 if (cursor().pos_ > from)
679 cursor().pos_ += diff;
680 if (Anchor_.back().pos_ > from)
681 Anchor_.back().pos_ += diff;
682 // just to be on the safe side
683 // theoretically unecessary
688 MathCursor::pos_type & MathCursor::pos()
690 return cursor().pos_;
694 bool MathCursor::inMacroMode() const
698 MathUnknownInset const * p = prevAtom()->asUnknownInset();
699 return p && !p->final();
703 MathUnknownInset * MathCursor::activeMacro()
705 return inMacroMode() ? prevAtom().nucleus()->asUnknownInset() : 0;
709 MathUnknownInset const * MathCursor::activeMacro() const
711 return inMacroMode() ? prevAtom()->asUnknownInset() : 0;
715 bool MathCursor::inMacroArgMode() const
717 return pos() > 0 && prevAtom()->getChar() == '#';
721 bool MathCursor::selection() const
727 MathGridInset * MathCursor::enclosingGrid(MathCursor::idx_type & idx) const
729 for (MathInset::difference_type i = depth() - 1; i >= 0; --i) {
730 MathGridInset * p = Cursor_[i].inset_->asGridInset();
732 idx = Cursor_[i].idx_;
740 void MathCursor::popToHere(MathInset const * p)
742 while (depth() && Cursor_.back().inset_ != p)
747 void MathCursor::popToEnclosingGrid()
749 while (depth() && !Cursor_.back().inset_->asGridInset())
754 void MathCursor::popToEnclosingHull()
756 while (depth() && !Cursor_.back().inset_->asHullInset())
761 void MathCursor::pullArg()
764 MathArray a = array();
767 array().insert(pos(), a);
770 formula()->mutateToText();
775 void MathCursor::touch()
777 MathIterator::const_iterator it = Cursor_.begin();
778 MathIterator::const_iterator et = Cursor_.end();
779 for ( ; it != et; ++it)
784 void MathCursor::normalize()
786 if (idx() >= inset()->nargs()) {
787 lyxerr << "this should not really happen - 1: "
788 << idx() << ' ' << inset()->nargs()
789 << " in: " << inset() << endl;
792 idx() = min(idx(), inset()->nargs() - 1);
794 if (pos() > size()) {
795 lyxerr << "this should not really happen - 2: "
796 << pos() << ' ' << size() << " in idx: " << idx()
798 WriteStream wi(lyxerr, false, true);
803 pos() = min(pos(), size());
807 MathCursor::size_type MathCursor::size() const
809 return array().size();
813 bool MathCursor::hasPrevAtom() const
819 bool MathCursor::hasNextAtom() const
821 return pos() < size();
825 MathAtom const & MathCursor::prevAtom() const
828 return array()[pos() - 1];
832 MathAtom & MathCursor::prevAtom()
835 return array()[pos() - 1];
839 MathAtom const & MathCursor::nextAtom() const
841 Assert(pos() < size());
842 return array()[pos()];
846 MathAtom & MathCursor::nextAtom()
848 Assert(pos() < size());
849 return array()[pos()];
853 MathArray & MathCursor::array() const
855 static MathArray dummy;
857 if (idx() >= inset()->nargs()) {
858 lyxerr << "############ idx_ " << idx() << " not valid" << endl;
863 lyxerr << "############ depth() == 0 not valid" << endl;
867 return cursor().cell();
871 void MathCursor::idxNext()
873 inset()->idxNext(idx(), pos());
877 void MathCursor::idxPrev()
879 inset()->idxPrev(idx(), pos());
883 char MathCursor::valign() const
886 MathGridInset * p = enclosingGrid(idx);
887 return p ? p->valign() : '\0';
891 char MathCursor::halign() const
894 MathGridInset * p = enclosingGrid(idx);
895 return p ? p->halign(idx % p->ncols()) : '\0';
899 void MathCursor::getSelection(CursorPos & i1, CursorPos & i2) const
901 CursorPos anc = normalAnchor();
902 if (anc < cursor()) {
912 CursorPos & MathCursor::cursor()
915 return Cursor_.back();
919 CursorPos const & MathCursor::cursor() const
922 return Cursor_.back();
926 bool MathCursor::goUpDown(bool up)
928 // Be warned: The 'logic' implemented in this function is highly fragile.
929 // A distance of one pixel or a '<' vs '<=' _really_ matters.
930 // So fiddle around with it only if you know what you are doing!
935 // check if we had something else in mind, if not, this is the future goal
941 // try neigbouring script insets
944 MathScriptInset const * p = prevAtom()->asScriptInset();
945 if (p && p->has(up)) {
948 idx() = up; // the superscript has index 1
950 ///lyxerr << "updown: handled by scriptinset to the left" << endl;
957 MathScriptInset const * p = nextAtom()->asScriptInset();
958 if (p && p->has(up)) {
962 ///lyxerr << "updown: handled by scriptinset to the right" << endl;
967 // try current cell for e.g. text insets
968 if (inset()->idxUpDown2(idx(), pos(), up, targetx_))
971 //xarray().boundingBox(xlow, xhigh, ylow, yhigh);
976 //if (bruteFind(xo, yo, xlow, xhigh, ylow, yhigh)) {
977 // lyxerr << "updown: handled by brute find in the same cell" << endl;
981 // try to find an inset that knows better then we
983 ///lyxerr << "updown: We are in " << *inset() << " idx: " << idx() << endl;
985 if (inset()->idxUpDown(idx(), pos(), up, targetx_)) {
986 // try to find best position within this inset
992 // no such inset found, just take something "above"
993 ///lyxerr << "updown: handled by strange case" << endl;
999 up ? formula()->ylow() : yo + 4,
1000 up ? yo - 4 : formula()->yhigh()
1003 // any improvement so far?
1006 if (up ? ynew < yo : ynew > yo)
1012 bool MathCursor::bruteFind
1013 (int x, int y, int xlow, int xhigh, int ylow, int yhigh)
1015 MathIterator best_cursor;
1016 double best_dist = 1e10;
1018 MathIterator it = ibegin(formula()->par().nucleus());
1019 MathIterator et = iend(formula()->par().nucleus());
1021 // avoid invalid nesting when selecting
1022 if (!selection_ || positionable(it, Anchor_)) {
1024 it.back().getPos(xo, yo);
1025 if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
1026 double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
1027 //lyxerr << "x: " << x << " y: " << y << " d: " << endl;
1028 // '<=' in order to take the last possible position
1029 // this is important for clicking behind \sum in e.g. '\sum_i a'
1030 if (d <= best_dist) {
1042 if (best_dist < 1e10)
1043 Cursor_ = best_cursor;
1044 return best_dist < 1e10;
1048 void MathCursor::bruteFind2(int x, int y)
1050 double best_dist = 1e10;
1052 MathIterator it = Cursor_;
1053 it.back().setPos(0);
1054 MathIterator et = Cursor_;
1055 et.back().setPos(it.cell().size());
1056 for (int i = 0; ; ++i) {
1058 it.back().getPos(xo, yo);
1059 double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
1060 // '<=' in order to take the last possible position
1061 // this is important for clicking behind \sum in e.g. '\sum_i a'
1062 lyxerr << "i: " << i << " d: " << d << " best: " << best_dist << endl;
1063 if (d <= best_dist) {
1074 bool MathCursor::idxLineLast()
1076 idx() -= idx() % inset()->ncols();
1077 idx() += inset()->ncols() - 1;
1082 bool MathCursor::idxLeft()
1084 return inset()->idxLeft(idx(), pos());
1088 bool MathCursor::idxRight()
1090 return inset()->idxRight(idx(), pos());
1094 bool MathCursor::script(bool up)
1096 // Hack to get \\^ and \\_ working
1097 if (inMacroMode() && macroName() == "\\") {
1099 niceInsert(createMathInset("mathcircumflex"));
1106 string safe = grabAndEraseSelection();
1108 // we are in a nucleus of a script inset, move to _our_ script
1109 inset()->asScriptInset()->ensure(up);
1112 } else if (hasPrevAtom() && prevAtom()->asScriptInset()) {
1113 prevAtom().nucleus()->asScriptInset()->ensure(up);
1114 pushRight(prevAtom());
1117 } else if (hasPrevAtom()) {
1119 array()[pos()] = MathAtom(new MathScriptInset(nextAtom(), up));
1120 pushLeft(nextAtom());
1124 plainInsert(MathAtom(new MathScriptInset(up)));
1125 prevAtom().nucleus()->asScriptInset()->ensure(up);
1126 pushRight(prevAtom());
1136 bool MathCursor::interpret(char c)
1138 //lyxerr << "interpret 2: '" << c << "'" << endl;
1139 targetx_ = -1; // "no target"
1140 if (inMacroArgMode()) {
1144 MathMacroTemplate const * p = formula()->par()->asMacroTemplate();
1145 if (p && 1 <= n && n <= p->numargs())
1146 insert(MathAtom(new MathMacroArgument(c - '0')));
1148 insert(createMathInset("#"));
1149 interpret(c); // try again
1155 if (inMacroMode()) {
1156 string name = macroName();
1157 //lyxerr << "interpret name: '" << name << "'" << endl;
1160 activeMacro()->setName(activeMacro()->name() + c);
1164 // handle 'special char' macros
1169 if (currentMode() == MathInset::TEXT_MODE)
1170 niceInsert(createMathInset("textbackslash"));
1172 niceInsert(createMathInset("backslash"));
1173 } else if (c == '{') {
1174 niceInsert(MathAtom(new MathBraceInset));
1176 niceInsert(createMathInset(string(1, c)));
1181 // leave macro mode and try again if necessary
1184 niceInsert(MathAtom(new MathBraceInset));
1190 // This is annoying as one has to press <space> far too often.
1194 // leave autocorrect mode if necessary
1195 if (autocorrect_ && c == ' ') {
1196 autocorrect_ = false;
1201 // just clear selection on pressing the space bar
1202 if (selection_ && c == ' ') {
1210 //lyxerr << "starting with macro" << endl;
1211 insert(MathAtom(new MathUnknownInset("\\", false)));
1216 if (currentMode() == MathInset::TEXT_MODE)
1222 if (currentMode() == MathInset::TEXT_MODE) {
1223 // insert spaces in text mode,
1224 // but suppress direct insertion of two spaces in a row
1225 // the still allows typing '<space>a<space>' and deleting the 'a', but
1226 // it is better than nothing...
1227 if (!hasPrevAtom() || prevAtom()->getChar() != ' ')
1231 if (hasPrevAtom() && prevAtom()->asSpaceInset()) {
1232 prevAtom().nucleus()->asSpaceInset()->incSpace();
1237 // if are at the very end, leave the formula
1238 return pos() != size();
1241 if (c == '{' || c == '}' || c == '#' || c == '&' || c == '$') {
1242 createMathInset(string(1, c));
1247 niceInsert(MathAtom(new MathCommentInset));
1251 // try auto-correction
1252 //if (autocorrect_ && hasPrevAtom() && math_autocorrect(prevAtom(), c))
1255 // no special circumstances, so insert the character without any fuss
1257 autocorrect_ = true;
1262 void MathCursor::setSelection(MathIterator const & where, size_type n)
1271 void MathCursor::insetToggle()
1273 if (hasNextAtom()) {
1274 // toggle previous inset ...
1275 nextAtom().nucleus()->lock(!nextAtom()->lock());
1276 } else if (popLeft() && hasNextAtom()) {
1277 // ... or enclosing inset if we are in the last inset position
1278 nextAtom().nucleus()->lock(!nextAtom()->lock());
1284 string MathCursor::info() const
1287 os << "Math editor mode. ";
1288 for (int i = 0, n = depth(); i < n; ++i) {
1289 Cursor_[i].inset_->infoize(os);
1293 prevAtom()->infoize2(os);
1295 return STRCONV(os.str());
1299 unsigned MathCursor::depth() const
1301 return Cursor_.size();
1309 void region(CursorPos const & i1, CursorPos const & i2,
1310 MathInset::row_type & r1, MathInset::row_type & r2,
1311 MathInset::col_type & c1, MathInset::col_type & c2)
1313 MathInset * p = i1.inset_;
1314 c1 = p->col(i1.idx_);
1315 c2 = p->col(i2.idx_);
1318 r1 = p->row(i1.idx_);
1319 r2 = p->row(i2.idx_);
1327 string MathCursor::grabSelection() const
1334 getSelection(i1, i2);
1336 if (i1.idx_ == i2.idx_) {
1337 MathArray::const_iterator it = i1.cell().begin();
1338 return asString(MathArray(it + i1.pos_, it + i2.pos_));
1343 region(i1, i2, r1, r2, c1, c2);
1346 for (row_type row = r1; row <= r2; ++row) {
1349 for (col_type col = c1; col <= c2; ++col) {
1352 data += asString(i1.inset_->cell(i1.inset_->index(row, col)));
1359 void MathCursor::eraseSelection()
1363 getSelection(i1, i2);
1364 if (i1.idx_ == i2.idx_)
1365 i1.cell().erase(i1.pos_, i2.pos_);
1367 MathInset * p = i1.inset_;
1370 region(i1, i2, r1, r2, c1, c2);
1371 for (row_type row = r1; row <= r2; ++row)
1372 for (col_type col = c1; col <= c2; ++col)
1373 p->cell(p->index(row, col)).clear();
1379 string MathCursor::grabAndEraseSelection()
1383 string res = grabSelection();
1390 CursorPos MathCursor::normalAnchor() const
1392 if (Anchor_.size() < depth()) {
1394 lyxerr << "unusual Anchor size" << endl;
1396 //lyx::Assert(Anchor_.size() >= cursor.depth());
1397 // use Anchor on the same level as Cursor
1398 CursorPos normal = Anchor_[depth() - 1];
1399 if (depth() < Anchor_.size() && !(normal < cursor())) {
1400 // anchor is behind cursor -> move anchor behind the inset
1407 dispatch_result MathCursor::dispatch(FuncRequest const & cmd)
1409 // mouse clicks are somewhat special
1411 switch (cmd.action) {
1412 case LFUN_MOUSE_PRESS:
1413 case LFUN_MOUSE_MOTION:
1414 case LFUN_MOUSE_RELEASE:
1415 case LFUN_MOUSE_DOUBLE: {
1416 CursorPos & pos = Cursor_.back();
1417 dispatch_result res = UNDISPATCHED;
1420 if (x < cmd.x && hasPrevAtom()) {
1421 res = prevAtom().nucleus()->dispatch(cmd, pos.idx_, pos.pos_);
1422 if (res != UNDISPATCHED)
1425 if (x > cmd.x && hasNextAtom()) {
1426 res = nextAtom().nucleus()->dispatch(cmd, pos.idx_, pos.pos_);
1427 if (res != UNDISPATCHED)
1435 for (int i = Cursor_.size() - 1; i >= 0; --i) {
1436 CursorPos & pos = Cursor_[i];
1437 dispatch_result res = pos.inset_->dispatch(cmd, pos.idx_, pos.pos_);
1438 if (res != UNDISPATCHED) {
1439 if (res == DISPATCHED_POP) {
1440 Cursor_.shrink(i + 1);
1446 return UNDISPATCHED;
1450 MathInset::mode_type MathCursor::currentMode() const
1452 for (int i = Cursor_.size() - 1; i >= 0; --i) {
1453 MathInset::mode_type res = Cursor_[i].inset_->currentMode();
1454 if (res != MathInset::UNDECIDED_MODE)
1457 return MathInset::UNDECIDED_MODE;
1461 void MathCursor::handleFont(string const & font)
1466 safe = grabAndEraseSelection();
1469 if (array().size()) {
1470 // something left in the cell
1472 // cursor in first position
1474 } else if (pos() == array().size()) {
1475 // cursor in last position
1478 // cursor in between. split cell
1479 MathArray::iterator bt = array().begin();
1480 MathAtom at = createMathInset(font);
1481 at.nucleus()->cell(0) = MathArray(bt, bt + pos());
1482 cursor().cell().erase(bt, bt + pos());
1487 // nothing left in the cell
1495 void releaseMathCursor(BufferView * bv)
1498 InsetFormulaBase * f = mathcursor->formula();