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"
42 using std::ostringstream;
45 // matheds own cut buffer
46 limited_stack<string> theCutBuffer;
49 MathCursor::MathCursor(InsetFormulaBase * formula, bool front)
50 : formula_(formula), autocorrect_(false), selection_(false), targetx_(-1)
52 front ? first() : last();
57 MathCursor::~MathCursor()
59 // ensure that 'notifyCursorLeave' is called
65 void MathCursor::push(MathAtom & t)
67 Cursor_.push_back(CursorPos(t.nucleus()));
71 void MathCursor::pushLeft(MathAtom & t)
73 //lyxerr << "Entering atom " << t << " left" << endl;
75 t->idxFirst(idx(), pos());
79 void MathCursor::pushRight(MathAtom & t)
81 //lyxerr << "Entering atom " << t << " right" << endl;
84 t->idxLast(idx(), pos());
88 bool MathCursor::popLeft()
90 //lyxerr << "Leaving atom to the left" << endl;
93 inset()->notifyCursorLeaves(idx());
96 inset()->notifyCursorLeaves(idx());
102 bool MathCursor::popRight()
104 //lyxerr << "Leaving atom "; inset()->write(cerr, false); cerr << " right" << endl;
107 inset()->notifyCursorLeaves(idx());
110 inset()->notifyCursorLeaves(idx());
119 void MathCursor::dump(char const * what) const
121 lyxerr << "MC: " << what << endl;
122 lyxerr << " Cursor: " << depth() << endl;
123 for (unsigned i = 0; i < depth(); ++i)
124 lyxerr << " i: " << i << ' ' << Cursor_[i] << endl;
125 lyxerr << " Anchor: " << Anchor_.size() << endl;
126 for (unsigned i = 0; i < Anchor_.size(); ++i)
127 lyxerr << " i: " << i << ' ' << Anchor_[i] << endl;
128 lyxerr << " sel: " << selection_ << endl;
131 void MathCursor::dump(char const *) const {}
135 bool MathCursor::isInside(MathInset const * p) const
137 for (unsigned i = 0; i < depth(); ++i)
138 if (Cursor_[i].inset_ == p)
144 bool MathCursor::openable(MathAtom const & t, bool sel) const
153 // we can't move into anything new during selection
154 if (depth() == Anchor_.size())
156 if (t.operator->() != Anchor_[depth()].inset_)
163 bool MathCursor::inNucleus() const
165 return inset()->asScriptInset() && idx() == 2;
169 bool MathCursor::posLeft()
178 bool MathCursor::posRight()
187 bool MathCursor::left(bool sel)
190 autocorrect_ = false;
191 targetx_ = -1; // "no target"
198 if (hasPrevAtom() && openable(prevAtom(), sel)) {
199 pushRight(prevAtom());
203 return posLeft() || idxLeft() || popLeft() || selection_;
207 bool MathCursor::right(bool sel)
210 autocorrect_ = false;
211 targetx_ = -1; // "no target"
218 if (hasNextAtom() && openable(nextAtom(), sel)) {
219 pushLeft(nextAtom());
223 return posRight() || idxRight() || popRight() || selection_;
227 void MathCursor::first()
230 push(formula_->par());
231 inset()->idxFirst(idx(), pos());
235 void MathCursor::last()
238 push(formula_->par());
239 inset()->idxLast(idx(), pos());
244 (MathIterator const & cursor, MathIterator const & anchor)
246 // avoid deeper nested insets when selecting
247 if (cursor.size() > anchor.size())
250 // anchor might be deeper, should have same path then
251 for (MathIterator::size_type i = 0; i < cursor.size(); ++i)
252 if (cursor[i].inset_ != anchor[i].inset_)
255 // position should be ok.
260 void MathCursor::setPos(int x, int y)
263 bool res = bruteFind(x, y,
264 formula()->xlow(), formula()->xhigh(),
265 formula()->ylow(), formula()->yhigh());
267 // this can happen on creation of "math-display"
271 targetx_ = -1; // "no target"
277 bool MathCursor::home(bool sel)
280 autocorrect_ = false;
283 if (!inset()->idxHome(idx(), pos()))
286 targetx_ = -1; // "no target"
291 bool MathCursor::end(bool sel)
294 autocorrect_ = false;
297 if (!inset()->idxEnd(idx(), pos()))
300 targetx_ = -1; // "no target"
305 void MathCursor::plainErase()
307 array().erase(pos());
311 void MathCursor::markInsert()
313 //lyxerr << "inserting mark" << endl;
314 array().insert(pos(), MathAtom(new MathCharInset(0)));
318 void MathCursor::markErase()
320 //lyxerr << "deleting mark" << endl;
321 array().erase(pos());
325 void MathCursor::plainInsert(MathAtom const & t)
328 array().insert(pos(), t);
333 void MathCursor::insert2(string const & str)
341 void MathCursor::insert(string const & str)
343 //lyxerr << "inserting '" << str << "'" << endl;
345 for (string::const_iterator it = str.begin(); it != str.end(); ++it)
346 plainInsert(MathAtom(new MathCharInset(*it)));
350 void MathCursor::insert(char c)
352 //lyxerr << "inserting '" << c << "'" << endl;
354 plainInsert(MathAtom(new MathCharInset(c)));
358 void MathCursor::insert(MathAtom const & t)
366 void MathCursor::niceInsert(string const & t)
377 void MathCursor::niceInsert(MathAtom const & t)
380 string safe = grabAndEraseSelection();
382 // enter the new inset and move the contents of the selection if possible
385 pushLeft(nextAtom());
391 void MathCursor::insert(MathArray const & ar)
396 array().insert(pos(), ar);
401 void MathCursor::paste(string const & data)
403 dispatch(FuncRequest(LFUN_PASTE, data));
407 bool MathCursor::backspace()
409 autocorrect_ = false;
417 if (inset()->ncols() == 1 &&
418 inset()->nrows() == 1 &&
427 MathUnknownInset * p = activeMacro();
428 if (p->name().size() > 1) {
429 p->setName(p->name().substr(0, p->name().size() - 1));
440 bool MathCursor::erase()
442 autocorrect_ = false;
451 // delete empty cells if possible
453 if (inset()->idxDelete(idx()))
456 // old behaviour when in last position of cell
457 if (pos() == size()) {
458 if (inset()->ncols() == 1 && inset()->nrows() == 1 && depth() == 1 && size() == 0)
461 inset()->idxGlue(idx());
471 bool MathCursor::up(bool sel)
476 MathIterator save = Cursor_;
480 autocorrect_ = false;
485 bool MathCursor::down(bool sel)
490 MathIterator save = Cursor_;
494 autocorrect_ = false;
499 void MathCursor::macroModeClose()
503 MathUnknownInset * p = activeMacro();
505 string s = p->name();
507 array().erase(pos());
509 // do nothing if the macro name is empty
513 string const name = s.substr(1);
515 // prevent entering of recursive macros
516 if (formula()->lyxCode() == InsetOld::MATHMACRO_CODE
517 && formula()->getInsetName() == name)
518 lyxerr << "can't enter recursive macro" << endl;
520 niceInsert(createMathInset(name));
524 string MathCursor::macroName() const
526 return inMacroMode() ? activeMacro()->name() : string();
530 void MathCursor::selClear()
537 void MathCursor::selCopy()
541 theCutBuffer.push(grabSelection());
544 //theCutBuffer.erase();
549 void MathCursor::selCut()
552 theCutBuffer.push(grabAndEraseSelection());
556 void MathCursor::selDel()
566 void MathCursor::selPaste(size_t n)
570 if (n < theCutBuffer.size())
571 paste(theCutBuffer[n]);
577 void MathCursor::selHandle(bool sel)
579 if (sel == selection_)
587 void MathCursor::selStart()
597 void MathCursor::selClearOrDel()
599 if (lyxrc.auto_region_delete)
606 void MathCursor::drawSelection(PainterInfo & pi) const
612 getSelection(i1, i2);
613 i1.inset_->drawSelection(pi, i1.idx_, i1.pos_, i2.idx_, i2.pos_);
617 void MathCursor::handleNest(MathAtom const & a)
620 asArray(grabAndEraseSelection(), at.nucleus()->cell(0));
622 pushRight(prevAtom());
626 void MathCursor::getPos(int & x, int & y) const
628 inset()->getPos(idx(), pos(), x, y);
632 int MathCursor::targetX() const
642 MathInset * MathCursor::inset() const
644 return cursor().inset_;
648 InsetFormulaBase * MathCursor::formula() const
654 MathCursor::idx_type MathCursor::idx() const
656 return cursor().idx_;
660 MathCursor::idx_type & MathCursor::idx()
662 return cursor().idx_;
666 MathCursor::pos_type MathCursor::pos() const
668 return cursor().pos_;
672 void MathCursor::adjust(pos_type from, difference_type diff)
674 if (cursor().pos_ > from)
675 cursor().pos_ += diff;
676 if (Anchor_.back().pos_ > from)
677 Anchor_.back().pos_ += diff;
678 // just to be on the safe side
679 // theoretically unecessary
684 MathCursor::pos_type & MathCursor::pos()
686 return cursor().pos_;
690 bool MathCursor::inMacroMode() const
694 MathUnknownInset const * p = prevAtom()->asUnknownInset();
695 return p && !p->final();
699 MathUnknownInset * MathCursor::activeMacro()
701 return inMacroMode() ? prevAtom().nucleus()->asUnknownInset() : 0;
705 MathUnknownInset const * MathCursor::activeMacro() const
707 return inMacroMode() ? prevAtom()->asUnknownInset() : 0;
711 bool MathCursor::inMacroArgMode() const
713 return pos() > 0 && prevAtom()->getChar() == '#';
717 bool MathCursor::selection() const
723 MathGridInset * MathCursor::enclosingGrid(MathCursor::idx_type & idx) const
725 for (MathInset::difference_type i = depth() - 1; i >= 0; --i) {
726 MathGridInset * p = Cursor_[i].inset_->asGridInset();
728 idx = Cursor_[i].idx_;
736 void MathCursor::popToHere(MathInset const * p)
738 while (depth() && Cursor_.back().inset_ != p)
743 void MathCursor::popToEnclosingGrid()
745 while (depth() && !Cursor_.back().inset_->asGridInset())
750 void MathCursor::popToEnclosingHull()
752 while (depth() && !Cursor_.back().inset_->asHullInset())
757 void MathCursor::pullArg()
760 MathArray a = array();
763 array().insert(pos(), a);
766 formula()->mutateToText();
771 void MathCursor::touch()
773 MathIterator::const_iterator it = Cursor_.begin();
774 MathIterator::const_iterator et = Cursor_.end();
775 for ( ; it != et; ++it)
780 void MathCursor::normalize()
782 if (idx() >= inset()->nargs()) {
783 lyxerr << "this should not really happen - 1: "
784 << idx() << ' ' << inset()->nargs()
785 << " in: " << inset() << endl;
788 idx() = min(idx(), inset()->nargs() - 1);
790 if (pos() > size()) {
791 lyxerr << "this should not really happen - 2: "
792 << pos() << ' ' << size() << " in idx: " << idx()
794 WriteStream wi(lyxerr, false, true);
799 pos() = min(pos(), size());
803 MathCursor::size_type MathCursor::size() const
805 return array().size();
809 bool MathCursor::hasPrevAtom() const
815 bool MathCursor::hasNextAtom() const
817 return pos() < size();
821 MathAtom const & MathCursor::prevAtom() const
823 BOOST_ASSERT(pos() > 0);
824 return array()[pos() - 1];
828 MathAtom & MathCursor::prevAtom()
830 BOOST_ASSERT(pos() > 0);
831 return array()[pos() - 1];
835 MathAtom const & MathCursor::nextAtom() const
837 BOOST_ASSERT(pos() < size());
838 return array()[pos()];
842 MathAtom & MathCursor::nextAtom()
844 BOOST_ASSERT(pos() < size());
845 return array()[pos()];
849 MathArray & MathCursor::array() const
851 static MathArray dummy;
853 if (idx() >= inset()->nargs()) {
854 lyxerr << "############ idx_ " << idx() << " not valid" << endl;
859 lyxerr << "############ depth() == 0 not valid" << endl;
863 return cursor().cell();
867 void MathCursor::idxNext()
869 inset()->idxNext(idx(), pos());
873 void MathCursor::idxPrev()
875 inset()->idxPrev(idx(), pos());
879 char MathCursor::valign() const
882 MathGridInset * p = enclosingGrid(idx);
883 return p ? p->valign() : '\0';
887 char MathCursor::halign() const
890 MathGridInset * p = enclosingGrid(idx);
891 return p ? p->halign(idx % p->ncols()) : '\0';
895 void MathCursor::getSelection(CursorPos & i1, CursorPos & i2) const
897 CursorPos anc = normalAnchor();
898 if (anc < cursor()) {
908 CursorPos & MathCursor::cursor()
910 BOOST_ASSERT(depth());
911 return Cursor_.back();
915 CursorPos const & MathCursor::cursor() const
917 BOOST_ASSERT(depth());
918 return Cursor_.back();
922 bool MathCursor::goUpDown(bool up)
924 // Be warned: The 'logic' implemented in this function is highly fragile.
925 // A distance of one pixel or a '<' vs '<=' _really_ matters.
926 // So fiddle around with it only if you know what you are doing!
931 // check if we had something else in mind, if not, this is the future goal
937 // try neigbouring script insets
940 MathScriptInset const * p = prevAtom()->asScriptInset();
941 if (p && p->has(up)) {
944 idx() = up; // the superscript has index 1
946 ///lyxerr << "updown: handled by scriptinset to the left" << endl;
953 MathScriptInset const * p = nextAtom()->asScriptInset();
954 if (p && p->has(up)) {
958 ///lyxerr << "updown: handled by scriptinset to the right" << endl;
963 // try current cell for e.g. text insets
964 if (inset()->idxUpDown2(idx(), pos(), up, targetx_))
967 //xarray().boundingBox(xlow, xhigh, ylow, yhigh);
972 //if (bruteFind(xo, yo, xlow, xhigh, ylow, yhigh)) {
973 // lyxerr << "updown: handled by brute find in the same cell" << endl;
977 // try to find an inset that knows better then we
979 ///lyxerr << "updown: We are in " << *inset() << " idx: " << idx() << endl;
981 if (inset()->idxUpDown(idx(), pos(), up, targetx_)) {
982 // try to find best position within this inset
988 // no such inset found, just take something "above"
989 ///lyxerr << "updown: handled by strange case" << endl;
995 up ? formula()->ylow() : yo + 4,
996 up ? yo - 4 : formula()->yhigh()
999 // any improvement so far?
1002 if (up ? ynew < yo : ynew > yo)
1008 bool MathCursor::bruteFind
1009 (int x, int y, int xlow, int xhigh, int ylow, int yhigh)
1011 MathIterator best_cursor;
1012 double best_dist = 1e10;
1014 MathIterator it = ibegin(formula()->par().nucleus());
1015 MathIterator et = iend(formula()->par().nucleus());
1017 // avoid invalid nesting when selecting
1018 if (!selection_ || positionable(it, Anchor_)) {
1020 it.back().getPos(xo, yo);
1021 if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
1022 double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
1023 //lyxerr << "x: " << x << " y: " << y << " d: " << endl;
1024 // '<=' in order to take the last possible position
1025 // this is important for clicking behind \sum in e.g. '\sum_i a'
1026 if (d <= best_dist) {
1038 if (best_dist < 1e10)
1039 Cursor_ = best_cursor;
1040 return best_dist < 1e10;
1044 void MathCursor::bruteFind2(int x, int y)
1046 double best_dist = 1e10;
1048 MathIterator it = Cursor_;
1049 it.back().setPos(0);
1050 MathIterator et = Cursor_;
1051 et.back().setPos(it.cell().size());
1052 for (int i = 0; ; ++i) {
1054 it.back().getPos(xo, yo);
1055 double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
1056 // '<=' in order to take the last possible position
1057 // this is important for clicking behind \sum in e.g. '\sum_i a'
1058 lyxerr << "i: " << i << " d: " << d << " best: " << best_dist << endl;
1059 if (d <= best_dist) {
1070 bool MathCursor::idxLineLast()
1072 idx() -= idx() % inset()->ncols();
1073 idx() += inset()->ncols() - 1;
1078 bool MathCursor::idxLeft()
1080 return inset()->idxLeft(idx(), pos());
1084 bool MathCursor::idxRight()
1086 return inset()->idxRight(idx(), pos());
1090 bool MathCursor::script(bool up)
1092 // Hack to get \\^ and \\_ working
1093 if (inMacroMode() && macroName() == "\\") {
1095 niceInsert(createMathInset("mathcircumflex"));
1102 string safe = grabAndEraseSelection();
1104 // we are in a nucleus of a script inset, move to _our_ script
1105 inset()->asScriptInset()->ensure(up);
1108 } else if (hasPrevAtom() && prevAtom()->asScriptInset()) {
1109 prevAtom().nucleus()->asScriptInset()->ensure(up);
1110 pushRight(prevAtom());
1113 } else if (hasPrevAtom()) {
1115 array()[pos()] = MathAtom(new MathScriptInset(nextAtom(), up));
1116 pushLeft(nextAtom());
1120 plainInsert(MathAtom(new MathScriptInset(up)));
1121 prevAtom().nucleus()->asScriptInset()->ensure(up);
1122 pushRight(prevAtom());
1132 bool MathCursor::interpret(char c)
1134 //lyxerr << "interpret 2: '" << c << "'" << endl;
1135 targetx_ = -1; // "no target"
1136 if (inMacroArgMode()) {
1140 MathMacroTemplate const * p = formula()->par()->asMacroTemplate();
1141 if (p && 1 <= n && n <= p->numargs())
1142 insert(MathAtom(new MathMacroArgument(c - '0')));
1144 insert(createMathInset("#"));
1145 interpret(c); // try again
1151 if (inMacroMode()) {
1152 string name = macroName();
1153 //lyxerr << "interpret name: '" << name << "'" << endl;
1156 activeMacro()->setName(activeMacro()->name() + c);
1160 // handle 'special char' macros
1165 if (currentMode() == MathInset::TEXT_MODE)
1166 niceInsert(createMathInset("textbackslash"));
1168 niceInsert(createMathInset("backslash"));
1169 } else if (c == '{') {
1170 niceInsert(MathAtom(new MathBraceInset));
1172 niceInsert(createMathInset(string(1, c)));
1177 // leave macro mode and try again if necessary
1180 niceInsert(MathAtom(new MathBraceInset));
1186 // This is annoying as one has to press <space> far too often.
1190 // leave autocorrect mode if necessary
1191 if (autocorrect_ && c == ' ') {
1192 autocorrect_ = false;
1197 // just clear selection on pressing the space bar
1198 if (selection_ && c == ' ') {
1206 //lyxerr << "starting with macro" << endl;
1207 insert(MathAtom(new MathUnknownInset("\\", false)));
1212 if (currentMode() == MathInset::TEXT_MODE)
1218 if (currentMode() == MathInset::TEXT_MODE) {
1219 // insert spaces in text mode,
1220 // but suppress direct insertion of two spaces in a row
1221 // the still allows typing '<space>a<space>' and deleting the 'a', but
1222 // it is better than nothing...
1223 if (!hasPrevAtom() || prevAtom()->getChar() != ' ')
1227 if (hasPrevAtom() && prevAtom()->asSpaceInset()) {
1228 prevAtom().nucleus()->asSpaceInset()->incSpace();
1233 // if are at the very end, leave the formula
1234 return pos() != size();
1237 if (c == '{' || c == '}' || c == '#' || c == '&' || c == '$') {
1238 createMathInset(string(1, c));
1243 niceInsert(MathAtom(new MathCommentInset));
1247 // try auto-correction
1248 //if (autocorrect_ && hasPrevAtom() && math_autocorrect(prevAtom(), c))
1251 // no special circumstances, so insert the character without any fuss
1253 autocorrect_ = true;
1258 void MathCursor::setSelection(MathIterator const & where, size_type n)
1267 void MathCursor::insetToggle()
1269 if (hasNextAtom()) {
1270 // toggle previous inset ...
1271 nextAtom().nucleus()->lock(!nextAtom()->lock());
1272 } else if (popLeft() && hasNextAtom()) {
1273 // ... or enclosing inset if we are in the last inset position
1274 nextAtom().nucleus()->lock(!nextAtom()->lock());
1280 string MathCursor::info() const
1283 os << "Math editor mode. ";
1284 for (int i = 0, n = depth(); i < n; ++i) {
1285 Cursor_[i].inset_->infoize(os);
1289 prevAtom()->infoize2(os);
1291 return STRCONV(os.str());
1295 unsigned MathCursor::depth() const
1297 return Cursor_.size();
1305 void region(CursorPos const & i1, CursorPos const & i2,
1306 MathInset::row_type & r1, MathInset::row_type & r2,
1307 MathInset::col_type & c1, MathInset::col_type & c2)
1309 MathInset * p = i1.inset_;
1310 c1 = p->col(i1.idx_);
1311 c2 = p->col(i2.idx_);
1314 r1 = p->row(i1.idx_);
1315 r2 = p->row(i2.idx_);
1323 string MathCursor::grabSelection() const
1330 getSelection(i1, i2);
1332 if (i1.idx_ == i2.idx_) {
1333 MathArray::const_iterator it = i1.cell().begin();
1334 return asString(MathArray(it + i1.pos_, it + i2.pos_));
1339 region(i1, i2, r1, r2, c1, c2);
1342 for (row_type row = r1; row <= r2; ++row) {
1345 for (col_type col = c1; col <= c2; ++col) {
1348 data += asString(i1.inset_->cell(i1.inset_->index(row, col)));
1355 void MathCursor::eraseSelection()
1359 getSelection(i1, i2);
1360 if (i1.idx_ == i2.idx_)
1361 i1.cell().erase(i1.pos_, i2.pos_);
1363 MathInset * p = i1.inset_;
1366 region(i1, i2, r1, r2, c1, c2);
1367 for (row_type row = r1; row <= r2; ++row)
1368 for (col_type col = c1; col <= c2; ++col)
1369 p->cell(p->index(row, col)).clear();
1375 string MathCursor::grabAndEraseSelection()
1379 string res = grabSelection();
1386 CursorPos MathCursor::normalAnchor() const
1388 if (Anchor_.size() < depth()) {
1390 lyxerr << "unusual Anchor size" << endl;
1392 //lyx::BOOST_ASSERT(Anchor_.size() >= cursor.depth());
1393 // use Anchor on the same level as Cursor
1394 CursorPos normal = Anchor_[depth() - 1];
1395 if (depth() < Anchor_.size() && !(normal < cursor())) {
1396 // anchor is behind cursor -> move anchor behind the inset
1403 dispatch_result MathCursor::dispatch(FuncRequest const & cmd)
1405 // mouse clicks are somewhat special
1407 switch (cmd.action) {
1408 case LFUN_MOUSE_PRESS:
1409 case LFUN_MOUSE_MOTION:
1410 case LFUN_MOUSE_RELEASE:
1411 case LFUN_MOUSE_DOUBLE: {
1412 CursorPos & pos = Cursor_.back();
1413 dispatch_result res = UNDISPATCHED;
1416 if (x < cmd.x && hasPrevAtom()) {
1417 res = prevAtom().nucleus()->dispatch(cmd, pos.idx_, pos.pos_);
1418 if (res != UNDISPATCHED)
1421 if (x > cmd.x && hasNextAtom()) {
1422 res = nextAtom().nucleus()->dispatch(cmd, pos.idx_, pos.pos_);
1423 if (res != UNDISPATCHED)
1431 for (int i = Cursor_.size() - 1; i >= 0; --i) {
1432 CursorPos & pos = Cursor_[i];
1433 dispatch_result res = pos.inset_->dispatch(cmd, pos.idx_, pos.pos_);
1434 if (res != UNDISPATCHED) {
1435 if (res == DISPATCHED_POP) {
1436 Cursor_.shrink(i + 1);
1442 return UNDISPATCHED;
1446 MathInset::mode_type MathCursor::currentMode() const
1448 for (int i = Cursor_.size() - 1; i >= 0; --i) {
1449 MathInset::mode_type res = Cursor_[i].inset_->currentMode();
1450 if (res != MathInset::UNDECIDED_MODE)
1453 return MathInset::UNDECIDED_MODE;
1457 void MathCursor::handleFont(string const & font)
1462 safe = grabAndEraseSelection();
1465 if (array().size()) {
1466 // something left in the cell
1468 // cursor in first position
1470 } else if (pos() == array().size()) {
1471 // cursor in last position
1474 // cursor in between. split cell
1475 MathArray::iterator bt = array().begin();
1476 MathAtom at = createMathInset(font);
1477 at.nucleus()->cell(0) = MathArray(bt, bt + pos());
1478 cursor().cell().erase(bt, bt + pos());
1483 // nothing left in the cell
1491 void releaseMathCursor(BufferView * bv)
1494 InsetFormulaBase * f = mathcursor->formula();