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>
39 #ifndef CXX_GLOBAL_CSTD
45 using std::ostringstream;
48 // matheds own cut buffer
49 limited_stack<string> theCutBuffer;
52 MathCursor::MathCursor(InsetFormulaBase * formula, bool front)
53 : formula_(formula), autocorrect_(false), selection_(false), targetx_(-1)
55 front ? first() : last();
60 MathCursor::~MathCursor()
62 // ensure that 'notifyCursorLeave' is called
68 void MathCursor::push(MathAtom & t)
70 Cursor_.push_back(CursorPos(t.nucleus()));
74 void MathCursor::pushLeft(MathAtom & t)
76 //lyxerr << "Entering atom " << t << " left" << endl;
78 t->idxFirst(idx(), pos());
82 void MathCursor::pushRight(MathAtom & t)
84 //lyxerr << "Entering atom " << t << " right" << endl;
87 t->idxLast(idx(), pos());
91 bool MathCursor::popLeft()
93 //lyxerr << "Leaving atom to the left" << endl;
96 inset()->notifyCursorLeaves(idx());
99 inset()->notifyCursorLeaves(idx());
105 bool MathCursor::popRight()
107 //lyxerr << "Leaving atom "; inset()->write(cerr, false); cerr << " right" << endl;
110 inset()->notifyCursorLeaves(idx());
113 inset()->notifyCursorLeaves(idx());
122 void MathCursor::dump(char const * what) const
124 lyxerr << "MC: " << what << endl;
125 lyxerr << " Cursor: " << depth() << endl;
126 for (unsigned i = 0; i < depth(); ++i)
127 lyxerr << " i: " << i << ' ' << Cursor_[i] << endl;
128 lyxerr << " Anchor: " << Anchor_.size() << endl;
129 for (unsigned i = 0; i < Anchor_.size(); ++i)
130 lyxerr << " i: " << i << ' ' << Anchor_[i] << endl;
131 lyxerr << " sel: " << selection_ << endl;
134 void MathCursor::dump(char const *) const {}
138 bool MathCursor::isInside(MathInset const * p) const
140 for (unsigned i = 0; i < depth(); ++i)
141 if (Cursor_[i].inset_ == p)
147 bool MathCursor::openable(MathAtom const & t, bool sel) const
156 // we can't move into anything new during selection
157 if (depth() == Anchor_.size())
159 if (t.operator->() != Anchor_[depth()].inset_)
166 bool MathCursor::inNucleus() const
168 return inset()->asScriptInset() && idx() == 2;
172 bool MathCursor::posLeft()
181 bool MathCursor::posRight()
190 bool MathCursor::left(bool sel)
193 autocorrect_ = false;
194 targetx_ = -1; // "no target"
201 if (hasPrevAtom() && openable(prevAtom(), sel)) {
202 pushRight(prevAtom());
206 return posLeft() || idxLeft() || popLeft() || selection_;
210 bool MathCursor::right(bool sel)
213 autocorrect_ = false;
214 targetx_ = -1; // "no target"
221 if (hasNextAtom() && openable(nextAtom(), sel)) {
222 pushLeft(nextAtom());
226 return posRight() || idxRight() || popRight() || selection_;
230 void MathCursor::first()
233 push(formula_->par());
234 inset()->idxFirst(idx(), pos());
238 void MathCursor::last()
241 push(formula_->par());
242 inset()->idxLast(idx(), pos());
247 (MathIterator const & cursor, MathIterator const & anchor)
249 // avoid deeper nested insets when selecting
250 if (cursor.size() > anchor.size())
253 // anchor might be deeper, should have same path then
254 for (MathIterator::size_type i = 0; i < cursor.size(); ++i)
255 if (cursor[i].inset_ != anchor[i].inset_)
258 // position should be ok.
263 void MathCursor::setPos(int x, int y)
266 bool res = bruteFind(x, y,
267 formula()->xlow(), formula()->xhigh(),
268 formula()->ylow(), formula()->yhigh());
270 // this can happen on creation of "math-display"
274 targetx_ = -1; // "no target"
280 bool MathCursor::home(bool sel)
283 autocorrect_ = false;
286 if (!inset()->idxHome(idx(), pos()))
289 targetx_ = -1; // "no target"
294 bool MathCursor::end(bool sel)
297 autocorrect_ = false;
300 if (!inset()->idxEnd(idx(), pos()))
303 targetx_ = -1; // "no target"
308 void MathCursor::plainErase()
310 array().erase(pos());
314 void MathCursor::markInsert()
316 //lyxerr << "inserting mark" << endl;
317 array().insert(pos(), MathAtom(new MathCharInset(0)));
321 void MathCursor::markErase()
323 //lyxerr << "deleting mark" << endl;
324 array().erase(pos());
328 void MathCursor::plainInsert(MathAtom const & t)
331 array().insert(pos(), t);
336 void MathCursor::insert2(string const & str)
344 void MathCursor::insert(string const & str)
346 //lyxerr << "inserting '" << str << "'" << endl;
348 for (string::const_iterator it = str.begin(); it != str.end(); ++it)
349 plainInsert(MathAtom(new MathCharInset(*it)));
353 void MathCursor::insert(char c)
355 //lyxerr << "inserting '" << c << "'" << endl;
357 plainInsert(MathAtom(new MathCharInset(c)));
361 void MathCursor::insert(MathAtom const & t)
369 void MathCursor::niceInsert(string const & t)
380 void MathCursor::niceInsert(MathAtom const & t)
383 string safe = grabAndEraseSelection();
385 // enter the new inset and move the contents of the selection if possible
388 pushLeft(nextAtom());
394 void MathCursor::insert(MathArray const & ar)
399 array().insert(pos(), ar);
404 void MathCursor::paste(string const & data)
406 dispatch(FuncRequest(LFUN_PASTE, data));
410 bool MathCursor::backspace()
412 autocorrect_ = false;
420 if (inset()->ncols() == 1 &&
421 inset()->nrows() == 1 &&
430 MathUnknownInset * p = activeMacro();
431 if (p->name().size() > 1) {
432 p->setName(p->name().substr(0, p->name().size() - 1));
443 bool MathCursor::erase()
445 autocorrect_ = false;
454 // delete empty cells if possible
456 if (inset()->idxDelete(idx()))
459 // old behaviour when in last position of cell
460 if (pos() == size()) {
461 if (inset()->ncols() == 1 && inset()->nrows() == 1 && depth() == 1 && size() == 0)
464 inset()->idxGlue(idx());
474 bool MathCursor::up(bool sel)
479 MathIterator save = Cursor_;
483 autocorrect_ = false;
488 bool MathCursor::down(bool sel)
493 MathIterator save = Cursor_;
497 autocorrect_ = false;
502 void MathCursor::macroModeClose()
506 MathUnknownInset * p = activeMacro();
508 string s = p->name();
510 array().erase(pos());
512 // do nothing if the macro name is empty
516 string const name = s.substr(1);
518 // prevent entering of recursive macros
519 if (formula()->lyxCode() == InsetOld::MATHMACRO_CODE
520 && formula()->getInsetName() == name)
521 lyxerr << "can't enter recursive macro" << endl;
523 niceInsert(createMathInset(name));
527 string MathCursor::macroName() const
529 return inMacroMode() ? activeMacro()->name() : string();
533 void MathCursor::selClear()
540 void MathCursor::selCopy()
544 theCutBuffer.push(grabSelection());
547 //theCutBuffer.erase();
552 void MathCursor::selCut()
555 theCutBuffer.push(grabAndEraseSelection());
559 void MathCursor::selDel()
569 void MathCursor::selPaste(size_t n)
573 if (n < theCutBuffer.size())
574 paste(theCutBuffer[n]);
580 void MathCursor::selHandle(bool sel)
582 if (sel == selection_)
590 void MathCursor::selStart()
600 void MathCursor::selClearOrDel()
602 if (lyxrc.auto_region_delete)
609 void MathCursor::drawSelection(PainterInfo & pi) const
615 getSelection(i1, i2);
616 i1.inset_->drawSelection(pi, i1.idx_, i1.pos_, i2.idx_, i2.pos_);
620 void MathCursor::handleNest(MathAtom const & a, int c)
623 asArray(grabAndEraseSelection(), at.nucleus()->cell(c));
625 pushRight(prevAtom());
629 void MathCursor::getPos(int & x, int & y) const
631 inset()->getPos(idx(), pos(), x, y);
635 int MathCursor::targetX() const
645 MathInset * MathCursor::inset() const
647 return cursor().inset_;
651 InsetFormulaBase * MathCursor::formula() const
657 MathCursor::idx_type MathCursor::idx() const
659 return cursor().idx_;
663 MathCursor::idx_type & MathCursor::idx()
665 return cursor().idx_;
669 MathCursor::pos_type MathCursor::pos() const
671 return cursor().pos_;
675 void MathCursor::adjust(pos_type from, difference_type diff)
677 if (cursor().pos_ > from)
678 cursor().pos_ += diff;
679 if (Anchor_.back().pos_ > from)
680 Anchor_.back().pos_ += diff;
681 // just to be on the safe side
682 // theoretically unecessary
687 MathCursor::pos_type & MathCursor::pos()
689 return cursor().pos_;
693 bool MathCursor::inMacroMode() const
697 MathUnknownInset const * p = prevAtom()->asUnknownInset();
698 return p && !p->final();
702 MathUnknownInset * MathCursor::activeMacro()
704 return inMacroMode() ? prevAtom().nucleus()->asUnknownInset() : 0;
708 MathUnknownInset const * MathCursor::activeMacro() const
710 return inMacroMode() ? prevAtom()->asUnknownInset() : 0;
714 bool MathCursor::inMacroArgMode() const
716 return pos() > 0 && prevAtom()->getChar() == '#';
720 bool MathCursor::selection() const
726 MathGridInset * MathCursor::enclosingGrid(MathCursor::idx_type & idx) const
728 for (MathInset::difference_type i = depth() - 1; i >= 0; --i) {
729 MathGridInset * p = Cursor_[i].inset_->asGridInset();
731 idx = Cursor_[i].idx_;
739 void MathCursor::popToHere(MathInset const * p)
741 while (depth() && Cursor_.back().inset_ != p)
746 void MathCursor::popToEnclosingGrid()
748 while (depth() && !Cursor_.back().inset_->asGridInset())
753 void MathCursor::popToEnclosingHull()
755 while (depth() && !Cursor_.back().inset_->asHullInset())
760 void MathCursor::pullArg()
763 MathArray a = array();
766 array().insert(pos(), a);
769 formula()->mutateToText();
774 void MathCursor::touch()
776 MathIterator::const_iterator it = Cursor_.begin();
777 MathIterator::const_iterator et = Cursor_.end();
778 for ( ; it != et; ++it)
783 void MathCursor::normalize()
785 if (idx() >= inset()->nargs()) {
786 lyxerr << "this should not really happen - 1: "
787 << idx() << ' ' << inset()->nargs()
788 << " in: " << inset() << endl;
791 idx() = min(idx(), inset()->nargs() - 1);
793 if (pos() > size()) {
794 lyxerr << "this should not really happen - 2: "
795 << pos() << ' ' << size() << " in idx: " << idx()
797 WriteStream wi(lyxerr, false, true);
802 pos() = min(pos(), size());
806 MathCursor::size_type MathCursor::size() const
808 return array().size();
812 bool MathCursor::hasPrevAtom() const
818 bool MathCursor::hasNextAtom() const
820 return pos() < size();
824 MathAtom const & MathCursor::prevAtom() const
826 BOOST_ASSERT(pos() > 0);
827 return array()[pos() - 1];
831 MathAtom & MathCursor::prevAtom()
833 BOOST_ASSERT(pos() > 0);
834 return array()[pos() - 1];
838 MathAtom const & MathCursor::nextAtom() const
840 BOOST_ASSERT(pos() < size());
841 return array()[pos()];
845 MathAtom & MathCursor::nextAtom()
847 BOOST_ASSERT(pos() < size());
848 return array()[pos()];
852 MathArray & MathCursor::array() const
854 static MathArray dummy;
856 if (idx() >= inset()->nargs()) {
857 lyxerr << "############ idx_ " << idx() << " not valid" << endl;
862 lyxerr << "############ depth() == 0 not valid" << endl;
866 return cursor().cell();
870 void MathCursor::idxNext()
872 inset()->idxNext(idx(), pos());
876 void MathCursor::idxPrev()
878 inset()->idxPrev(idx(), pos());
882 char MathCursor::valign() const
885 MathGridInset * p = enclosingGrid(idx);
886 return p ? p->valign() : '\0';
890 char MathCursor::halign() const
893 MathGridInset * p = enclosingGrid(idx);
894 return p ? p->halign(idx % p->ncols()) : '\0';
898 void MathCursor::getSelection(CursorPos & i1, CursorPos & i2) const
900 CursorPos anc = normalAnchor();
901 if (anc < cursor()) {
911 CursorPos & MathCursor::cursor()
913 BOOST_ASSERT(depth());
914 return Cursor_.back();
918 CursorPos const & MathCursor::cursor() const
920 BOOST_ASSERT(depth());
921 return Cursor_.back();
925 bool MathCursor::goUpDown(bool up)
927 // Be warned: The 'logic' implemented in this function is highly fragile.
928 // A distance of one pixel or a '<' vs '<=' _really_ matters.
929 // So fiddle around with it only if you know what you are doing!
934 // check if we had something else in mind, if not, this is the future goal
940 // 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;
968 // try current cell for e.g. text insets
969 if (inset()->idxUpDown2(idx(), pos(), up, targetx_))
972 //xarray().boundingBox(xlow, xhigh, ylow, yhigh);
977 //if (bruteFind(xo, yo, xlow, xhigh, ylow, yhigh)) {
978 // lyxerr << "updown: handled by brute find in the same cell" << endl;
982 // try to find an inset that knows better then we
984 //lyxerr << "updown: We are in " << inset() << " idx: " << idx() << endl;
986 if (inset()->idxUpDown(idx(), pos(), up, targetx_)) {
987 // try to find best position within this inset
993 // no such inset found, just take something "above"
994 //lyxerr << "updown: handled by strange case" << endl;
1000 up ? formula()->ylow() : yo + 4,
1001 up ? yo - 4 : formula()->yhigh()
1004 // any improvement so far?
1007 if (up ? ynew < yo : ynew > yo)
1013 bool MathCursor::bruteFind
1014 (int x, int y, int xlow, int xhigh, int ylow, int yhigh)
1016 MathIterator best_cursor;
1017 double best_dist = 1e10;
1019 MathIterator it = ibegin(formula()->par().nucleus());
1020 MathIterator et = iend(formula()->par().nucleus());
1022 // avoid invalid nesting when selecting
1023 if (!selection_ || positionable(it, Anchor_)) {
1025 it.back().getPos(xo, yo);
1026 if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
1027 double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
1028 //lyxerr << "x: " << x << " y: " << y << " d: " << endl;
1029 // '<=' in order to take the last possible position
1030 // this is important for clicking behind \sum in e.g. '\sum_i a'
1031 if (d <= best_dist) {
1043 if (best_dist < 1e10)
1044 Cursor_ = best_cursor;
1045 return best_dist < 1e10;
1049 void MathCursor::bruteFind2(int x, int y)
1051 double best_dist = 1e10;
1053 MathIterator it = Cursor_;
1054 it.back().setPos(0);
1055 MathIterator et = Cursor_;
1056 et.back().setPos(it.cell().size());
1057 for (int i = 0; ; ++i) {
1059 it.back().getPos(xo, yo);
1060 double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
1061 // '<=' in order to take the last possible position
1062 // this is important for clicking behind \sum in e.g. '\sum_i a'
1063 lyxerr << "i: " << i << " d: " << d << " best: " << best_dist << endl;
1064 if (d <= best_dist) {
1075 bool MathCursor::idxLineLast()
1077 idx() -= idx() % inset()->ncols();
1078 idx() += inset()->ncols() - 1;
1083 bool MathCursor::idxLeft()
1085 return inset()->idxLeft(idx(), pos());
1089 bool MathCursor::idxRight()
1091 return inset()->idxRight(idx(), pos());
1095 bool MathCursor::script(bool up)
1097 // Hack to get \\^ and \\_ working
1098 if (inMacroMode() && macroName() == "\\") {
1100 niceInsert(createMathInset("mathcircumflex"));
1107 string safe = grabAndEraseSelection();
1109 // we are in a nucleus of a script inset, move to _our_ script
1110 inset()->asScriptInset()->ensure(up);
1113 } else if (hasPrevAtom() && prevAtom()->asScriptInset()) {
1114 prevAtom().nucleus()->asScriptInset()->ensure(up);
1115 pushRight(prevAtom());
1118 } else if (hasPrevAtom()) {
1120 array()[pos()] = MathAtom(new MathScriptInset(nextAtom(), up));
1121 pushLeft(nextAtom());
1125 plainInsert(MathAtom(new MathScriptInset(up)));
1126 prevAtom().nucleus()->asScriptInset()->ensure(up);
1127 pushRight(prevAtom());
1137 bool MathCursor::interpret(char c)
1139 //lyxerr << "interpret 2: '" << c << "'" << endl;
1140 targetx_ = -1; // "no target"
1141 if (inMacroArgMode()) {
1145 MathMacroTemplate const * p = formula()->par()->asMacroTemplate();
1146 if (p && 1 <= n && n <= p->numargs())
1147 insert(MathAtom(new MathMacroArgument(c - '0')));
1149 insert(createMathInset("#"));
1150 interpret(c); // try again
1156 if (inMacroMode()) {
1157 string name = macroName();
1158 //lyxerr << "interpret name: '" << name << "'" << endl;
1161 activeMacro()->setName(activeMacro()->name() + c);
1165 // handle 'special char' macros
1170 if (currentMode() == MathInset::TEXT_MODE)
1171 niceInsert(createMathInset("textbackslash"));
1173 niceInsert(createMathInset("backslash"));
1174 } else if (c == '{') {
1175 niceInsert(MathAtom(new MathBraceInset));
1177 niceInsert(createMathInset(string(1, c)));
1182 // leave macro mode and try again if necessary
1185 niceInsert(MathAtom(new MathBraceInset));
1191 // This is annoying as one has to press <space> far too often.
1195 // leave autocorrect mode if necessary
1196 if (autocorrect_ && c == ' ') {
1197 autocorrect_ = false;
1202 // just clear selection on pressing the space bar
1203 if (selection_ && c == ' ') {
1211 //lyxerr << "starting with macro" << endl;
1212 insert(MathAtom(new MathUnknownInset("\\", false)));
1217 if (currentMode() == MathInset::TEXT_MODE)
1223 if (currentMode() == MathInset::TEXT_MODE) {
1224 // insert spaces in text mode,
1225 // but suppress direct insertion of two spaces in a row
1226 // the still allows typing '<space>a<space>' and deleting the 'a', but
1227 // it is better than nothing...
1228 if (!hasPrevAtom() || prevAtom()->getChar() != ' ')
1232 if (hasPrevAtom() && prevAtom()->asSpaceInset()) {
1233 prevAtom().nucleus()->asSpaceInset()->incSpace();
1238 // if are at the very end, leave the formula
1239 return pos() != size();
1242 if (c == '{' || c == '}' || c == '#' || c == '&' || c == '$') {
1243 niceInsert(createMathInset(string(1, c)));
1248 niceInsert(MathAtom(new MathCommentInset));
1252 // try auto-correction
1253 //if (autocorrect_ && hasPrevAtom() && math_autocorrect(prevAtom(), c))
1256 // no special circumstances, so insert the character without any fuss
1258 autocorrect_ = true;
1263 void MathCursor::setSelection(MathIterator const & where, size_type n)
1272 void MathCursor::insetToggle()
1274 if (hasNextAtom()) {
1275 // toggle previous inset ...
1276 nextAtom().nucleus()->lock(!nextAtom()->lock());
1277 } else if (popLeft() && hasNextAtom()) {
1278 // ... or enclosing inset if we are in the last inset position
1279 nextAtom().nucleus()->lock(!nextAtom()->lock());
1285 string MathCursor::info() const
1288 os << "Math editor mode. ";
1289 for (int i = 0, n = depth(); i < n; ++i) {
1290 Cursor_[i].inset_->infoize(os);
1294 prevAtom()->infoize2(os);
1300 unsigned MathCursor::depth() const
1302 return Cursor_.size();
1310 void region(CursorPos const & i1, CursorPos const & i2,
1311 MathInset::row_type & r1, MathInset::row_type & r2,
1312 MathInset::col_type & c1, MathInset::col_type & c2)
1314 MathInset * p = i1.inset_;
1315 c1 = p->col(i1.idx_);
1316 c2 = p->col(i2.idx_);
1319 r1 = p->row(i1.idx_);
1320 r2 = p->row(i2.idx_);
1328 string MathCursor::grabSelection() const
1335 getSelection(i1, i2);
1337 if (i1.idx_ == i2.idx_) {
1338 MathArray::const_iterator it = i1.cell().begin();
1339 return asString(MathArray(it + i1.pos_, it + i2.pos_));
1344 region(i1, i2, r1, r2, c1, c2);
1347 for (row_type row = r1; row <= r2; ++row) {
1350 for (col_type col = c1; col <= c2; ++col) {
1353 data += asString(i1.inset_->cell(i1.inset_->index(row, col)));
1360 void MathCursor::eraseSelection()
1364 getSelection(i1, i2);
1365 if (i1.idx_ == i2.idx_)
1366 i1.cell().erase(i1.pos_, i2.pos_);
1368 MathInset * p = i1.inset_;
1371 region(i1, i2, r1, r2, c1, c2);
1372 for (row_type row = r1; row <= r2; ++row)
1373 for (col_type col = c1; col <= c2; ++col)
1374 p->cell(p->index(row, col)).clear();
1380 string MathCursor::grabAndEraseSelection()
1384 string res = grabSelection();
1391 CursorPos MathCursor::normalAnchor() const
1393 if (Anchor_.size() < depth()) {
1395 lyxerr << "unusual Anchor size" << endl;
1397 //lyx::BOOST_ASSERT(Anchor_.size() >= cursor.depth());
1398 // use Anchor on the same level as Cursor
1399 CursorPos normal = Anchor_[depth() - 1];
1400 if (depth() < Anchor_.size() && !(normal < cursor())) {
1401 // anchor is behind cursor -> move anchor behind the inset
1408 dispatch_result MathCursor::dispatch(FuncRequest const & cmd)
1410 // mouse clicks are somewhat special
1412 switch (cmd.action) {
1413 case LFUN_MOUSE_PRESS:
1414 case LFUN_MOUSE_MOTION:
1415 case LFUN_MOUSE_RELEASE:
1416 case LFUN_MOUSE_DOUBLE: {
1417 CursorPos & pos = Cursor_.back();
1418 dispatch_result res = UNDISPATCHED;
1421 if (x < cmd.x && hasPrevAtom()) {
1422 res = prevAtom().nucleus()->dispatch(cmd, pos.idx_, pos.pos_);
1423 if (res != UNDISPATCHED)
1426 if (x > cmd.x && hasNextAtom()) {
1427 res = nextAtom().nucleus()->dispatch(cmd, pos.idx_, pos.pos_);
1428 if (res != UNDISPATCHED)
1436 for (int i = Cursor_.size() - 1; i >= 0; --i) {
1437 CursorPos & pos = Cursor_[i];
1438 dispatch_result res = pos.inset_->dispatch(cmd, pos.idx_, pos.pos_);
1439 if (res != UNDISPATCHED) {
1440 if (res == DISPATCHED_POP) {
1441 Cursor_.shrink(i + 1);
1447 return UNDISPATCHED;
1451 MathInset::mode_type MathCursor::currentMode() const
1453 for (int i = Cursor_.size() - 1; i >= 0; --i) {
1454 MathInset::mode_type res = Cursor_[i].inset_->currentMode();
1455 if (res != MathInset::UNDECIDED_MODE)
1458 return MathInset::UNDECIDED_MODE;
1462 void MathCursor::handleFont(string const & font)
1467 safe = grabAndEraseSelection();
1470 if (array().size()) {
1471 // something left in the cell
1473 // cursor in first position
1475 } else if (pos() == array().size()) {
1476 // cursor in last position
1479 // cursor in between. split cell
1480 MathArray::iterator bt = array().begin();
1481 MathAtom at = createMathInset(font);
1482 at.nucleus()->cell(0) = MathArray(bt, bt + pos());
1483 cursor().cell().erase(bt, bt + pos());
1488 // nothing left in the cell
1496 void releaseMathCursor(BufferView * bv)
1499 InsetFormulaBase * f = mathcursor->formula();