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.
22 #include "support/lstrings.h"
23 #include "support/LAssert.h"
25 #include "frontends/Painter.h"
26 #include "math_cursor.h"
27 #include "formulabase.h"
28 #include "funcrequest.h"
29 #include "math_autocorrect.h"
30 #include "math_braceinset.h"
31 #include "math_commentinset.h"
32 #include "math_charinset.h"
33 #include "math_extern.h"
34 #include "math_factory.h"
35 #include "math_fontinset.h"
36 #include "math_gridinset.h"
37 #include "math_iterator.h"
38 #include "math_macroarg.h"
39 #include "math_macrotemplate.h"
40 #include "math_mathmlstream.h"
41 #include "math_scriptinset.h"
42 #include "math_spaceinset.h"
43 #include "math_support.h"
44 #include "math_unknowninset.h"
56 using std::ostringstream;
60 // matheds own cut buffer
64 MathCursor::MathCursor(InsetFormulaBase * formula, bool front)
65 : formula_(formula), autocorrect_(false), selection_(false), targetx_(-1)
67 front ? first() : last();
72 MathCursor::~MathCursor()
74 // ensure that 'notifyCursorLeave' is called
80 void MathCursor::push(MathAtom & t)
82 Cursor_.push_back(MathCursorPos(t.nucleus()));
86 void MathCursor::pushLeft(MathAtom & t)
88 //lyxerr << "Entering atom " << t << " left\n";
90 t->idxFirst(idx(), pos());
94 void MathCursor::pushRight(MathAtom & t)
96 //lyxerr << "Entering atom " << t << " right\n";
99 t->idxLast(idx(), pos());
103 bool MathCursor::popLeft()
105 //lyxerr << "Leaving atom to the left\n";
108 par()->notifyCursorLeaves(idx());
111 par()->notifyCursorLeaves(idx());
117 bool MathCursor::popRight()
119 //lyxerr << "Leaving atom "; par()->write(cerr, false); cerr << " right\n";
122 par()->notifyCursorLeaves(idx());
125 par()->notifyCursorLeaves(idx());
134 void MathCursor::dump(char const * what) const
136 lyxerr << "MC: " << what << endl;
137 lyxerr << " Cursor: " << depth() << endl;
138 for (unsigned i = 0; i < depth(); ++i)
139 lyxerr << " i: " << i << ' ' << Cursor_[i] << endl;
140 lyxerr << " Anchor: " << Anchor_.size() << endl;
141 for (unsigned i = 0; i < Anchor_.size(); ++i)
142 lyxerr << " i: " << i << ' ' << Anchor_[i] << endl;
143 lyxerr << " sel: " << selection_ << endl;
146 void MathCursor::dump(char const *) const {}
150 bool MathCursor::isInside(MathInset const * p) const
152 for (unsigned i = 0; i < depth(); ++i)
153 if (Cursor_[i].par_ == p)
159 bool MathCursor::openable(MathAtom const & t, bool sel) const
168 // we can't move into anything new during selection
169 if (depth() == Anchor_.size())
171 if (t.operator->() != Anchor_[depth()].par_)
178 bool MathCursor::inNucleus() const
180 return par()->asScriptInset() && idx() == 2;
184 bool MathCursor::posLeft()
193 bool MathCursor::posRight()
202 bool MathCursor::left(bool sel)
205 autocorrect_ = false;
206 targetx_ = -1; // "no target"
213 if (hasPrevAtom() && openable(prevAtom(), sel)) {
214 pushRight(prevAtom());
218 return posLeft() || idxLeft() || popLeft() || selection_;
222 bool MathCursor::right(bool sel)
225 autocorrect_ = false;
226 targetx_ = -1; // "no target"
233 if (hasNextAtom() && openable(nextAtom(), sel)) {
234 pushLeft(nextAtom());
238 return posRight() || idxRight() || popRight() || selection_;
242 void MathCursor::first()
245 push(formula_->par());
246 par()->idxFirst(idx(), pos());
250 void MathCursor::last()
253 push(formula_->par());
254 par()->idxLast(idx(), pos());
259 (MathIterator const & cursor, MathIterator const & anchor)
261 // avoid deeper nested insets when selecting
262 if (cursor.size() > anchor.size())
265 // anchor might be deeper, should have same path then
266 for (MathIterator::size_type i = 0; i < cursor.size(); ++i)
267 if (cursor[i].par_ != anchor[i].par_)
270 // position should be ok.
275 void MathCursor::setPos(int x, int y)
278 bool res = bruteFind(x, y,
279 formula()->xlow(), formula()->xhigh(),
280 formula()->ylow(), formula()->yhigh());
282 // this can happen on creation of "math-display"
286 targetx_ = -1; // "no target"
292 bool MathCursor::home(bool sel)
295 autocorrect_ = false;
298 if (!par()->idxHome(idx(), pos()))
301 targetx_ = -1; // "no target"
306 bool MathCursor::end(bool sel)
309 autocorrect_ = false;
312 if (!par()->idxEnd(idx(), pos()))
315 targetx_ = -1; // "no target"
320 void MathCursor::plainErase()
322 array().erase(pos());
326 void MathCursor::markInsert()
328 //lyxerr << "inserting mark\n";
329 array().insert(pos(), MathAtom(new MathCharInset(0)));
333 void MathCursor::markErase()
335 //lyxerr << "deleting mark\n";
336 array().erase(pos());
340 void MathCursor::plainInsert(MathAtom const & t)
343 array().insert(pos(), t);
348 void MathCursor::insert(string const & str)
350 //lyxerr << "inserting '" << str << "'\n";
352 for (string::const_iterator it = str.begin(); it != str.end(); ++it)
353 plainInsert(MathAtom(new MathCharInset(*it)));
357 void MathCursor::insert(char c)
359 //lyxerr << "inserting '" << c << "'\n";
361 plainInsert(MathAtom(new MathCharInset(c)));
365 void MathCursor::insert(MathAtom const & t)
373 void MathCursor::niceInsert(string const & t)
375 MathArray ar = asArray(t);
383 void MathCursor::niceInsert(MathAtom const & t)
386 string safe = grabAndEraseSelection();
388 // enter the new inset and move the contents of the selection if possible
391 pushLeft(nextAtom());
397 void MathCursor::insert(MathArray const & ar)
402 array().insert(pos(), ar);
407 void MathCursor::paste(string const & data)
409 dispatch(FuncRequest(LFUN_PASTE, data));
413 bool MathCursor::backspace()
415 autocorrect_ = false;
423 if (par()->ncols() == 1 &&
424 par()->nrows() == 1 &&
433 MathUnknownInset * p = activeMacro();
434 if (p->name().size() > 1) {
435 p->setName(p->name().substr(0, p->name().size() - 1));
446 bool MathCursor::erase()
448 autocorrect_ = false;
457 // delete empty cells if possible
459 if (par()->idxDelete(idx()))
462 // old behaviour when in last position of cell
463 if (pos() == size()) {
464 if (par()->ncols() == 1 && par()->nrows() == 1 && depth() == 1 && size() == 0)
467 par()->idxGlue(idx());
477 bool MathCursor::up(bool sel)
482 MathIterator save = Cursor_;
486 autocorrect_ = false;
491 bool MathCursor::down(bool sel)
496 MathIterator save = Cursor_;
500 autocorrect_ = false;
505 void MathCursor::macroModeClose()
509 MathUnknownInset * p = activeMacro();
511 string s = p->name();
513 array().erase(pos());
515 // do nothing if the macro name is empty
519 string name = s.substr(1);
521 // prevent entering of recursive macros
522 if (formula()->lyxCode() == Inset::MATHMACRO_CODE
523 && formula()->getInsetName() == name)
524 lyxerr << "can't enter recursive macro\n";
526 niceInsert(createMathInset(name));
530 string MathCursor::macroName() const
532 return inMacroMode() ? activeMacro()->name() : string();
536 void MathCursor::selClear()
543 void MathCursor::selCopy()
547 theCutBuffer = grabSelection();
550 theCutBuffer.erase();
555 void MathCursor::selCut()
558 theCutBuffer = grabAndEraseSelection();
562 void MathCursor::selDel()
572 void MathCursor::selPaste()
582 void MathCursor::selHandle(bool sel)
584 if (sel == selection_)
592 void MathCursor::selStart()
602 void MathCursor::selClearOrDel()
604 if (lyxrc.auto_region_delete)
611 void MathCursor::drawSelection(PainterInfo & pi) const
617 getSelection(i1, i2);
618 i1.par_->drawSelection(pi, i1.idx_, i1.pos_, i2.idx_, i2.pos_);
622 void MathCursor::handleNest(MathAtom const & a)
625 at.nucleus()->cell(0) = asArray(grabAndEraseSelection());
627 pushRight(prevAtom());
631 void MathCursor::getPos(int & x, int & y) const
633 par()->getPos(idx(), pos(), x, y);
637 int MathCursor::targetX() const
647 MathInset * MathCursor::par() const
649 return cursor().par_;
653 InsetFormulaBase * MathCursor::formula() const
659 MathCursor::idx_type MathCursor::idx() const
661 return cursor().idx_;
665 MathCursor::idx_type & MathCursor::idx()
667 return cursor().idx_;
671 MathCursor::pos_type MathCursor::pos() const
673 return cursor().pos_;
677 void MathCursor::adjust(pos_type from, difference_type diff)
679 if (cursor().pos_ > from)
680 cursor().pos_ += diff;
681 if (Anchor_.back().pos_ > from)
682 Anchor_.back().pos_ += diff;
683 // just to be on the safe side
684 // theoretically unecessary
689 MathCursor::pos_type & MathCursor::pos()
691 return cursor().pos_;
695 bool MathCursor::inMacroMode() const
699 MathUnknownInset const * p = prevAtom()->asUnknownInset();
700 return p && !p->final();
704 MathUnknownInset * MathCursor::activeMacro()
706 return inMacroMode() ? prevAtom().nucleus()->asUnknownInset() : 0;
710 MathUnknownInset const * MathCursor::activeMacro() const
712 return inMacroMode() ? prevAtom()->asUnknownInset() : 0;
716 bool MathCursor::inMacroArgMode() const
718 return pos() > 0 && prevAtom()->getChar() == '#';
722 bool MathCursor::selection() const
728 MathGridInset * MathCursor::enclosingGrid(MathCursor::idx_type & idx) const
730 for (MathInset::difference_type i = depth() - 1; i >= 0; --i) {
731 MathGridInset * p = Cursor_[i].par_->asGridInset();
733 idx = Cursor_[i].idx_;
741 void MathCursor::popToHere(MathInset const * p)
743 while (depth() && Cursor_.back().par_ != p)
748 void MathCursor::popToEnclosingGrid()
750 while (depth() && !Cursor_.back().par_->asGridInset())
755 void MathCursor::popToEnclosingHull()
757 while (depth() && !Cursor_.back().par_->asHullInset())
762 void MathCursor::pullArg()
765 MathArray a = array();
768 array().insert(pos(), a);
771 formula()->mutateToText();
776 void MathCursor::touch()
778 MathIterator::const_iterator it = Cursor_.begin();
779 MathIterator::const_iterator et = Cursor_.end();
780 for ( ; it != et; ++it)
785 void MathCursor::normalize()
787 if (idx() >= par()->nargs()) {
788 lyxerr << "this should not really happen - 1: "
789 << idx() << ' ' << par()->nargs()
790 << " in: " << par() << endl;
793 idx() = min(idx(), par()->nargs() - 1);
795 if (pos() > size()) {
796 lyxerr << "this should not really happen - 2: "
797 << pos() << ' ' << size() << " in idx: " << idx()
799 WriteStream wi(lyxerr, false, true);
804 pos() = min(pos(), size());
808 MathCursor::size_type MathCursor::size() const
810 return array().size();
814 bool MathCursor::hasPrevAtom() const
820 bool MathCursor::hasNextAtom() const
822 return pos() < size();
826 MathAtom const & MathCursor::prevAtom() const
828 lyx::Assert(pos() > 0);
829 return array()[pos() - 1];
833 MathAtom & MathCursor::prevAtom()
835 lyx::Assert(pos() > 0);
836 return array()[pos() - 1];
840 MathAtom const & MathCursor::nextAtom() const
842 lyx::Assert(pos() < size());
843 return array()[pos()];
847 MathAtom & MathCursor::nextAtom()
849 lyx::Assert(pos() < size());
850 return array()[pos()];
854 MathArray & MathCursor::array() const
856 static MathArray dummy;
858 if (idx() >= par()->nargs()) {
859 lyxerr << "############ idx_ " << idx() << " not valid\n";
864 lyxerr << "############ depth() == 0 not valid\n";
868 return cursor().cell();
872 void MathCursor::idxNext()
874 par()->idxNext(idx(), pos());
878 void MathCursor::idxPrev()
880 par()->idxPrev(idx(), pos());
884 char MathCursor::valign() const
887 MathGridInset * p = enclosingGrid(idx);
888 return p ? p->valign() : '\0';
892 char MathCursor::halign() const
895 MathGridInset * p = enclosingGrid(idx);
896 return p ? p->halign(idx % p->ncols()) : '\0';
900 void MathCursor::getSelection(MathCursorPos & i1, MathCursorPos & i2) const
902 MathCursorPos anc = normalAnchor();
903 if (anc < cursor()) {
913 MathCursorPos & MathCursor::cursor()
915 lyx::Assert(depth());
916 return Cursor_.back();
920 MathCursorPos const & MathCursor::cursor() const
922 lyx::Assert(depth());
923 return Cursor_.back();
927 bool MathCursor::goUpDown(bool up)
929 // Be warned: The 'logic' implemented in this function is highly fragile.
930 // A distance of one pixel or a '<' vs '<=' _really_ matters.
931 // So fiddle around with it only if you know what you are doing!
936 // check if we had something else in mind, if not, this is the future goal
942 // try neigbouring script insets
945 MathScriptInset const * p = prevAtom()->asScriptInset();
946 if (p && p->has(up)) {
949 idx() = up; // the superscript has index 1
951 ///lyxerr << "updown: handled by scriptinset to the left\n";
958 MathScriptInset const * p = nextAtom()->asScriptInset();
959 if (p && p->has(up)) {
963 ///lyxerr << "updown: handled by scriptinset to the right\n";
968 // try current cell for e.g. text insets
969 if (par()->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\n";
982 // try to find an inset that knows better then we
984 ///lyxerr << "updown: We are in " << *par() << " idx: " << idx() << '\n';
986 if (par()->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\n";
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() % par()->ncols();
1078 idx() += par()->ncols() - 1;
1083 bool MathCursor::idxLeft()
1085 return par()->idxLeft(idx(), pos());
1089 bool MathCursor::idxRight()
1091 return par()->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 par()->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 << "'\n";
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 << "'\n";
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\n";
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();
1247 if (c == '{' || c == '}') {
1248 niceInsert(createMathInset(string(1, c)));
1253 insert(createMathInset("$"));
1258 niceInsert(MathAtom(new MathCommentInset));
1262 // try auto-correction
1263 //if (autocorrect_ && hasPrevAtom() && math_autocorrect(prevAtom(), c))
1266 // no special circumstances, so insert the character without any fuss
1268 autocorrect_ = true;
1273 void MathCursor::setSelection(MathIterator const & where, size_type n)
1282 void MathCursor::insetToggle()
1284 if (hasNextAtom()) {
1285 // toggle previous inset ...
1286 nextAtom().nucleus()->lock(!nextAtom()->lock());
1287 } else if (popLeft() && hasNextAtom()) {
1288 // ... or enclosing inset if we are in the last inset position
1289 nextAtom().nucleus()->lock(!nextAtom()->lock());
1295 string MathCursor::info() const
1298 os << "Math editor mode. ";
1299 for (int i = 0, n = depth(); i < n; ++i) {
1300 Cursor_[i].par_->infoize(os);
1304 prevAtom()->infoize2(os);
1306 return STRCONV(os.str());
1310 unsigned MathCursor::depth() const
1312 return Cursor_.size();
1320 void region(MathCursorPos const & i1, MathCursorPos const & i2,
1321 MathInset::row_type & r1, MathInset::row_type & r2,
1322 MathInset::col_type & c1, MathInset::col_type & c2)
1324 MathInset * p = i1.par_;
1325 c1 = p->col(i1.idx_);
1326 c2 = p->col(i2.idx_);
1329 r1 = p->row(i1.idx_);
1330 r2 = p->row(i2.idx_);
1338 string MathCursor::grabSelection() const
1345 getSelection(i1, i2);
1347 if (i1.idx_ == i2.idx_) {
1348 MathArray::const_iterator it = i1.cell().begin();
1349 return asString(MathArray(it + i1.pos_, it + i2.pos_));
1354 region(i1, i2, r1, r2, c1, c2);
1357 for (row_type row = r1; row <= r2; ++row) {
1360 for (col_type col = c1; col <= c2; ++col) {
1363 data += asString(i1.par_->cell(i1.par_->index(row, col)));
1370 void MathCursor::eraseSelection()
1374 getSelection(i1, i2);
1375 if (i1.idx_ == i2.idx_)
1376 i1.cell().erase(i1.pos_, i2.pos_);
1378 MathInset * p = i1.par_;
1381 region(i1, i2, r1, r2, c1, c2);
1382 for (row_type row = r1; row <= r2; ++row)
1383 for (col_type col = c1; col <= c2; ++col)
1384 p->cell(p->index(row, col)).clear();
1390 string MathCursor::grabAndEraseSelection()
1394 string res = grabSelection();
1401 MathCursorPos MathCursor::normalAnchor() const
1403 if (Anchor_.size() < depth()) {
1405 lyxerr << "unusual Anchor size\n";
1407 //lyx::Assert(Anchor_.size() >= cursor.depth());
1408 // use Anchor on the same level as Cursor
1409 MathCursorPos normal = Anchor_[depth() - 1];
1410 if (depth() < Anchor_.size() && !(normal < cursor())) {
1411 // anchor is behind cursor -> move anchor behind the inset
1418 dispatch_result MathCursor::dispatch(FuncRequest const & cmd)
1420 // mouse clicks are somewhat special
1422 switch (cmd.action) {
1423 case LFUN_MOUSE_PRESS:
1424 case LFUN_MOUSE_MOTION:
1425 case LFUN_MOUSE_RELEASE:
1426 case LFUN_MOUSE_DOUBLE: {
1427 MathCursorPos & pos = Cursor_.back();
1428 dispatch_result res = UNDISPATCHED;
1431 if (x < cmd.x && hasPrevAtom()) {
1432 res = prevAtom().nucleus()->dispatch(cmd, pos.idx_, pos.pos_);
1433 if (res != UNDISPATCHED)
1436 if (x > cmd.x && hasNextAtom()) {
1437 res = nextAtom().nucleus()->dispatch(cmd, pos.idx_, pos.pos_);
1438 if (res != UNDISPATCHED)
1446 for (int i = Cursor_.size() - 1; i >= 0; --i) {
1447 MathCursorPos & pos = Cursor_[i];
1448 dispatch_result res = pos.par_->dispatch(cmd, pos.idx_, pos.pos_);
1449 if (res != UNDISPATCHED) {
1450 if (res == DISPATCHED_POP) {
1451 Cursor_.shrink(i + 1);
1457 return UNDISPATCHED;
1461 MathInset::mode_type MathCursor::currentMode() const
1463 for (int i = Cursor_.size() - 1; i >= 0; --i) {
1464 MathInset::mode_type res = Cursor_[i].par_->currentMode();
1465 if (res != MathInset::UNDECIDED_MODE)
1468 return MathInset::UNDECIDED_MODE;
1472 void MathCursor::handleFont(string const & font)
1477 safe = grabAndEraseSelection();
1480 if (array().size()) {
1481 // something left in the cell
1483 // cursor in first position
1485 } else if (pos() == array().size()) {
1486 // cursor in last position
1489 // cursor in between. split cell
1490 MathArray::iterator bt = array().begin();
1491 MathAtom at = createMathInset(font);
1492 at.nucleus()->cell(0) = MathArray(bt, bt + pos());
1493 cursor().cell().erase(bt, bt + pos());
1498 // nothing left in the cell
1506 void releaseMathCursor(BufferView * bv)
1509 InsetFormulaBase * f = mathcursor->formula();
1510 f->hideInsetCursor(bv);