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/lstrings.h"
17 #include "support/LAssert.h"
18 #include "support/limited_stack.h"
21 #include "frontends/Painter.h"
22 #include "math_cursor.h"
23 #include "formulabase.h"
24 #include "funcrequest.h"
25 #include "math_autocorrect.h"
26 #include "math_braceinset.h"
27 #include "math_commentinset.h"
28 #include "math_charinset.h"
29 #include "math_extern.h"
30 #include "math_factory.h"
31 #include "math_fontinset.h"
32 #include "math_gridinset.h"
33 #include "math_iterator.h"
34 #include "math_macroarg.h"
35 #include "math_macrotemplate.h"
36 #include "math_mathmlstream.h"
37 #include "math_scriptinset.h"
38 #include "math_spaceinset.h"
39 #include "math_support.h"
40 #include "math_unknowninset.h"
47 using namespace lyx::support;
54 using std::ostringstream;
58 // matheds own cut buffer
59 limited_stack<string> theCutBuffer;
62 MathCursor::MathCursor(InsetFormulaBase * formula, bool front)
63 : formula_(formula), autocorrect_(false), selection_(false), targetx_(-1)
65 front ? first() : last();
70 MathCursor::~MathCursor()
72 // ensure that 'notifyCursorLeave' is called
78 void MathCursor::push(MathAtom & t)
80 Cursor_.push_back(CursorPos(t.nucleus()));
84 void MathCursor::pushLeft(MathAtom & t)
86 //lyxerr << "Entering atom " << t << " left" << endl;
88 t->idxFirst(idx(), pos());
92 void MathCursor::pushRight(MathAtom & t)
94 //lyxerr << "Entering atom " << t << " right" << endl;
97 t->idxLast(idx(), pos());
101 bool MathCursor::popLeft()
103 //lyxerr << "Leaving atom to the left" << endl;
106 inset()->notifyCursorLeaves(idx());
109 inset()->notifyCursorLeaves(idx());
115 bool MathCursor::popRight()
117 //lyxerr << "Leaving atom "; inset()->write(cerr, false); cerr << " right" << endl;
120 inset()->notifyCursorLeaves(idx());
123 inset()->notifyCursorLeaves(idx());
132 void MathCursor::dump(char const * what) const
134 lyxerr << "MC: " << what << endl;
135 lyxerr << " Cursor: " << depth() << endl;
136 for (unsigned i = 0; i < depth(); ++i)
137 lyxerr << " i: " << i << ' ' << Cursor_[i] << endl;
138 lyxerr << " Anchor: " << Anchor_.size() << endl;
139 for (unsigned i = 0; i < Anchor_.size(); ++i)
140 lyxerr << " i: " << i << ' ' << Anchor_[i] << endl;
141 lyxerr << " sel: " << selection_ << endl;
144 void MathCursor::dump(char const *) const {}
148 bool MathCursor::isInside(MathInset const * p) const
150 for (unsigned i = 0; i < depth(); ++i)
151 if (Cursor_[i].inset_ == p)
157 bool MathCursor::openable(MathAtom const & t, bool sel) const
166 // we can't move into anything new during selection
167 if (depth() == Anchor_.size())
169 if (t.operator->() != Anchor_[depth()].inset_)
176 bool MathCursor::inNucleus() const
178 return inset()->asScriptInset() && idx() == 2;
182 bool MathCursor::posLeft()
191 bool MathCursor::posRight()
200 bool MathCursor::left(bool sel)
203 autocorrect_ = false;
204 targetx_ = -1; // "no target"
211 if (hasPrevAtom() && openable(prevAtom(), sel)) {
212 pushRight(prevAtom());
216 return posLeft() || idxLeft() || popLeft() || selection_;
220 bool MathCursor::right(bool sel)
223 autocorrect_ = false;
224 targetx_ = -1; // "no target"
231 if (hasNextAtom() && openable(nextAtom(), sel)) {
232 pushLeft(nextAtom());
236 return posRight() || idxRight() || popRight() || selection_;
240 void MathCursor::first()
243 push(formula_->par());
244 inset()->idxFirst(idx(), pos());
248 void MathCursor::last()
251 push(formula_->par());
252 inset()->idxLast(idx(), pos());
257 (MathIterator const & cursor, MathIterator const & anchor)
259 // avoid deeper nested insets when selecting
260 if (cursor.size() > anchor.size())
263 // anchor might be deeper, should have same path then
264 for (MathIterator::size_type i = 0; i < cursor.size(); ++i)
265 if (cursor[i].inset_ != anchor[i].inset_)
268 // position should be ok.
273 void MathCursor::setPos(int x, int y)
276 bool res = bruteFind(x, y,
277 formula()->xlow(), formula()->xhigh(),
278 formula()->ylow(), formula()->yhigh());
280 // this can happen on creation of "math-display"
284 targetx_ = -1; // "no target"
290 bool MathCursor::home(bool sel)
293 autocorrect_ = false;
296 if (!inset()->idxHome(idx(), pos()))
299 targetx_ = -1; // "no target"
304 bool MathCursor::end(bool sel)
307 autocorrect_ = false;
310 if (!inset()->idxEnd(idx(), pos()))
313 targetx_ = -1; // "no target"
318 void MathCursor::plainErase()
320 array().erase(pos());
324 void MathCursor::markInsert()
326 //lyxerr << "inserting mark" << endl;
327 array().insert(pos(), MathAtom(new MathCharInset(0)));
331 void MathCursor::markErase()
333 //lyxerr << "deleting mark" << endl;
334 array().erase(pos());
338 void MathCursor::plainInsert(MathAtom const & t)
341 array().insert(pos(), t);
346 void MathCursor::insert2(string const & str)
354 void MathCursor::insert(string const & str)
356 //lyxerr << "inserting '" << str << "'" << endl;
358 for (string::const_iterator it = str.begin(); it != str.end(); ++it)
359 plainInsert(MathAtom(new MathCharInset(*it)));
363 void MathCursor::insert(char c)
365 //lyxerr << "inserting '" << c << "'" << endl;
367 plainInsert(MathAtom(new MathCharInset(c)));
371 void MathCursor::insert(MathAtom const & t)
379 void MathCursor::niceInsert(string const & t)
390 void MathCursor::niceInsert(MathAtom const & t)
393 string safe = grabAndEraseSelection();
395 // enter the new inset and move the contents of the selection if possible
398 pushLeft(nextAtom());
404 void MathCursor::insert(MathArray const & ar)
409 array().insert(pos(), ar);
414 void MathCursor::paste(string const & data)
416 dispatch(FuncRequest(LFUN_PASTE, data));
420 bool MathCursor::backspace()
422 autocorrect_ = false;
430 if (inset()->ncols() == 1 &&
431 inset()->nrows() == 1 &&
440 MathUnknownInset * p = activeMacro();
441 if (p->name().size() > 1) {
442 p->setName(p->name().substr(0, p->name().size() - 1));
453 bool MathCursor::erase()
455 autocorrect_ = false;
464 // delete empty cells if possible
466 if (inset()->idxDelete(idx()))
469 // old behaviour when in last position of cell
470 if (pos() == size()) {
471 if (inset()->ncols() == 1 && inset()->nrows() == 1 && depth() == 1 && size() == 0)
474 inset()->idxGlue(idx());
484 bool MathCursor::up(bool sel)
489 MathIterator save = Cursor_;
493 autocorrect_ = false;
498 bool MathCursor::down(bool sel)
503 MathIterator save = Cursor_;
507 autocorrect_ = false;
512 void MathCursor::macroModeClose()
516 MathUnknownInset * p = activeMacro();
518 string s = p->name();
520 array().erase(pos());
522 // do nothing if the macro name is empty
526 string const name = s.substr(1);
528 // prevent entering of recursive macros
529 if (formula()->lyxCode() == InsetOld::MATHMACRO_CODE
530 && formula()->getInsetName() == name)
531 lyxerr << "can't enter recursive macro" << endl;
533 niceInsert(createMathInset(name));
537 string MathCursor::macroName() const
539 return inMacroMode() ? activeMacro()->name() : string();
543 void MathCursor::selClear()
550 void MathCursor::selCopy()
554 theCutBuffer.push(grabSelection());
557 //theCutBuffer.erase();
562 void MathCursor::selCut()
565 theCutBuffer.push(grabAndEraseSelection());
569 void MathCursor::selDel()
579 void MathCursor::selPaste(size_t n)
583 if (n < theCutBuffer.size())
584 paste(theCutBuffer[n]);
590 void MathCursor::selHandle(bool sel)
592 if (sel == selection_)
600 void MathCursor::selStart()
610 void MathCursor::selClearOrDel()
612 if (lyxrc.auto_region_delete)
619 void MathCursor::drawSelection(PainterInfo & pi) const
625 getSelection(i1, i2);
626 i1.inset_->drawSelection(pi, i1.idx_, i1.pos_, i2.idx_, i2.pos_);
630 void MathCursor::handleNest(MathAtom const & a)
633 asArray(grabAndEraseSelection(), at.nucleus()->cell(0));
635 pushRight(prevAtom());
639 void MathCursor::getPos(int & x, int & y) const
641 inset()->getPos(idx(), pos(), x, y);
645 int MathCursor::targetX() const
655 MathInset * MathCursor::inset() const
657 return cursor().inset_;
661 InsetFormulaBase * MathCursor::formula() const
667 MathCursor::idx_type MathCursor::idx() const
669 return cursor().idx_;
673 MathCursor::idx_type & MathCursor::idx()
675 return cursor().idx_;
679 MathCursor::pos_type MathCursor::pos() const
681 return cursor().pos_;
685 void MathCursor::adjust(pos_type from, difference_type diff)
687 if (cursor().pos_ > from)
688 cursor().pos_ += diff;
689 if (Anchor_.back().pos_ > from)
690 Anchor_.back().pos_ += diff;
691 // just to be on the safe side
692 // theoretically unecessary
697 MathCursor::pos_type & MathCursor::pos()
699 return cursor().pos_;
703 bool MathCursor::inMacroMode() const
707 MathUnknownInset const * p = prevAtom()->asUnknownInset();
708 return p && !p->final();
712 MathUnknownInset * MathCursor::activeMacro()
714 return inMacroMode() ? prevAtom().nucleus()->asUnknownInset() : 0;
718 MathUnknownInset const * MathCursor::activeMacro() const
720 return inMacroMode() ? prevAtom()->asUnknownInset() : 0;
724 bool MathCursor::inMacroArgMode() const
726 return pos() > 0 && prevAtom()->getChar() == '#';
730 bool MathCursor::selection() const
736 MathGridInset * MathCursor::enclosingGrid(MathCursor::idx_type & idx) const
738 for (MathInset::difference_type i = depth() - 1; i >= 0; --i) {
739 MathGridInset * p = Cursor_[i].inset_->asGridInset();
741 idx = Cursor_[i].idx_;
749 void MathCursor::popToHere(MathInset const * p)
751 while (depth() && Cursor_.back().inset_ != p)
756 void MathCursor::popToEnclosingGrid()
758 while (depth() && !Cursor_.back().inset_->asGridInset())
763 void MathCursor::popToEnclosingHull()
765 while (depth() && !Cursor_.back().inset_->asHullInset())
770 void MathCursor::pullArg()
773 MathArray a = array();
776 array().insert(pos(), a);
779 formula()->mutateToText();
784 void MathCursor::touch()
786 MathIterator::const_iterator it = Cursor_.begin();
787 MathIterator::const_iterator et = Cursor_.end();
788 for ( ; it != et; ++it)
793 void MathCursor::normalize()
795 if (idx() >= inset()->nargs()) {
796 lyxerr << "this should not really happen - 1: "
797 << idx() << ' ' << inset()->nargs()
798 << " in: " << inset() << endl;
801 idx() = min(idx(), inset()->nargs() - 1);
803 if (pos() > size()) {
804 lyxerr << "this should not really happen - 2: "
805 << pos() << ' ' << size() << " in idx: " << idx()
807 WriteStream wi(lyxerr, false, true);
812 pos() = min(pos(), size());
816 MathCursor::size_type MathCursor::size() const
818 return array().size();
822 bool MathCursor::hasPrevAtom() const
828 bool MathCursor::hasNextAtom() const
830 return pos() < size();
834 MathAtom const & MathCursor::prevAtom() const
837 return array()[pos() - 1];
841 MathAtom & MathCursor::prevAtom()
844 return array()[pos() - 1];
848 MathAtom const & MathCursor::nextAtom() const
850 Assert(pos() < size());
851 return array()[pos()];
855 MathAtom & MathCursor::nextAtom()
857 Assert(pos() < size());
858 return array()[pos()];
862 MathArray & MathCursor::array() const
864 static MathArray dummy;
866 if (idx() >= inset()->nargs()) {
867 lyxerr << "############ idx_ " << idx() << " not valid" << endl;
872 lyxerr << "############ depth() == 0 not valid" << endl;
876 return cursor().cell();
880 void MathCursor::idxNext()
882 inset()->idxNext(idx(), pos());
886 void MathCursor::idxPrev()
888 inset()->idxPrev(idx(), pos());
892 char MathCursor::valign() const
895 MathGridInset * p = enclosingGrid(idx);
896 return p ? p->valign() : '\0';
900 char MathCursor::halign() const
903 MathGridInset * p = enclosingGrid(idx);
904 return p ? p->halign(idx % p->ncols()) : '\0';
908 void MathCursor::getSelection(CursorPos & i1, CursorPos & i2) const
910 CursorPos anc = normalAnchor();
911 if (anc < cursor()) {
921 CursorPos & MathCursor::cursor()
924 return Cursor_.back();
928 CursorPos const & MathCursor::cursor() const
931 return Cursor_.back();
935 bool MathCursor::goUpDown(bool up)
937 // Be warned: The 'logic' implemented in this function is highly fragile.
938 // A distance of one pixel or a '<' vs '<=' _really_ matters.
939 // So fiddle around with it only if you know what you are doing!
944 // check if we had something else in mind, if not, this is the future goal
950 // try neigbouring script insets
953 MathScriptInset const * p = prevAtom()->asScriptInset();
954 if (p && p->has(up)) {
957 idx() = up; // the superscript has index 1
959 ///lyxerr << "updown: handled by scriptinset to the left" << endl;
966 MathScriptInset const * p = nextAtom()->asScriptInset();
967 if (p && p->has(up)) {
971 ///lyxerr << "updown: handled by scriptinset to the right" << endl;
976 // try current cell for e.g. text insets
977 if (inset()->idxUpDown2(idx(), pos(), up, targetx_))
980 //xarray().boundingBox(xlow, xhigh, ylow, yhigh);
985 //if (bruteFind(xo, yo, xlow, xhigh, ylow, yhigh)) {
986 // lyxerr << "updown: handled by brute find in the same cell" << endl;
990 // try to find an inset that knows better then we
992 ///lyxerr << "updown: We are in " << *inset() << " idx: " << idx() << endl;
994 if (inset()->idxUpDown(idx(), pos(), up, targetx_)) {
995 // try to find best position within this inset
1001 // no such inset found, just take something "above"
1002 ///lyxerr << "updown: handled by strange case" << endl;
1008 up ? formula()->ylow() : yo + 4,
1009 up ? yo - 4 : formula()->yhigh()
1012 // any improvement so far?
1015 if (up ? ynew < yo : ynew > yo)
1021 bool MathCursor::bruteFind
1022 (int x, int y, int xlow, int xhigh, int ylow, int yhigh)
1024 MathIterator best_cursor;
1025 double best_dist = 1e10;
1027 MathIterator it = ibegin(formula()->par().nucleus());
1028 MathIterator et = iend(formula()->par().nucleus());
1030 // avoid invalid nesting when selecting
1031 if (!selection_ || positionable(it, Anchor_)) {
1033 it.back().getPos(xo, yo);
1034 if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
1035 double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
1036 //lyxerr << "x: " << x << " y: " << y << " d: " << endl;
1037 // '<=' in order to take the last possible position
1038 // this is important for clicking behind \sum in e.g. '\sum_i a'
1039 if (d <= best_dist) {
1051 if (best_dist < 1e10)
1052 Cursor_ = best_cursor;
1053 return best_dist < 1e10;
1057 void MathCursor::bruteFind2(int x, int y)
1059 double best_dist = 1e10;
1061 MathIterator it = Cursor_;
1062 it.back().setPos(0);
1063 MathIterator et = Cursor_;
1064 et.back().setPos(it.cell().size());
1065 for (int i = 0; ; ++i) {
1067 it.back().getPos(xo, yo);
1068 double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
1069 // '<=' in order to take the last possible position
1070 // this is important for clicking behind \sum in e.g. '\sum_i a'
1071 lyxerr << "i: " << i << " d: " << d << " best: " << best_dist << endl;
1072 if (d <= best_dist) {
1083 bool MathCursor::idxLineLast()
1085 idx() -= idx() % inset()->ncols();
1086 idx() += inset()->ncols() - 1;
1091 bool MathCursor::idxLeft()
1093 return inset()->idxLeft(idx(), pos());
1097 bool MathCursor::idxRight()
1099 return inset()->idxRight(idx(), pos());
1103 bool MathCursor::script(bool up)
1105 // Hack to get \\^ and \\_ working
1106 if (inMacroMode() && macroName() == "\\") {
1108 niceInsert(createMathInset("mathcircumflex"));
1115 string safe = grabAndEraseSelection();
1117 // we are in a nucleus of a script inset, move to _our_ script
1118 inset()->asScriptInset()->ensure(up);
1121 } else if (hasPrevAtom() && prevAtom()->asScriptInset()) {
1122 prevAtom().nucleus()->asScriptInset()->ensure(up);
1123 pushRight(prevAtom());
1126 } else if (hasPrevAtom()) {
1128 array()[pos()] = MathAtom(new MathScriptInset(nextAtom(), up));
1129 pushLeft(nextAtom());
1133 plainInsert(MathAtom(new MathScriptInset(up)));
1134 prevAtom().nucleus()->asScriptInset()->ensure(up);
1135 pushRight(prevAtom());
1145 bool MathCursor::interpret(char c)
1147 //lyxerr << "interpret 2: '" << c << "'" << endl;
1148 targetx_ = -1; // "no target"
1149 if (inMacroArgMode()) {
1153 MathMacroTemplate const * p = formula()->par()->asMacroTemplate();
1154 if (p && 1 <= n && n <= p->numargs())
1155 insert(MathAtom(new MathMacroArgument(c - '0')));
1157 insert(createMathInset("#"));
1158 interpret(c); // try again
1164 if (inMacroMode()) {
1165 string name = macroName();
1166 //lyxerr << "interpret name: '" << name << "'" << endl;
1169 activeMacro()->setName(activeMacro()->name() + c);
1173 // handle 'special char' macros
1178 if (currentMode() == MathInset::TEXT_MODE)
1179 niceInsert(createMathInset("textbackslash"));
1181 niceInsert(createMathInset("backslash"));
1182 } else if (c == '{') {
1183 niceInsert(MathAtom(new MathBraceInset));
1185 niceInsert(createMathInset(string(1, c)));
1190 // leave macro mode and try again if necessary
1193 niceInsert(MathAtom(new MathBraceInset));
1199 // This is annoying as one has to press <space> far too often.
1203 // leave autocorrect mode if necessary
1204 if (autocorrect_ && c == ' ') {
1205 autocorrect_ = false;
1210 // just clear selection on pressing the space bar
1211 if (selection_ && c == ' ') {
1219 //lyxerr << "starting with macro" << endl;
1220 insert(MathAtom(new MathUnknownInset("\\", false)));
1225 if (currentMode() == MathInset::TEXT_MODE)
1231 if (currentMode() == MathInset::TEXT_MODE) {
1232 // insert spaces in text mode,
1233 // but suppress direct insertion of two spaces in a row
1234 // the still allows typing '<space>a<space>' and deleting the 'a', but
1235 // it is better than nothing...
1236 if (!hasPrevAtom() || prevAtom()->getChar() != ' ')
1240 if (hasPrevAtom() && prevAtom()->asSpaceInset()) {
1241 prevAtom().nucleus()->asSpaceInset()->incSpace();
1246 // if are at the very end, leave the formula
1247 return pos() != size();
1250 if (c == '{' || c == '}' || c == '#' || c == '&' || c == '$') {
1251 createMathInset(string(1, c));
1256 niceInsert(MathAtom(new MathCommentInset));
1260 // try auto-correction
1261 //if (autocorrect_ && hasPrevAtom() && math_autocorrect(prevAtom(), c))
1264 // no special circumstances, so insert the character without any fuss
1266 autocorrect_ = true;
1271 void MathCursor::setSelection(MathIterator const & where, size_type n)
1280 void MathCursor::insetToggle()
1282 if (hasNextAtom()) {
1283 // toggle previous inset ...
1284 nextAtom().nucleus()->lock(!nextAtom()->lock());
1285 } else if (popLeft() && hasNextAtom()) {
1286 // ... or enclosing inset if we are in the last inset position
1287 nextAtom().nucleus()->lock(!nextAtom()->lock());
1293 string MathCursor::info() const
1296 os << "Math editor mode. ";
1297 for (int i = 0, n = depth(); i < n; ++i) {
1298 Cursor_[i].inset_->infoize(os);
1302 prevAtom()->infoize2(os);
1304 return STRCONV(os.str());
1308 unsigned MathCursor::depth() const
1310 return Cursor_.size();
1318 void region(CursorPos const & i1, CursorPos const & i2,
1319 MathInset::row_type & r1, MathInset::row_type & r2,
1320 MathInset::col_type & c1, MathInset::col_type & c2)
1322 MathInset * p = i1.inset_;
1323 c1 = p->col(i1.idx_);
1324 c2 = p->col(i2.idx_);
1327 r1 = p->row(i1.idx_);
1328 r2 = p->row(i2.idx_);
1336 string MathCursor::grabSelection() const
1343 getSelection(i1, i2);
1345 if (i1.idx_ == i2.idx_) {
1346 MathArray::const_iterator it = i1.cell().begin();
1347 return asString(MathArray(it + i1.pos_, it + i2.pos_));
1352 region(i1, i2, r1, r2, c1, c2);
1355 for (row_type row = r1; row <= r2; ++row) {
1358 for (col_type col = c1; col <= c2; ++col) {
1361 data += asString(i1.inset_->cell(i1.inset_->index(row, col)));
1368 void MathCursor::eraseSelection()
1372 getSelection(i1, i2);
1373 if (i1.idx_ == i2.idx_)
1374 i1.cell().erase(i1.pos_, i2.pos_);
1376 MathInset * p = i1.inset_;
1379 region(i1, i2, r1, r2, c1, c2);
1380 for (row_type row = r1; row <= r2; ++row)
1381 for (col_type col = c1; col <= c2; ++col)
1382 p->cell(p->index(row, col)).clear();
1388 string MathCursor::grabAndEraseSelection()
1392 string res = grabSelection();
1399 CursorPos MathCursor::normalAnchor() const
1401 if (Anchor_.size() < depth()) {
1403 lyxerr << "unusual Anchor size" << endl;
1405 //lyx::Assert(Anchor_.size() >= cursor.depth());
1406 // use Anchor on the same level as Cursor
1407 CursorPos normal = Anchor_[depth() - 1];
1408 if (depth() < Anchor_.size() && !(normal < cursor())) {
1409 // anchor is behind cursor -> move anchor behind the inset
1416 dispatch_result MathCursor::dispatch(FuncRequest const & cmd)
1418 // mouse clicks are somewhat special
1420 switch (cmd.action) {
1421 case LFUN_MOUSE_PRESS:
1422 case LFUN_MOUSE_MOTION:
1423 case LFUN_MOUSE_RELEASE:
1424 case LFUN_MOUSE_DOUBLE: {
1425 CursorPos & pos = Cursor_.back();
1426 dispatch_result res = UNDISPATCHED;
1429 if (x < cmd.x && hasPrevAtom()) {
1430 res = prevAtom().nucleus()->dispatch(cmd, pos.idx_, pos.pos_);
1431 if (res != UNDISPATCHED)
1434 if (x > cmd.x && hasNextAtom()) {
1435 res = nextAtom().nucleus()->dispatch(cmd, pos.idx_, pos.pos_);
1436 if (res != UNDISPATCHED)
1444 for (int i = Cursor_.size() - 1; i >= 0; --i) {
1445 CursorPos & pos = Cursor_[i];
1446 dispatch_result res = pos.inset_->dispatch(cmd, pos.idx_, pos.pos_);
1447 if (res != UNDISPATCHED) {
1448 if (res == DISPATCHED_POP) {
1449 Cursor_.shrink(i + 1);
1455 return UNDISPATCHED;
1459 MathInset::mode_type MathCursor::currentMode() const
1461 for (int i = Cursor_.size() - 1; i >= 0; --i) {
1462 MathInset::mode_type res = Cursor_[i].inset_->currentMode();
1463 if (res != MathInset::UNDECIDED_MODE)
1466 return MathInset::UNDECIDED_MODE;
1470 void MathCursor::handleFont(string const & font)
1475 safe = grabAndEraseSelection();
1478 if (array().size()) {
1479 // something left in the cell
1481 // cursor in first position
1483 } else if (pos() == array().size()) {
1484 // cursor in last position
1487 // cursor in between. split cell
1488 MathArray::iterator bt = array().begin();
1489 MathAtom at = createMathInset(font);
1490 at.nucleus()->cell(0) = MathArray(bt, bt + pos());
1491 cursor().cell().erase(bt, bt + pos());
1496 // nothing left in the cell
1504 void releaseMathCursor(BufferView * bv)
1507 InsetFormulaBase * f = mathcursor->formula();