3 * Purpose: Interaction for mathed
4 * Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
5 * Created: January 1996
6 * Description: Math interaction for a WYSIWYG math editor.
8 * Dependencies: Xlib, XForms
10 * Copyright: 1996, Alejandro Aguilar Sierra
12 * Version: 0.8beta, Math & Lyx project.
14 * You are free to use and modify this code under the terms of
15 * the GNU General Public Licence version 2 or later.
21 #include "support/lstrings.h"
22 #include "support/LAssert.h"
23 #include "support/limited_stack.h"
26 #include "frontends/Painter.h"
27 #include "math_cursor.h"
28 #include "formulabase.h"
29 #include "funcrequest.h"
30 #include "math_autocorrect.h"
31 #include "math_braceinset.h"
32 #include "math_commentinset.h"
33 #include "math_charinset.h"
34 #include "math_extern.h"
35 #include "math_factory.h"
36 #include "math_fontinset.h"
37 #include "math_gridinset.h"
38 #include "math_iterator.h"
39 #include "math_macroarg.h"
40 #include "math_macrotemplate.h"
41 #include "math_mathmlstream.h"
42 #include "math_scriptinset.h"
43 #include "math_spaceinset.h"
44 #include "math_support.h"
45 #include "math_unknowninset.h"
57 using std::ostringstream;
61 // matheds own cut buffer
62 limited_stack<string> theCutBuffer;
65 MathCursor::MathCursor(InsetFormulaBase * formula, bool front)
66 : formula_(formula), autocorrect_(false), selection_(false), targetx_(-1)
68 front ? first() : last();
73 MathCursor::~MathCursor()
75 // ensure that 'notifyCursorLeave' is called
81 void MathCursor::push(MathAtom & t)
83 Cursor_.push_back(MathCursorPos(t.nucleus()));
87 void MathCursor::pushLeft(MathAtom & t)
89 //lyxerr << "Entering atom " << t << " left\n";
91 t->idxFirst(idx(), pos());
95 void MathCursor::pushRight(MathAtom & t)
97 //lyxerr << "Entering atom " << t << " right\n";
100 t->idxLast(idx(), pos());
104 bool MathCursor::popLeft()
106 //lyxerr << "Leaving atom to the left\n";
109 par()->notifyCursorLeaves(idx());
112 par()->notifyCursorLeaves(idx());
118 bool MathCursor::popRight()
120 //lyxerr << "Leaving atom "; par()->write(cerr, false); cerr << " right\n";
123 par()->notifyCursorLeaves(idx());
126 par()->notifyCursorLeaves(idx());
135 void MathCursor::dump(char const * what) const
137 lyxerr << "MC: " << what << endl;
138 lyxerr << " Cursor: " << depth() << endl;
139 for (unsigned i = 0; i < depth(); ++i)
140 lyxerr << " i: " << i << ' ' << Cursor_[i] << endl;
141 lyxerr << " Anchor: " << Anchor_.size() << endl;
142 for (unsigned i = 0; i < Anchor_.size(); ++i)
143 lyxerr << " i: " << i << ' ' << Anchor_[i] << endl;
144 lyxerr << " sel: " << selection_ << endl;
147 void MathCursor::dump(char const *) const {}
151 bool MathCursor::isInside(MathInset const * p) const
153 for (unsigned i = 0; i < depth(); ++i)
154 if (Cursor_[i].par_ == p)
160 bool MathCursor::openable(MathAtom const & t, bool sel) const
169 // we can't move into anything new during selection
170 if (depth() == Anchor_.size())
172 if (t.operator->() != Anchor_[depth()].par_)
179 bool MathCursor::inNucleus() const
181 return par()->asScriptInset() && idx() == 2;
185 bool MathCursor::posLeft()
194 bool MathCursor::posRight()
203 bool MathCursor::left(bool sel)
206 autocorrect_ = false;
207 targetx_ = -1; // "no target"
214 if (hasPrevAtom() && openable(prevAtom(), sel)) {
215 pushRight(prevAtom());
219 return posLeft() || idxLeft() || popLeft() || selection_;
223 bool MathCursor::right(bool sel)
226 autocorrect_ = false;
227 targetx_ = -1; // "no target"
234 if (hasNextAtom() && openable(nextAtom(), sel)) {
235 pushLeft(nextAtom());
239 return posRight() || idxRight() || popRight() || selection_;
243 void MathCursor::first()
246 push(formula_->par());
247 par()->idxFirst(idx(), pos());
251 void MathCursor::last()
254 push(formula_->par());
255 par()->idxLast(idx(), pos());
260 (MathIterator const & cursor, MathIterator const & anchor)
262 // avoid deeper nested insets when selecting
263 if (cursor.size() > anchor.size())
266 // anchor might be deeper, should have same path then
267 for (MathIterator::size_type i = 0; i < cursor.size(); ++i)
268 if (cursor[i].par_ != anchor[i].par_)
271 // position should be ok.
276 void MathCursor::setPos(int x, int y)
279 bool res = bruteFind(x, y,
280 formula()->xlow(), formula()->xhigh(),
281 formula()->ylow(), formula()->yhigh());
283 // this can happen on creation of "math-display"
287 targetx_ = -1; // "no target"
293 bool MathCursor::home(bool sel)
296 autocorrect_ = false;
299 if (!par()->idxHome(idx(), pos()))
302 targetx_ = -1; // "no target"
307 bool MathCursor::end(bool sel)
310 autocorrect_ = false;
313 if (!par()->idxEnd(idx(), pos()))
316 targetx_ = -1; // "no target"
321 void MathCursor::plainErase()
323 array().erase(pos());
327 void MathCursor::markInsert()
329 //lyxerr << "inserting mark\n";
330 array().insert(pos(), MathAtom(new MathCharInset(0)));
334 void MathCursor::markErase()
336 //lyxerr << "deleting mark\n";
337 array().erase(pos());
341 void MathCursor::plainInsert(MathAtom const & t)
344 array().insert(pos(), t);
349 void MathCursor::insert2(string const & str)
357 void MathCursor::insert(string const & str)
359 //lyxerr << "inserting '" << str << "'\n";
361 for (string::const_iterator it = str.begin(); it != str.end(); ++it)
362 plainInsert(MathAtom(new MathCharInset(*it)));
366 void MathCursor::insert(char c)
368 //lyxerr << "inserting '" << c << "'\n";
370 plainInsert(MathAtom(new MathCharInset(c)));
374 void MathCursor::insert(MathAtom const & t)
382 void MathCursor::niceInsert(string const & t)
393 void MathCursor::niceInsert(MathAtom const & t)
396 string safe = grabAndEraseSelection();
398 // enter the new inset and move the contents of the selection if possible
401 pushLeft(nextAtom());
407 void MathCursor::insert(MathArray const & ar)
412 array().insert(pos(), ar);
417 void MathCursor::paste(string const & data)
419 dispatch(FuncRequest(LFUN_PASTE, data));
423 bool MathCursor::backspace()
425 autocorrect_ = false;
433 if (par()->ncols() == 1 &&
434 par()->nrows() == 1 &&
443 MathUnknownInset * p = activeMacro();
444 if (p->name().size() > 1) {
445 p->setName(p->name().substr(0, p->name().size() - 1));
456 bool MathCursor::erase()
458 autocorrect_ = false;
467 // delete empty cells if possible
469 if (par()->idxDelete(idx()))
472 // old behaviour when in last position of cell
473 if (pos() == size()) {
474 if (par()->ncols() == 1 && par()->nrows() == 1 && depth() == 1 && size() == 0)
477 par()->idxGlue(idx());
487 bool MathCursor::up(bool sel)
492 MathIterator save = Cursor_;
496 autocorrect_ = false;
501 bool MathCursor::down(bool sel)
506 MathIterator save = Cursor_;
510 autocorrect_ = false;
515 void MathCursor::macroModeClose()
519 MathUnknownInset * p = activeMacro();
521 string s = p->name();
523 array().erase(pos());
525 // do nothing if the macro name is empty
529 string name = s.substr(1);
531 // prevent entering of recursive macros
532 if (formula()->lyxCode() == Inset::MATHMACRO_CODE
533 && formula()->getInsetName() == name)
534 lyxerr << "can't enter recursive macro\n";
536 niceInsert(createMathInset(name));
540 string MathCursor::macroName() const
542 return inMacroMode() ? activeMacro()->name() : string();
546 void MathCursor::selClear()
553 void MathCursor::selCopy()
557 theCutBuffer.push(grabSelection());
560 //theCutBuffer.erase();
565 void MathCursor::selCut()
568 theCutBuffer.push(grabAndEraseSelection());
572 void MathCursor::selDel()
582 void MathCursor::selPaste(int n)
586 if (n < theCutBuffer.size())
587 paste(theCutBuffer[n]);
593 void MathCursor::selHandle(bool sel)
595 if (sel == selection_)
603 void MathCursor::selStart()
613 void MathCursor::selClearOrDel()
615 if (lyxrc.auto_region_delete)
622 void MathCursor::drawSelection(PainterInfo & pi) const
628 getSelection(i1, i2);
629 i1.par_->drawSelection(pi, i1.idx_, i1.pos_, i2.idx_, i2.pos_);
633 void MathCursor::handleNest(MathAtom const & a)
636 asArray(grabAndEraseSelection(), at.nucleus()->cell(0));
638 pushRight(prevAtom());
642 void MathCursor::getPos(int & x, int & y) const
644 par()->getPos(idx(), pos(), x, y);
648 int MathCursor::targetX() const
658 MathInset * MathCursor::par() const
660 return cursor().par_;
664 InsetFormulaBase * MathCursor::formula() const
670 MathCursor::idx_type MathCursor::idx() const
672 return cursor().idx_;
676 MathCursor::idx_type & MathCursor::idx()
678 return cursor().idx_;
682 MathCursor::pos_type MathCursor::pos() const
684 return cursor().pos_;
688 void MathCursor::adjust(pos_type from, difference_type diff)
690 if (cursor().pos_ > from)
691 cursor().pos_ += diff;
692 if (Anchor_.back().pos_ > from)
693 Anchor_.back().pos_ += diff;
694 // just to be on the safe side
695 // theoretically unecessary
700 MathCursor::pos_type & MathCursor::pos()
702 return cursor().pos_;
706 bool MathCursor::inMacroMode() const
710 MathUnknownInset const * p = prevAtom()->asUnknownInset();
711 return p && !p->final();
715 MathUnknownInset * MathCursor::activeMacro()
717 return inMacroMode() ? prevAtom().nucleus()->asUnknownInset() : 0;
721 MathUnknownInset const * MathCursor::activeMacro() const
723 return inMacroMode() ? prevAtom()->asUnknownInset() : 0;
727 bool MathCursor::inMacroArgMode() const
729 return pos() > 0 && prevAtom()->getChar() == '#';
733 bool MathCursor::selection() const
739 MathGridInset * MathCursor::enclosingGrid(MathCursor::idx_type & idx) const
741 for (MathInset::difference_type i = depth() - 1; i >= 0; --i) {
742 MathGridInset * p = Cursor_[i].par_->asGridInset();
744 idx = Cursor_[i].idx_;
752 void MathCursor::popToHere(MathInset const * p)
754 while (depth() && Cursor_.back().par_ != p)
759 void MathCursor::popToEnclosingGrid()
761 while (depth() && !Cursor_.back().par_->asGridInset())
766 void MathCursor::popToEnclosingHull()
768 while (depth() && !Cursor_.back().par_->asHullInset())
773 void MathCursor::pullArg()
776 MathArray a = array();
779 array().insert(pos(), a);
782 formula()->mutateToText();
787 void MathCursor::touch()
789 MathIterator::const_iterator it = Cursor_.begin();
790 MathIterator::const_iterator et = Cursor_.end();
791 for ( ; it != et; ++it)
796 void MathCursor::normalize()
798 if (idx() >= par()->nargs()) {
799 lyxerr << "this should not really happen - 1: "
800 << idx() << ' ' << par()->nargs()
801 << " in: " << par() << endl;
804 idx() = min(idx(), par()->nargs() - 1);
806 if (pos() > size()) {
807 lyxerr << "this should not really happen - 2: "
808 << pos() << ' ' << size() << " in idx: " << idx()
810 WriteStream wi(lyxerr, false, true);
815 pos() = min(pos(), size());
819 MathCursor::size_type MathCursor::size() const
821 return array().size();
825 bool MathCursor::hasPrevAtom() const
831 bool MathCursor::hasNextAtom() const
833 return pos() < size();
837 MathAtom const & MathCursor::prevAtom() const
839 lyx::Assert(pos() > 0);
840 return array()[pos() - 1];
844 MathAtom & MathCursor::prevAtom()
846 lyx::Assert(pos() > 0);
847 return array()[pos() - 1];
851 MathAtom const & MathCursor::nextAtom() const
853 lyx::Assert(pos() < size());
854 return array()[pos()];
858 MathAtom & MathCursor::nextAtom()
860 lyx::Assert(pos() < size());
861 return array()[pos()];
865 MathArray & MathCursor::array() const
867 static MathArray dummy;
869 if (idx() >= par()->nargs()) {
870 lyxerr << "############ idx_ " << idx() << " not valid\n";
875 lyxerr << "############ depth() == 0 not valid\n";
879 return cursor().cell();
883 void MathCursor::idxNext()
885 par()->idxNext(idx(), pos());
889 void MathCursor::idxPrev()
891 par()->idxPrev(idx(), pos());
895 char MathCursor::valign() const
898 MathGridInset * p = enclosingGrid(idx);
899 return p ? p->valign() : '\0';
903 char MathCursor::halign() const
906 MathGridInset * p = enclosingGrid(idx);
907 return p ? p->halign(idx % p->ncols()) : '\0';
911 void MathCursor::getSelection(MathCursorPos & i1, MathCursorPos & i2) const
913 MathCursorPos anc = normalAnchor();
914 if (anc < cursor()) {
924 MathCursorPos & MathCursor::cursor()
926 lyx::Assert(depth());
927 return Cursor_.back();
931 MathCursorPos const & MathCursor::cursor() const
933 lyx::Assert(depth());
934 return Cursor_.back();
938 bool MathCursor::goUpDown(bool up)
940 // Be warned: The 'logic' implemented in this function is highly fragile.
941 // A distance of one pixel or a '<' vs '<=' _really_ matters.
942 // So fiddle around with it only if you know what you are doing!
947 // check if we had something else in mind, if not, this is the future goal
953 // try neigbouring script insets
956 MathScriptInset const * p = prevAtom()->asScriptInset();
957 if (p && p->has(up)) {
960 idx() = up; // the superscript has index 1
962 ///lyxerr << "updown: handled by scriptinset to the left\n";
969 MathScriptInset const * p = nextAtom()->asScriptInset();
970 if (p && p->has(up)) {
974 ///lyxerr << "updown: handled by scriptinset to the right\n";
979 // try current cell for e.g. text insets
980 if (par()->idxUpDown2(idx(), pos(), up, targetx_))
983 //xarray().boundingBox(xlow, xhigh, ylow, yhigh);
988 //if (bruteFind(xo, yo, xlow, xhigh, ylow, yhigh)) {
989 // lyxerr << "updown: handled by brute find in the same cell\n";
993 // try to find an inset that knows better then we
995 ///lyxerr << "updown: We are in " << *par() << " idx: " << idx() << '\n';
997 if (par()->idxUpDown(idx(), pos(), up, targetx_)) {
998 // try to find best position within this inset
1004 // no such inset found, just take something "above"
1005 ///lyxerr << "updown: handled by strange case\n";
1011 up ? formula()->ylow() : yo + 4,
1012 up ? yo - 4 : formula()->yhigh()
1015 // any improvement so far?
1018 if (up ? ynew < yo : ynew > yo)
1024 bool MathCursor::bruteFind
1025 (int x, int y, int xlow, int xhigh, int ylow, int yhigh)
1027 MathIterator best_cursor;
1028 double best_dist = 1e10;
1030 MathIterator it = ibegin(formula()->par().nucleus());
1031 MathIterator et = iend(formula()->par().nucleus());
1033 // avoid invalid nesting when selecting
1034 if (!selection_ || positionable(it, Anchor_)) {
1036 it.back().getPos(xo, yo);
1037 if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
1038 double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
1039 //lyxerr << "x: " << x << " y: " << y << " d: " << endl;
1040 // '<=' in order to take the last possible position
1041 // this is important for clicking behind \sum in e.g. '\sum_i a'
1042 if (d <= best_dist) {
1054 if (best_dist < 1e10)
1055 Cursor_ = best_cursor;
1056 return best_dist < 1e10;
1060 void MathCursor::bruteFind2(int x, int y)
1062 double best_dist = 1e10;
1064 MathIterator it = Cursor_;
1065 it.back().setPos(0);
1066 MathIterator et = Cursor_;
1067 et.back().setPos(it.cell().size());
1068 for (int i = 0; ; ++i) {
1070 it.back().getPos(xo, yo);
1071 double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
1072 // '<=' in order to take the last possible position
1073 // this is important for clicking behind \sum in e.g. '\sum_i a'
1074 lyxerr << "i: " << i << " d: " << d << " best: " << best_dist << endl;
1075 if (d <= best_dist) {
1086 bool MathCursor::idxLineLast()
1088 idx() -= idx() % par()->ncols();
1089 idx() += par()->ncols() - 1;
1094 bool MathCursor::idxLeft()
1096 return par()->idxLeft(idx(), pos());
1100 bool MathCursor::idxRight()
1102 return par()->idxRight(idx(), pos());
1106 bool MathCursor::script(bool up)
1108 // Hack to get \\^ and \\_ working
1109 if (inMacroMode() && macroName() == "\\") {
1111 niceInsert(createMathInset("mathcircumflex"));
1118 string safe = grabAndEraseSelection();
1120 // we are in a nucleus of a script inset, move to _our_ script
1121 par()->asScriptInset()->ensure(up);
1124 } else if (hasPrevAtom() && prevAtom()->asScriptInset()) {
1125 prevAtom().nucleus()->asScriptInset()->ensure(up);
1126 pushRight(prevAtom());
1129 } else if (hasPrevAtom()) {
1131 array()[pos()] = MathAtom(new MathScriptInset(nextAtom(), up));
1132 pushLeft(nextAtom());
1136 plainInsert(MathAtom(new MathScriptInset(up)));
1137 prevAtom().nucleus()->asScriptInset()->ensure(up);
1138 pushRight(prevAtom());
1148 bool MathCursor::interpret(char c)
1150 //lyxerr << "interpret 2: '" << c << "'\n";
1151 targetx_ = -1; // "no target"
1152 if (inMacroArgMode()) {
1156 MathMacroTemplate const * p = formula()->par()->asMacroTemplate();
1157 if (p && 1 <= n && n <= p->numargs())
1158 insert(MathAtom(new MathMacroArgument(c - '0')));
1160 insert(createMathInset("#"));
1161 interpret(c); // try again
1167 if (inMacroMode()) {
1168 string name = macroName();
1169 //lyxerr << "interpret name: '" << name << "'\n";
1172 activeMacro()->setName(activeMacro()->name() + c);
1176 // handle 'special char' macros
1181 if (currentMode() == MathInset::TEXT_MODE)
1182 niceInsert(createMathInset("textbackslash"));
1184 niceInsert(createMathInset("backslash"));
1185 } else if (c == '{') {
1186 niceInsert(MathAtom(new MathBraceInset));
1188 niceInsert(createMathInset(string(1, c)));
1193 // leave macro mode and try again if necessary
1196 niceInsert(MathAtom(new MathBraceInset));
1202 // This is annoying as one has to press <space> far too often.
1206 // leave autocorrect mode if necessary
1207 if (autocorrect_ && c == ' ') {
1208 autocorrect_ = false;
1213 // just clear selection on pressing the space bar
1214 if (selection_ && c == ' ') {
1222 //lyxerr << "starting with macro\n";
1223 insert(MathAtom(new MathUnknownInset("\\", false)));
1228 if (currentMode() == MathInset::TEXT_MODE)
1234 if (currentMode() == MathInset::TEXT_MODE) {
1235 // insert spaces in text mode,
1236 // but suppress direct insertion of two spaces in a row
1237 // the still allows typing '<space>a<space>' and deleting the 'a', but
1238 // it is better than nothing...
1239 if (!hasPrevAtom() || prevAtom()->getChar() != ' ')
1243 if (hasPrevAtom() && prevAtom()->asSpaceInset()) {
1244 prevAtom().nucleus()->asSpaceInset()->incSpace();
1249 // if are at the very end, leave the formula
1250 return pos() != size();
1253 if (c == '{' || c == '}' || c == '#' || c == '&' || c == '$') {
1254 createMathInset(string(1, c));
1259 niceInsert(MathAtom(new MathCommentInset));
1263 // try auto-correction
1264 //if (autocorrect_ && hasPrevAtom() && math_autocorrect(prevAtom(), c))
1267 // no special circumstances, so insert the character without any fuss
1269 autocorrect_ = true;
1274 void MathCursor::setSelection(MathIterator const & where, size_type n)
1283 void MathCursor::insetToggle()
1285 if (hasNextAtom()) {
1286 // toggle previous inset ...
1287 nextAtom().nucleus()->lock(!nextAtom()->lock());
1288 } else if (popLeft() && hasNextAtom()) {
1289 // ... or enclosing inset if we are in the last inset position
1290 nextAtom().nucleus()->lock(!nextAtom()->lock());
1296 string MathCursor::info() const
1299 os << "Math editor mode. ";
1300 for (int i = 0, n = depth(); i < n; ++i) {
1301 Cursor_[i].par_->infoize(os);
1305 prevAtom()->infoize2(os);
1307 return STRCONV(os.str());
1311 unsigned MathCursor::depth() const
1313 return Cursor_.size();
1321 void region(MathCursorPos const & i1, MathCursorPos const & i2,
1322 MathInset::row_type & r1, MathInset::row_type & r2,
1323 MathInset::col_type & c1, MathInset::col_type & c2)
1325 MathInset * p = i1.par_;
1326 c1 = p->col(i1.idx_);
1327 c2 = p->col(i2.idx_);
1330 r1 = p->row(i1.idx_);
1331 r2 = p->row(i2.idx_);
1339 string MathCursor::grabSelection() const
1346 getSelection(i1, i2);
1348 if (i1.idx_ == i2.idx_) {
1349 MathArray::const_iterator it = i1.cell().begin();
1350 return asString(MathArray(it + i1.pos_, it + i2.pos_));
1355 region(i1, i2, r1, r2, c1, c2);
1358 for (row_type row = r1; row <= r2; ++row) {
1361 for (col_type col = c1; col <= c2; ++col) {
1364 data += asString(i1.par_->cell(i1.par_->index(row, col)));
1371 void MathCursor::eraseSelection()
1375 getSelection(i1, i2);
1376 if (i1.idx_ == i2.idx_)
1377 i1.cell().erase(i1.pos_, i2.pos_);
1379 MathInset * p = i1.par_;
1382 region(i1, i2, r1, r2, c1, c2);
1383 for (row_type row = r1; row <= r2; ++row)
1384 for (col_type col = c1; col <= c2; ++col)
1385 p->cell(p->index(row, col)).clear();
1391 string MathCursor::grabAndEraseSelection()
1395 string res = grabSelection();
1402 MathCursorPos MathCursor::normalAnchor() const
1404 if (Anchor_.size() < depth()) {
1406 lyxerr << "unusual Anchor size\n";
1408 //lyx::Assert(Anchor_.size() >= cursor.depth());
1409 // use Anchor on the same level as Cursor
1410 MathCursorPos normal = Anchor_[depth() - 1];
1411 if (depth() < Anchor_.size() && !(normal < cursor())) {
1412 // anchor is behind cursor -> move anchor behind the inset
1419 dispatch_result MathCursor::dispatch(FuncRequest const & cmd)
1421 // mouse clicks are somewhat special
1423 switch (cmd.action) {
1424 case LFUN_MOUSE_PRESS:
1425 case LFUN_MOUSE_MOTION:
1426 case LFUN_MOUSE_RELEASE:
1427 case LFUN_MOUSE_DOUBLE: {
1428 MathCursorPos & pos = Cursor_.back();
1429 dispatch_result res = UNDISPATCHED;
1432 if (x < cmd.x && hasPrevAtom()) {
1433 res = prevAtom().nucleus()->dispatch(cmd, pos.idx_, pos.pos_);
1434 if (res != UNDISPATCHED)
1437 if (x > cmd.x && hasNextAtom()) {
1438 res = nextAtom().nucleus()->dispatch(cmd, pos.idx_, pos.pos_);
1439 if (res != UNDISPATCHED)
1447 for (int i = Cursor_.size() - 1; i >= 0; --i) {
1448 MathCursorPos & pos = Cursor_[i];
1449 dispatch_result res = pos.par_->dispatch(cmd, pos.idx_, pos.pos_);
1450 if (res != UNDISPATCHED) {
1451 if (res == DISPATCHED_POP) {
1452 Cursor_.shrink(i + 1);
1458 return UNDISPATCHED;
1462 MathInset::mode_type MathCursor::currentMode() const
1464 for (int i = Cursor_.size() - 1; i >= 0; --i) {
1465 MathInset::mode_type res = Cursor_[i].par_->currentMode();
1466 if (res != MathInset::UNDECIDED_MODE)
1469 return MathInset::UNDECIDED_MODE;
1473 void MathCursor::handleFont(string const & font)
1478 safe = grabAndEraseSelection();
1481 if (array().size()) {
1482 // something left in the cell
1484 // cursor in first position
1486 } else if (pos() == array().size()) {
1487 // cursor in last position
1490 // cursor in between. split cell
1491 MathArray::iterator bt = array().begin();
1492 MathAtom at = createMathInset(font);
1493 at.nucleus()->cell(0) = MathArray(bt, bt + pos());
1494 cursor().cell().erase(bt, bt + pos());
1499 // nothing left in the cell
1507 void releaseMathCursor(BufferView * bv)
1510 InsetFormulaBase * f = mathcursor->formula();