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.
15 #include "support/limited_stack.h"
17 #include "support/std_sstream.h"
18 #include "math_cursor.h"
19 #include "formulabase.h"
20 #include "funcrequest.h"
21 #include "math_braceinset.h"
22 #include "math_commentinset.h"
23 #include "math_charinset.h"
24 #include "math_factory.h"
25 #include "math_gridinset.h"
26 #include "math_macroarg.h"
27 #include "math_macrotemplate.h"
28 #include "math_mathmlstream.h"
29 #include "math_scriptinset.h"
30 #include "math_spaceinset.h"
31 #include "math_support.h"
32 #include "math_unknowninset.h"
34 #include <boost/assert.hpp>
43 using std::ostringstream;
46 // matheds own cut buffer
47 limited_stack<string> theCutBuffer;
50 MathCursor::MathCursor(InsetFormulaBase * formula, bool front)
51 : formula_(formula), autocorrect_(false), selection_(false), targetx_(-1)
53 front ? first() : last();
58 MathCursor::~MathCursor()
60 // ensure that 'notifyCursorLeave' is called
66 void MathCursor::push(MathAtom & t)
68 Cursor_.push_back(CursorPos(t.nucleus()));
72 void MathCursor::pushLeft(MathAtom & t)
74 //lyxerr << "Entering atom " << t << " left" << endl;
76 t->idxFirst(idx(), pos());
80 void MathCursor::pushRight(MathAtom & t)
82 //lyxerr << "Entering atom " << t << " right" << endl;
85 t->idxLast(idx(), pos());
89 bool MathCursor::popLeft()
91 //lyxerr << "Leaving atom to the left" << endl;
94 inset()->notifyCursorLeaves(idx());
97 inset()->notifyCursorLeaves(idx());
103 bool MathCursor::popRight()
105 //lyxerr << "Leaving atom "; inset()->write(cerr, false); cerr << " right" << endl;
108 inset()->notifyCursorLeaves(idx());
111 inset()->notifyCursorLeaves(idx());
120 void MathCursor::dump(char const * what) const
122 lyxerr << "MC: " << what << endl;
123 lyxerr << " Cursor: " << depth() << endl;
124 for (unsigned i = 0; i < depth(); ++i)
125 lyxerr << " i: " << i << ' ' << Cursor_[i] << endl;
126 lyxerr << " Anchor: " << Anchor_.size() << endl;
127 for (unsigned i = 0; i < Anchor_.size(); ++i)
128 lyxerr << " i: " << i << ' ' << Anchor_[i] << endl;
129 lyxerr << " sel: " << selection_ << endl;
132 void MathCursor::dump(char const *) const {}
136 bool MathCursor::isInside(MathInset const * p) const
138 for (unsigned i = 0; i < depth(); ++i)
139 if (Cursor_[i].inset_ == p)
145 bool MathCursor::openable(MathAtom const & t, bool sel) const
154 // we can't move into anything new during selection
155 if (depth() == Anchor_.size())
157 if (t.operator->() != Anchor_[depth()].inset_)
164 bool MathCursor::inNucleus() const
166 return inset()->asScriptInset() && idx() == 2;
170 bool MathCursor::posLeft()
179 bool MathCursor::posRight()
188 bool MathCursor::left(bool sel)
191 autocorrect_ = false;
192 targetx_ = -1; // "no target"
199 if (hasPrevAtom() && openable(prevAtom(), sel)) {
200 pushRight(prevAtom());
204 return posLeft() || idxLeft() || popLeft() || selection_;
208 bool MathCursor::right(bool sel)
211 autocorrect_ = false;
212 targetx_ = -1; // "no target"
219 if (hasNextAtom() && openable(nextAtom(), sel)) {
220 pushLeft(nextAtom());
224 return posRight() || idxRight() || popRight() || selection_;
228 void MathCursor::first()
231 push(formula_->par());
232 inset()->idxFirst(idx(), pos());
236 void MathCursor::last()
239 push(formula_->par());
240 inset()->idxLast(idx(), pos());
245 (MathIterator const & cursor, MathIterator const & anchor)
247 // avoid deeper nested insets when selecting
248 if (cursor.size() > anchor.size())
251 // anchor might be deeper, should have same path then
252 for (MathIterator::size_type i = 0; i < cursor.size(); ++i)
253 if (cursor[i].inset_ != anchor[i].inset_)
256 // position should be ok.
261 void MathCursor::setPos(int x, int y)
264 bool res = bruteFind(x, y,
265 formula()->xlow(), formula()->xhigh(),
266 formula()->ylow(), formula()->yhigh());
268 // this can happen on creation of "math-display"
272 targetx_ = -1; // "no target"
278 bool MathCursor::home(bool sel)
281 autocorrect_ = false;
284 if (!inset()->idxHome(idx(), pos()))
287 targetx_ = -1; // "no target"
292 bool MathCursor::end(bool sel)
295 autocorrect_ = false;
298 if (!inset()->idxEnd(idx(), pos()))
301 targetx_ = -1; // "no target"
306 void MathCursor::plainErase()
308 array().erase(pos());
312 void MathCursor::markInsert()
314 //lyxerr << "inserting mark" << endl;
315 array().insert(pos(), MathAtom(new MathCharInset(0)));
319 void MathCursor::markErase()
321 //lyxerr << "deleting mark" << endl;
322 array().erase(pos());
326 void MathCursor::plainInsert(MathAtom const & t)
329 array().insert(pos(), t);
334 void MathCursor::insert2(string const & str)
342 void MathCursor::insert(string const & str)
344 //lyxerr << "inserting '" << str << "'" << endl;
346 for (string::const_iterator it = str.begin(); it != str.end(); ++it)
347 plainInsert(MathAtom(new MathCharInset(*it)));
351 void MathCursor::insert(char c)
353 //lyxerr << "inserting '" << c << "'" << endl;
355 plainInsert(MathAtom(new MathCharInset(c)));
359 void MathCursor::insert(MathAtom const & t)
367 void MathCursor::niceInsert(string const & t)
378 void MathCursor::niceInsert(MathAtom const & t)
381 string safe = grabAndEraseSelection();
383 // enter the new inset and move the contents of the selection if possible
386 pushLeft(nextAtom());
392 void MathCursor::insert(MathArray const & ar)
397 array().insert(pos(), ar);
402 void MathCursor::paste(string const & data)
404 dispatch(FuncRequest(LFUN_PASTE, data));
408 bool MathCursor::backspace()
410 autocorrect_ = false;
418 if (inset()->ncols() == 1 &&
419 inset()->nrows() == 1 &&
428 MathUnknownInset * p = activeMacro();
429 if (p->name().size() > 1) {
430 p->setName(p->name().substr(0, p->name().size() - 1));
441 bool MathCursor::erase()
443 autocorrect_ = false;
452 // delete empty cells if possible
454 if (inset()->idxDelete(idx()))
457 // old behaviour when in last position of cell
458 if (pos() == size()) {
459 if (inset()->ncols() == 1 && inset()->nrows() == 1 && depth() == 1 && size() == 0)
462 inset()->idxGlue(idx());
472 bool MathCursor::up(bool sel)
477 MathIterator save = Cursor_;
481 autocorrect_ = false;
486 bool MathCursor::down(bool sel)
491 MathIterator save = Cursor_;
495 autocorrect_ = false;
500 void MathCursor::macroModeClose()
504 MathUnknownInset * p = activeMacro();
506 string s = p->name();
508 array().erase(pos());
510 // do nothing if the macro name is empty
514 string const name = s.substr(1);
516 // prevent entering of recursive macros
517 if (formula()->lyxCode() == InsetOld::MATHMACRO_CODE
518 && formula()->getInsetName() == name)
519 lyxerr << "can't enter recursive macro" << endl;
521 niceInsert(createMathInset(name));
525 string MathCursor::macroName() const
527 return inMacroMode() ? activeMacro()->name() : string();
531 void MathCursor::selClear()
538 void MathCursor::selCopy()
542 theCutBuffer.push(grabSelection());
545 //theCutBuffer.erase();
550 void MathCursor::selCut()
553 theCutBuffer.push(grabAndEraseSelection());
557 void MathCursor::selDel()
567 void MathCursor::selPaste(size_t n)
571 if (n < theCutBuffer.size())
572 paste(theCutBuffer[n]);
578 void MathCursor::selHandle(bool sel)
580 if (sel == selection_)
588 void MathCursor::selStart()
598 void MathCursor::selClearOrDel()
600 if (lyxrc.auto_region_delete)
607 void MathCursor::drawSelection(PainterInfo & pi) const
613 getSelection(i1, i2);
614 i1.inset_->drawSelection(pi, i1.idx_, i1.pos_, i2.idx_, i2.pos_);
618 void MathCursor::handleNest(MathAtom const & a)
621 asArray(grabAndEraseSelection(), at.nucleus()->cell(0));
623 pushRight(prevAtom());
627 void MathCursor::getPos(int & x, int & y) const
629 inset()->getPos(idx(), pos(), x, y);
633 int MathCursor::targetX() const
643 MathInset * MathCursor::inset() const
645 return cursor().inset_;
649 InsetFormulaBase * MathCursor::formula() const
655 MathCursor::idx_type MathCursor::idx() const
657 return cursor().idx_;
661 MathCursor::idx_type & MathCursor::idx()
663 return cursor().idx_;
667 MathCursor::pos_type MathCursor::pos() const
669 return cursor().pos_;
673 void MathCursor::adjust(pos_type from, difference_type diff)
675 if (cursor().pos_ > from)
676 cursor().pos_ += diff;
677 if (Anchor_.back().pos_ > from)
678 Anchor_.back().pos_ += diff;
679 // just to be on the safe side
680 // theoretically unecessary
685 MathCursor::pos_type & MathCursor::pos()
687 return cursor().pos_;
691 bool MathCursor::inMacroMode() const
695 MathUnknownInset const * p = prevAtom()->asUnknownInset();
696 return p && !p->final();
700 MathUnknownInset * MathCursor::activeMacro()
702 return inMacroMode() ? prevAtom().nucleus()->asUnknownInset() : 0;
706 MathUnknownInset const * MathCursor::activeMacro() const
708 return inMacroMode() ? prevAtom()->asUnknownInset() : 0;
712 bool MathCursor::inMacroArgMode() const
714 return pos() > 0 && prevAtom()->getChar() == '#';
718 bool MathCursor::selection() const
724 MathGridInset * MathCursor::enclosingGrid(MathCursor::idx_type & idx) const
726 for (MathInset::difference_type i = depth() - 1; i >= 0; --i) {
727 MathGridInset * p = Cursor_[i].inset_->asGridInset();
729 idx = Cursor_[i].idx_;
737 void MathCursor::popToHere(MathInset const * p)
739 while (depth() && Cursor_.back().inset_ != p)
744 void MathCursor::popToEnclosingGrid()
746 while (depth() && !Cursor_.back().inset_->asGridInset())
751 void MathCursor::popToEnclosingHull()
753 while (depth() && !Cursor_.back().inset_->asHullInset())
758 void MathCursor::pullArg()
761 MathArray a = array();
764 array().insert(pos(), a);
767 formula()->mutateToText();
772 void MathCursor::touch()
774 MathIterator::const_iterator it = Cursor_.begin();
775 MathIterator::const_iterator et = Cursor_.end();
776 for ( ; it != et; ++it)
781 void MathCursor::normalize()
783 if (idx() >= inset()->nargs()) {
784 lyxerr << "this should not really happen - 1: "
785 << idx() << ' ' << inset()->nargs()
786 << " in: " << inset() << endl;
789 idx() = min(idx(), inset()->nargs() - 1);
791 if (pos() > size()) {
792 lyxerr << "this should not really happen - 2: "
793 << pos() << ' ' << size() << " in idx: " << idx()
795 WriteStream wi(lyxerr, false, true);
800 pos() = min(pos(), size());
804 MathCursor::size_type MathCursor::size() const
806 return array().size();
810 bool MathCursor::hasPrevAtom() const
816 bool MathCursor::hasNextAtom() const
818 return pos() < size();
822 MathAtom const & MathCursor::prevAtom() const
824 BOOST_ASSERT(pos() > 0);
825 return array()[pos() - 1];
829 MathAtom & MathCursor::prevAtom()
831 BOOST_ASSERT(pos() > 0);
832 return array()[pos() - 1];
836 MathAtom const & MathCursor::nextAtom() const
838 BOOST_ASSERT(pos() < size());
839 return array()[pos()];
843 MathAtom & MathCursor::nextAtom()
845 BOOST_ASSERT(pos() < size());
846 return array()[pos()];
850 MathArray & MathCursor::array() const
852 static MathArray dummy;
854 if (idx() >= inset()->nargs()) {
855 lyxerr << "############ idx_ " << idx() << " not valid" << endl;
860 lyxerr << "############ depth() == 0 not valid" << endl;
864 return cursor().cell();
868 void MathCursor::idxNext()
870 inset()->idxNext(idx(), pos());
874 void MathCursor::idxPrev()
876 inset()->idxPrev(idx(), pos());
880 char MathCursor::valign() const
883 MathGridInset * p = enclosingGrid(idx);
884 return p ? p->valign() : '\0';
888 char MathCursor::halign() const
891 MathGridInset * p = enclosingGrid(idx);
892 return p ? p->halign(idx % p->ncols()) : '\0';
896 void MathCursor::getSelection(CursorPos & i1, CursorPos & i2) const
898 CursorPos anc = normalAnchor();
899 if (anc < cursor()) {
909 CursorPos & MathCursor::cursor()
911 BOOST_ASSERT(depth());
912 return Cursor_.back();
916 CursorPos const & MathCursor::cursor() const
918 BOOST_ASSERT(depth());
919 return Cursor_.back();
923 bool MathCursor::goUpDown(bool up)
925 // Be warned: The 'logic' implemented in this function is highly fragile.
926 // A distance of one pixel or a '<' vs '<=' _really_ matters.
927 // So fiddle around with it only if you know what you are doing!
932 // check if we had something else in mind, if not, this is the future goal
938 // try neigbouring script insets
942 MathScriptInset const * p = prevAtom()->asScriptInset();
943 if (p && p->has(up)) {
946 idx() = up; // the superscript has index 1
948 //lyxerr << "updown: handled by scriptinset to the left" << endl;
955 MathScriptInset const * p = nextAtom()->asScriptInset();
956 if (p && p->has(up)) {
960 //lyxerr << "updown: handled by scriptinset to the right" << endl;
966 // try current cell for e.g. text insets
967 if (inset()->idxUpDown2(idx(), pos(), up, targetx_))
970 //xarray().boundingBox(xlow, xhigh, ylow, yhigh);
975 //if (bruteFind(xo, yo, xlow, xhigh, ylow, yhigh)) {
976 // lyxerr << "updown: handled by brute find in the same cell" << endl;
980 // try to find an inset that knows better then we
982 //lyxerr << "updown: We are in " << inset() << " idx: " << idx() << endl;
984 if (inset()->idxUpDown(idx(), pos(), up, targetx_)) {
985 // try to find best position within this inset
991 // no such inset found, just take something "above"
992 //lyxerr << "updown: handled by strange case" << endl;
998 up ? formula()->ylow() : yo + 4,
999 up ? yo - 4 : formula()->yhigh()
1002 // any improvement so far?
1005 if (up ? ynew < yo : ynew > yo)
1011 bool MathCursor::bruteFind
1012 (int x, int y, int xlow, int xhigh, int ylow, int yhigh)
1014 MathIterator best_cursor;
1015 double best_dist = 1e10;
1017 MathIterator it = ibegin(formula()->par().nucleus());
1018 MathIterator et = iend(formula()->par().nucleus());
1020 // avoid invalid nesting when selecting
1021 if (!selection_ || positionable(it, Anchor_)) {
1023 it.back().getPos(xo, yo);
1024 if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
1025 double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
1026 //lyxerr << "x: " << x << " y: " << y << " d: " << endl;
1027 // '<=' in order to take the last possible position
1028 // this is important for clicking behind \sum in e.g. '\sum_i a'
1029 if (d <= best_dist) {
1041 if (best_dist < 1e10)
1042 Cursor_ = best_cursor;
1043 return best_dist < 1e10;
1047 void MathCursor::bruteFind2(int x, int y)
1049 double best_dist = 1e10;
1051 MathIterator it = Cursor_;
1052 it.back().setPos(0);
1053 MathIterator et = Cursor_;
1054 et.back().setPos(it.cell().size());
1055 for (int i = 0; ; ++i) {
1057 it.back().getPos(xo, yo);
1058 double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
1059 // '<=' in order to take the last possible position
1060 // this is important for clicking behind \sum in e.g. '\sum_i a'
1061 lyxerr << "i: " << i << " d: " << d << " best: " << best_dist << endl;
1062 if (d <= best_dist) {
1073 bool MathCursor::idxLineLast()
1075 idx() -= idx() % inset()->ncols();
1076 idx() += inset()->ncols() - 1;
1081 bool MathCursor::idxLeft()
1083 return inset()->idxLeft(idx(), pos());
1087 bool MathCursor::idxRight()
1089 return inset()->idxRight(idx(), pos());
1093 bool MathCursor::script(bool up)
1095 // Hack to get \\^ and \\_ working
1096 if (inMacroMode() && macroName() == "\\") {
1098 niceInsert(createMathInset("mathcircumflex"));
1105 string safe = grabAndEraseSelection();
1107 // we are in a nucleus of a script inset, move to _our_ script
1108 inset()->asScriptInset()->ensure(up);
1111 } else if (hasPrevAtom() && prevAtom()->asScriptInset()) {
1112 prevAtom().nucleus()->asScriptInset()->ensure(up);
1113 pushRight(prevAtom());
1116 } else if (hasPrevAtom()) {
1118 array()[pos()] = MathAtom(new MathScriptInset(nextAtom(), up));
1119 pushLeft(nextAtom());
1123 plainInsert(MathAtom(new MathScriptInset(up)));
1124 prevAtom().nucleus()->asScriptInset()->ensure(up);
1125 pushRight(prevAtom());
1135 bool MathCursor::interpret(char c)
1137 //lyxerr << "interpret 2: '" << c << "'" << endl;
1138 targetx_ = -1; // "no target"
1139 if (inMacroArgMode()) {
1143 MathMacroTemplate const * p = formula()->par()->asMacroTemplate();
1144 if (p && 1 <= n && n <= p->numargs())
1145 insert(MathAtom(new MathMacroArgument(c - '0')));
1147 insert(createMathInset("#"));
1148 interpret(c); // try again
1154 if (inMacroMode()) {
1155 string name = macroName();
1156 //lyxerr << "interpret name: '" << name << "'" << endl;
1159 activeMacro()->setName(activeMacro()->name() + c);
1163 // handle 'special char' macros
1168 if (currentMode() == MathInset::TEXT_MODE)
1169 niceInsert(createMathInset("textbackslash"));
1171 niceInsert(createMathInset("backslash"));
1172 } else if (c == '{') {
1173 niceInsert(MathAtom(new MathBraceInset));
1175 niceInsert(createMathInset(string(1, c)));
1180 // leave macro mode and try again if necessary
1183 niceInsert(MathAtom(new MathBraceInset));
1189 // This is annoying as one has to press <space> far too often.
1193 // leave autocorrect mode if necessary
1194 if (autocorrect_ && c == ' ') {
1195 autocorrect_ = false;
1200 // just clear selection on pressing the space bar
1201 if (selection_ && c == ' ') {
1209 //lyxerr << "starting with macro" << endl;
1210 insert(MathAtom(new MathUnknownInset("\\", false)));
1215 if (currentMode() == MathInset::TEXT_MODE)
1221 if (currentMode() == MathInset::TEXT_MODE) {
1222 // insert spaces in text mode,
1223 // but suppress direct insertion of two spaces in a row
1224 // the still allows typing '<space>a<space>' and deleting the 'a', but
1225 // it is better than nothing...
1226 if (!hasPrevAtom() || prevAtom()->getChar() != ' ')
1230 if (hasPrevAtom() && prevAtom()->asSpaceInset()) {
1231 prevAtom().nucleus()->asSpaceInset()->incSpace();
1236 // if are at the very end, leave the formula
1237 return pos() != size();
1240 if (c == '{' || c == '}' || c == '#' || c == '&' || c == '$') {
1241 createMathInset(string(1, c));
1246 niceInsert(MathAtom(new MathCommentInset));
1250 // try auto-correction
1251 //if (autocorrect_ && hasPrevAtom() && math_autocorrect(prevAtom(), c))
1254 // no special circumstances, so insert the character without any fuss
1256 autocorrect_ = true;
1261 void MathCursor::setSelection(MathIterator const & where, size_type n)
1270 void MathCursor::insetToggle()
1272 if (hasNextAtom()) {
1273 // toggle previous inset ...
1274 nextAtom().nucleus()->lock(!nextAtom()->lock());
1275 } else if (popLeft() && hasNextAtom()) {
1276 // ... or enclosing inset if we are in the last inset position
1277 nextAtom().nucleus()->lock(!nextAtom()->lock());
1283 string MathCursor::info() const
1286 os << "Math editor mode. ";
1287 for (int i = 0, n = depth(); i < n; ++i) {
1288 Cursor_[i].inset_->infoize(os);
1292 prevAtom()->infoize2(os);
1298 unsigned MathCursor::depth() const
1300 return Cursor_.size();
1308 void region(CursorPos const & i1, CursorPos const & i2,
1309 MathInset::row_type & r1, MathInset::row_type & r2,
1310 MathInset::col_type & c1, MathInset::col_type & c2)
1312 MathInset * p = i1.inset_;
1313 c1 = p->col(i1.idx_);
1314 c2 = p->col(i2.idx_);
1317 r1 = p->row(i1.idx_);
1318 r2 = p->row(i2.idx_);
1326 string MathCursor::grabSelection() const
1333 getSelection(i1, i2);
1335 if (i1.idx_ == i2.idx_) {
1336 MathArray::const_iterator it = i1.cell().begin();
1337 return asString(MathArray(it + i1.pos_, it + i2.pos_));
1342 region(i1, i2, r1, r2, c1, c2);
1345 for (row_type row = r1; row <= r2; ++row) {
1348 for (col_type col = c1; col <= c2; ++col) {
1351 data += asString(i1.inset_->cell(i1.inset_->index(row, col)));
1358 void MathCursor::eraseSelection()
1362 getSelection(i1, i2);
1363 if (i1.idx_ == i2.idx_)
1364 i1.cell().erase(i1.pos_, i2.pos_);
1366 MathInset * p = i1.inset_;
1369 region(i1, i2, r1, r2, c1, c2);
1370 for (row_type row = r1; row <= r2; ++row)
1371 for (col_type col = c1; col <= c2; ++col)
1372 p->cell(p->index(row, col)).clear();
1378 string MathCursor::grabAndEraseSelection()
1382 string res = grabSelection();
1389 CursorPos MathCursor::normalAnchor() const
1391 if (Anchor_.size() < depth()) {
1393 lyxerr << "unusual Anchor size" << endl;
1395 //lyx::BOOST_ASSERT(Anchor_.size() >= cursor.depth());
1396 // use Anchor on the same level as Cursor
1397 CursorPos normal = Anchor_[depth() - 1];
1398 if (depth() < Anchor_.size() && !(normal < cursor())) {
1399 // anchor is behind cursor -> move anchor behind the inset
1406 dispatch_result MathCursor::dispatch(FuncRequest const & cmd)
1408 // mouse clicks are somewhat special
1410 switch (cmd.action) {
1411 case LFUN_MOUSE_PRESS:
1412 case LFUN_MOUSE_MOTION:
1413 case LFUN_MOUSE_RELEASE:
1414 case LFUN_MOUSE_DOUBLE: {
1415 CursorPos & pos = Cursor_.back();
1416 dispatch_result res = UNDISPATCHED;
1419 if (x < cmd.x && hasPrevAtom()) {
1420 res = prevAtom().nucleus()->dispatch(cmd, pos.idx_, pos.pos_);
1421 if (res != UNDISPATCHED)
1424 if (x > cmd.x && hasNextAtom()) {
1425 res = nextAtom().nucleus()->dispatch(cmd, pos.idx_, pos.pos_);
1426 if (res != UNDISPATCHED)
1434 for (int i = Cursor_.size() - 1; i >= 0; --i) {
1435 CursorPos & pos = Cursor_[i];
1436 dispatch_result res = pos.inset_->dispatch(cmd, pos.idx_, pos.pos_);
1437 if (res != UNDISPATCHED) {
1438 if (res == DISPATCHED_POP) {
1439 Cursor_.shrink(i + 1);
1445 return UNDISPATCHED;
1449 MathInset::mode_type MathCursor::currentMode() const
1451 for (int i = Cursor_.size() - 1; i >= 0; --i) {
1452 MathInset::mode_type res = Cursor_[i].inset_->currentMode();
1453 if (res != MathInset::UNDECIDED_MODE)
1456 return MathInset::UNDECIDED_MODE;
1460 void MathCursor::handleFont(string const & font)
1465 safe = grabAndEraseSelection();
1468 if (array().size()) {
1469 // something left in the cell
1471 // cursor in first position
1473 } else if (pos() == array().size()) {
1474 // cursor in last position
1477 // cursor in between. split cell
1478 MathArray::iterator bt = array().begin();
1479 MathAtom at = createMathInset(font);
1480 at.nucleus()->cell(0) = MathArray(bt, bt + pos());
1481 cursor().cell().erase(bt, bt + pos());
1486 // nothing left in the cell
1494 void releaseMathCursor(BufferView * bv)
1497 InsetFormulaBase * f = mathcursor->formula();