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.
19 #pragma implementation
26 #include "support/lstrings.h"
31 #include "formulabase.h"
32 #include "math_cursor.h"
33 #include "math_factory.h"
34 #include "math_arrayinset.h"
35 #include "math_charinset.h"
36 #include "math_deliminset.h"
37 #include "math_matrixinset.h"
38 #include "math_scriptinset.h"
39 #include "math_spaceinset.h"
40 #include "math_specialcharinset.h"
41 #include "math_parser.h"
55 void grab(MathCursor const & cursor)
60 cursor.getSelection(i1, i2);
61 if (i1.idx_ == i2.idx_)
62 data_.push_back(MathArray(i1.cell(), i1.pos_, i2.pos_));
64 std::vector<MathInset::idx_type> indices =
65 i1.par_->idxBetween(i1.idx_, i2.idx_);
66 for (MathInset::idx_type i = 0; i < indices.size(); ++i)
67 data_.push_back(i1.cell(indices[i]));
71 void erase(MathCursor & cursor)
75 cursor.getSelection(i1, i2);
76 if (i1.idx_ == i2.idx_)
77 i1.cell().erase(i1.pos_, i2.pos_);
79 std::vector<unsigned int> indices = i1.par_->idxBetween(i1.idx_, i2.idx_);
80 for (unsigned i = 0; i < indices.size(); ++i)
81 i1.cell(indices[i]).erase();
86 void paste(MathCursor & cursor) const
88 cursor.insert(glue());
91 // glues selection to one cell
92 MathArray glue() const
95 for (unsigned i = 0; i < data_.size(); ++i)
96 ar.push_back(data_[i]);
105 std::vector<MathArray> data_;
109 Selection theSelection;
113 std::ostream & operator<<(std::ostream & os, MathCursorPos const & p)
115 os << "(par: " << p.par_ << " idx: " << p.idx_
116 << " pos: " << p.pos_ << ")";
124 MathCursor::MathCursor(InsetFormulaBase * formula)
125 : formula_(formula), lastcode_(LM_TC_VAR), selection_(false)
131 void MathCursor::pushLeft(MathInset * par)
135 par->idxFirst(p.idx_, p.pos_);
136 Cursor_.push_back(p);
140 void MathCursor::pushRight(MathInset * par)
145 par->idxLast(p.idx_, p.pos_);
146 Cursor_.push_back(p);
150 bool MathCursor::popLeft()
152 if (Cursor_.size() <= 1)
155 nextAtom()->removeEmptyScripts();
158 nextAtom()->removeEmptyScripts();
163 bool MathCursor::popRight()
165 if (Cursor_.size() <= 1)
168 nextAtom()->removeEmptyScripts();
171 nextAtom()->removeEmptyScripts();
177 MathInset * MathCursor::parInset(int i) const
179 return Cursor_[i].par_;
184 void MathCursor::dump(char const *) const
186 lyxerr << "MC: " << what << "\n";
187 for (unsigned i = 0; i < Cursor_.size(); ++i)
188 lyxerr << " i: " << i
189 << " pos: " << Cursor_[i].pos_
190 << " idx: " << Cursor_[i].idx_
191 << " par: " << Cursor_[i].par_ << "\n";
192 //lyxerr << " sel: " << selection_ << " data: " << array() << "\n";
195 void MathCursor::seldump(char const * str) const
197 //lyxerr << "SEL: " << str << ": '" << theSelection << "'\n";
200 lyxerr << "\n\n\n=================vvvvvvvvvvvvv======================= "
201 << str << "\ntheSelection: " << selection_
202 << " '" << theSelection.glue() << "'\n";
203 for (unsigned int i = 0; i < Cursor_.size(); ++i)
204 lyxerr << Cursor_[i].par_ << "\n'" << Cursor_[i].cell() << "'\n";
206 for (unsigned int i = 0; i < Anchor_.size(); ++i)
207 lyxerr << Anchor_[i].par_ << "\n'" << Anchor_[i].cell() << "'\n";
208 //lyxerr << "\ncursor.pos_: " << pos();
209 //lyxerr << "\nanchor.pos_: " << anchor().pos_;
210 lyxerr << "\n===================^^^^^^^^^^^^=====================\n\n\n";
215 void MathCursor::seldump(char const *) const {}
216 void MathCursor::dump(char const *) const {}
221 bool MathCursor::isInside(MathInset const * p) const
223 for (unsigned i = 0; i < Cursor_.size(); ++i)
224 if (parInset(i) == p)
230 bool MathCursor::openable(MathInset * p, bool sel) const
239 // we can't move into anything new during selection
240 if (Cursor_.size() == Anchor_.size())
242 if (p != Anchor_[Cursor_.size()].par_)
249 MathInset * MathCursor::positionable(MathAtom * t, int x, int y) const
255 // we can't move into anything new during selection
256 if (Cursor_.size() == Anchor_.size())
258 //if (t != Anchor_[Cursor_.size()].par_)
265 if (p && p->nargs() && p->covers(x, y))
269 if (p && p->nargs() && p->covers(x, y))
273 if (p && p->nargs() && p->covers(x, y))
280 bool MathCursor::posLeft()
289 bool MathCursor::posRight()
298 bool MathCursor::left(bool sel)
303 lastcode_ = LM_TC_VAR;
307 lastcode_ = LM_TC_VAR;
309 MathInset * p = prevInset();
310 if (openable(p, sel)) {
315 return posLeft() || idxLeft() || popLeft();
319 bool MathCursor::right(bool sel)
324 lastcode_ = LM_TC_VAR;
328 lastcode_ = LM_TC_VAR;
330 MathInset * p = nextInset();
331 if (openable(p, sel)) {
336 return posRight() || idxRight() || popRight();
340 void MathCursor::first()
343 pushLeft(outerPar());
347 void MathCursor::last()
354 void MathCursor::setPos(int x, int y)
357 //lyxerr << "MathCursor::setPos x: " << x << " y: " << y << "\n";
360 lastcode_ = LM_TC_VAR;
363 cursor().par_ = outerPar();
368 //lyxerr << "found idx: " << idx() << " cursor: " << pos() << "\n";
369 int distmin = 1 << 30; // large enough
370 for (unsigned int i = 0; i < par()->nargs(); ++i) {
371 MathXArray const & ar = par()->xcell(i);
372 int x1 = x - ar.xo();
373 int y1 = y - ar.yo();
374 int c = ar.x2pos(x1);
375 int xx = abs(x1 - ar.pos2x(c));
377 //lyxerr << "idx: " << i << " xx: " << xx << " yy: " << yy
378 // << " c: " << c << " xo: " << ar.xo() << "\n";
379 if (yy + xx <= distmin) {
385 //lyxerr << "found idx: " << idx() << " cursor: "
387 if (MathInset * p = positionable(nextAtom(), x, y))
389 else if (MathInset * p = positionable(prevAtom(), x, y))
398 void MathCursor::home(bool sel)
403 lastcode_ = LM_TC_VAR;
404 if (!par()->idxHome(idx(), pos()))
410 void MathCursor::end(bool sel)
415 lastcode_ = LM_TC_VAR;
416 if (!par()->idxEnd(idx(), pos()))
422 void MathCursor::plainErase()
424 array().erase(pos());
428 void MathCursor::insert(char c, MathTextCodes t)
430 //lyxerr << "inserting '" << c << "'\n";
431 array().insert(pos(), new MathCharInset(c, t));
436 void MathCursor::insert(MathInset * p)
447 array().insert(pos(), p); // this invalidates the pointer!
448 p = array().at(pos())->nucleus();
453 void MathCursor::niceInsert(MathInset * p)
456 lyxerr << "should not happen\n";
460 //cerr << "\n2: "; p->write(cerr, true); cerr << "\n";
461 insert(p); // inserting invalidates the pointer!
462 p = prevAtom()->nucleus();
463 //cerr << "\n3: "; p->write(cerr, true); cerr << "\n";
466 right(); // do not push for e.g. MathSymbolInset
469 p->metrics(p->size());
473 void MathCursor::insert(MathArray const & ar)
479 array().insert(pos(), ar);
484 void MathCursor::backspace()
500 void MathCursor::erase()
511 // delete empty cells if necessary
512 if (pos() == 0 && array().empty()) {
515 par()->idxDelete(idx(), popit, removeit);
516 if (popit && popLeft() && removeit)
524 // delete nucleus, keep scripts if possible
525 MathAtom * p = prevAtom();
526 MathAtom * n = nextAtom();
528 bool need_parans = (p->up() && n->up()) || (p->down() && n->down());
531 insert('{', LM_TC_TEX);
532 insert('}', LM_TC_TEX);
536 // move indices to the left
538 swap(p->up(), n->up());
540 swap(p->down(), n->down());
546 if (n->up() || n->down()) {
547 insert('{', LM_TC_TEX);
548 insert('}', LM_TC_TEX);
551 swap(p->up(), n->up());
552 swap(p->down(), n->down());
560 void MathCursor::delLine()
569 if (par()->nrows() > 1)
570 par()->delRow(row());
574 bool MathCursor::up(bool sel)
583 // check whether we could move into a superscript on the right or on the left
584 if (prevAtom() && prevAtom()->up()) {
585 pushRight(prevAtom()->up());
589 if (nextAtom() && nextAtom()->up()) {
590 pushLeft(nextAtom()->up());
598 bool MathCursor::down(bool sel)
607 // check whether we could move into an subscript on the right or on the left
608 if (prevAtom() && prevAtom()->down()) {
609 pushRight(prevAtom()->down());
613 if (nextAtom() && nextAtom()->down()) {
614 pushLeft(nextAtom()->down());
622 bool MathCursor::toggleLimits()
624 MathAtom * t = prevAtom();
627 int old = t->limits();
628 t->limits(old < 0 ? 1 : -1);
629 return old != t->limits();
633 void MathCursor::setSize(MathStyles size)
635 par()->userSetSize(size);
639 void MathCursor::macroModeClose()
641 string s = macroName();
643 pos() = pos() - s.size();
644 for (unsigned i = 0; i < s.size(); ++i)
646 lastcode_ = LM_TC_VAR;
652 string MathCursor::macroName() const
655 for (int i = pos() - 1; i >= 0; --i) {
656 MathInset * p = array().at(i)->nucleus();
657 if (p && p->code() == LM_TC_TEX)
658 s = p->getChar() + s;
666 void MathCursor::selCopy()
670 theSelection.grab(*this);
676 void MathCursor::selCut()
680 theSelection.grab(*this);
681 theSelection.erase(*this);
684 theSelection.clear();
689 void MathCursor::selDel()
693 theSelection.erase(*this);
699 void MathCursor::selPaste()
702 theSelection.paste(*this);
707 void MathCursor::selHandle(bool sel)
709 if (sel == selection_)
712 theSelection.clear();
718 void MathCursor::selStart()
724 theSelection.clear();
730 void MathCursor::selClear()
737 void MathCursor::drawSelection(Painter & pain) const
744 getSelection(i1, i2);
746 //lyxerr << "selection from: " << i1 << " to " << i2 << "\n";
748 if (i1.idx_ == i2.idx_) {
749 MathXArray & c = i1.xcell();
750 int x1 = c.xo() + c.pos2x(i1.pos_);
751 int y1 = c.yo() - c.ascent();
752 int x2 = c.xo() + c.pos2x(i2.pos_);
753 int y2 = c.yo() + c.descent();
754 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
756 std::vector<unsigned int> indices = i1.par_->idxBetween(i1.idx_, i2.idx_);
757 for (unsigned i = 0; i < indices.size(); ++i) {
758 MathXArray & c = i1.xcell(indices[i]);
760 int y1 = c.yo() - c.ascent();
761 int x2 = c.xo() + c.width();
762 int y2 = c.yo() + c.descent();
763 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
769 MathTextCodes MathCursor::nextCode() const
771 //return (pos() == size()) ? LM_TC_VAR : nextInset()->code();
776 void MathCursor::handleFont(MathTextCodes t)
782 getSelection(i1, i2);
783 if (i1.idx_ == i2.idx_) {
784 MathArray & ar = i1.cell();
785 for (unsigned int pos = i1.pos_; pos != i2.pos_; ++pos) {
786 MathInset * p = ar.at(pos)->nucleus();
792 lastcode_ = (lastcode_ == t) ? LM_TC_VAR : t;
796 void MathCursor::handleDelim(string const & l, string const & r)
798 handleNest(new MathDelimInset(l, r));
802 void MathCursor::handleNest(MathInset * p)
806 p->cell(0) = theSelection.glue();
808 insert(p); // this invalidates p!
809 p = prevAtom()->nucleus();
814 void MathCursor::getPos(int & x, int & y)
817 #warning This should probably take cellXOffset and cellYOffset into account
819 x = xarray().xo() + xarray().pos2x(pos());
824 MathInset * MathCursor::par() const
826 return cursor().par_;
830 InsetFormulaBase const * MathCursor::formula()
836 unsigned int MathCursor::idx() const
838 return cursor().idx_;
842 unsigned int & MathCursor::idx()
844 return cursor().idx_;
848 unsigned int MathCursor::pos() const
850 return cursor().pos_;
854 unsigned int & MathCursor::pos()
856 return cursor().pos_;
860 bool MathCursor::inMacroMode() const
862 return lastcode_ == LM_TC_TEX;
866 bool MathCursor::selection() const
872 MathArrayInset * MathCursor::enclosingArray(unsigned int & idx) const
874 for (int i = Cursor_.size() - 1; i >= 0; --i) {
875 if (Cursor_[i].par_->isArray()) {
876 idx = Cursor_[i].idx_;
877 return static_cast<MathArrayInset *>(Cursor_[i].par_);
884 void MathCursor::pullArg(bool goright)
888 MathArray a = array();
891 array().insert(pos(), a);
898 MathStyles MathCursor::style() const
900 return xarray().style();
904 void MathCursor::normalize() const
907 #warning This is evil!
909 MathCursor * it = const_cast<MathCursor *>(this);
911 if (idx() >= par()->nargs()) {
912 lyxerr << "this should not really happen - 1: "
913 << idx() << " " << par()->nargs() << "\n";
916 it->idx() = min(idx(), par()->nargs() - 1);
918 if (pos() > size()) {
919 lyxerr << "this should not really happen - 2: "
920 << pos() << " " << size() << "\n";
923 it->pos() = min(pos(), size());
927 unsigned int MathCursor::size() const
929 return array().size();
933 unsigned int MathCursor::col() const
935 return par()->col(idx());
939 unsigned int MathCursor::row() const
941 return par()->row(idx());
946 char MathCursorPos::getChar() const
948 return array().getChar(pos());
952 string MathCursorPos::readString()
955 int code = nextCode();
956 for ( ; OK() && nextCode() == code; Next())
964 MathInset * MathCursor::prevInset() const
966 return prevAtom() ? prevAtom()->nucleus() : 0;
970 MathInset * MathCursor::nextInset() const
972 return nextAtom() ? nextAtom()->nucleus() : 0;
976 MathSpaceInset * MathCursor::prevSpaceInset() const
978 MathInset * p = prevInset();
979 return (p && p->isSpaceInset()) ? static_cast<MathSpaceInset *>(p) : 0;
983 MathAtom const * MathCursor::prevAtom() const
985 return array().at(pos() - 1);
989 MathAtom * MathCursor::prevAtom()
991 return array().at(pos() - 1);
995 MathAtom const * MathCursor::nextAtom() const
997 return array().at(pos());
1001 MathAtom * MathCursor::nextAtom()
1003 return array().at(pos());
1007 MathArray & MathCursor::array() const
1009 static MathArray dummy;
1011 lyxerr << "############ par_ not valid\n";
1015 if (idx() >= par()->nargs()) {
1016 lyxerr << "############ idx_ " << idx() << " not valid\n";
1020 return cursor().cell();
1024 MathXArray & MathCursor::xarray() const
1026 return cursor().xcell();
1030 void MathCursor::idxNext()
1032 par()->idxNext(idx(), pos());
1036 void MathCursor::idxPrev()
1038 par()->idxPrev(idx(), pos());
1042 void MathCursor::splitCell()
1044 if (idx() == par()->nargs() - 1)
1046 MathArray ar = array();
1048 array().erase(pos(), size());
1051 array().insert(0, ar);
1055 void MathCursor::breakLine()
1057 // leave inner cells
1061 MathMatrixInset * p = outerPar();
1062 if (p->getType() == LM_OT_SIMPLE || p->getType() == LM_OT_EQUATION) {
1063 p->mutate(LM_OT_EQNARRAY);
1070 const unsigned int r = row();
1071 for (unsigned int c = col() + 1; c < p->ncols(); ++c) {
1072 const unsigned int i1 = p->index(r, c);
1073 const unsigned int i2 = p->index(r + 1, c);
1074 lyxerr << "swapping cells " << i1 << " and " << i2 << "\n";
1075 p->cell(i1).swap(p->cell(i2));
1080 p->cell(idx()).swap(p->cell(idx() + p->ncols() - 1));
1085 char MathCursor::valign() const
1088 MathArrayInset * p = enclosingArray(idx);
1089 return p ? p->valign() : 0;
1093 char MathCursor::halign() const
1096 MathArrayInset * p = enclosingArray(idx);
1097 return p ? p->halign(idx % p->ncols()) : 0;
1101 void MathCursor::getSelection(MathCursorPos & i1, MathCursorPos & i2) const
1103 MathCursorPos anc = normalAnchor();
1104 if (anc < cursor()) {
1114 MathCursorPos & MathCursor::cursor()
1116 return Cursor_.back();
1120 MathCursorPos const & MathCursor::cursor() const
1122 return Cursor_.back();
1126 unsigned int MathCursor::cellXOffset() const
1128 return par()->cellXOffset(idx());
1132 unsigned int MathCursor::cellYOffset() const
1134 return par()->cellYOffset(idx());
1138 int MathCursor::xpos() const
1140 return cellXOffset() + xarray().pos2x(pos());
1144 int MathCursor::ypos() const
1146 return cellYOffset();
1151 void MathCursor::gotoX(int x)
1153 pos() = xarray().x2pos(x - cellXOffset());
1157 bool MathCursor::goUp()
1159 // first ask the inset if it knows better then we
1160 if (par()->idxUp(idx(), pos()))
1163 // leave subscript to the nearest side
1164 if (par()->asScriptInset() && par()->asScriptInset()->down()) {
1165 if (pos() <= size() / 2)
1172 // if not, apply brute force.
1176 std::vector<MathCursorPos> save = Cursor_;
1177 y0 -= xarray().ascent();
1178 for (int y = y0 - 4; y > outerPar()->yo() - outerPar()->ascent(); y -= 4) {
1180 if (save != Cursor_ && xarray().yo() < y0)
1188 bool MathCursor::goDown()
1190 // first ask the inset if it knows better then we
1191 if (par()->idxDown(idx(), pos()))
1194 // leave superscript to the nearest side
1195 if (par()->asScriptInset() && par()->asScriptInset()->up()) {
1196 if (pos() <= size() / 2)
1203 // if not, apply brute force.
1207 std::vector<MathCursorPos> save = Cursor_;
1208 y0 += xarray().descent();
1209 for (int y = y0 + 4; y < outerPar()->yo() + outerPar()->descent(); y += 4) {
1211 if (save != Cursor_ && xarray().yo() > y0)
1219 bool MathCursor::idxLeft()
1221 return par()->idxLeft(idx(), pos());
1225 bool MathCursor::idxRight()
1227 return par()->idxRight(idx(), pos());
1231 MathMatrixInset * MathCursor::outerPar() const
1234 static_cast<MathMatrixInset *>(const_cast<MathInset *>(formula_->par()));
1238 void MathCursor::interpret(string const & s)
1240 //lyxerr << "interpret: '" << s << "'\n";
1241 //lyxerr << "in: " << in_word_set(s) << " \n";
1248 //lyxerr << "char: '" << c << "' int: " << int(c) << endl;
1249 //owner_->getIntl()->getTrans().TranslateAndInsert(c, lt);
1250 //lyxerr << "trans: '" << c << "' int: " << int(c) << endl;
1252 if (s.size() > 7 && s.substr(0, 7) == "matrix ") {
1257 istringstream is(s.substr(7).c_str());
1258 is >> m >> n >> v_align >> h_align;
1259 m = std::max(1u, m);
1260 n = std::max(1u, n);
1262 MathArrayInset * p = new MathArrayInset(m, n);
1263 p->valign(v_align[0]);
1269 if (s == "\\over" || s == "\\choose" || s == "\\atop") {
1270 MathArray ar = array();
1271 MathInset * p = createMathInset(s.substr(1));
1272 p->cell(0).swap(array());
1281 niceInsert(createMathInset(s.substr(1)));
1286 // we got just a single char now
1288 if (c == '^' || c == '_') {
1289 bool const up = (s[0] == '^');
1292 insert('{', LM_TC_TEX);
1293 insert('}', LM_TC_TEX);
1295 MathInset * par = prevAtom()->ensure(up);
1304 if (lastcode_ == LM_TC_TEXTRM) {
1305 insert(c, LM_TC_TEXTRM);
1310 if (inMacroMode()) {
1312 lastcode_ = LM_TC_VAR;
1316 MathSpaceInset * p = prevSpaceInset();
1322 if (mathcursor->popRight())
1326 // this would not work if the inset is in an table!
1327 //bv->text->cursorRight(bv, true);
1328 //result = FINISHED;
1332 if (lastcode_ != LM_TC_TEX && strchr("#$%{}", c)) {
1333 insert(new MathSpecialCharInset(c));
1334 lastcode_ = LM_TC_VAR;
1338 if (lastcode_ == LM_TC_TEX) {
1339 if (macroName().empty()) {
1340 if (strchr("$%{}", c)) {
1341 insert(new MathCharInset(c, LM_TC_TEX));
1342 lastcode_ = LM_TC_VAR;
1345 insert(c, LM_TC_TEX);
1346 if (!isalpha(c) && c != '#') {
1348 lastcode_ = LM_TC_VAR;
1351 if ('1' <= c && c <= '9' && macroName() == "#") {
1352 insert(c, LM_TC_TEX);
1354 lastcode_ = LM_TC_VAR;
1356 else if (isalpha(c))
1357 insert(c, LM_TC_TEX);
1360 lastcode_ = LM_TC_VAR;
1366 if (isalpha(c) && (lastcode_ == LM_TC_GREEK || lastcode_ == LM_TC_GREEK1)) {
1367 static char const greekl[][26] =
1368 {"alpha", "beta", "chi", "delta", "epsilon", "phi",
1369 "gamma", "eta", "iota", "", "kappa", "lambda", "mu",
1370 "nu", "omikron", "pi", "omega", "rho", "sigma",
1371 "tau", "upsilon", "theta", "", "xi", "upsilon", "zeta"};
1372 static char const greeku[][26] =
1373 {"Alpha", "Beta", "Chi", "Delta", "Epsilon", "Phi",
1374 "Gamma", "Eta", "Iota", "", "Kappa", "Lambda", "Mu",
1375 "Nu", "Omikron", "Pi", "Omega", "Rho", "Sigma", "Tau",
1376 "Upsilon", "Theta", "", "xi", "Upsilon", "Zeta"};
1378 latexkeys const * l = 0;
1379 if ('a' <= c && c <= 'z')
1380 l = in_word_set(greekl[c - 'a']);
1381 if ('A' <= c && c <= 'Z')
1382 l = in_word_set(greeku[c - 'A']);
1385 insert(createMathInset(l));
1387 insert(c, LM_TC_VAR);
1389 #warning greek insert problem? look here!
1390 if (lastcode_ == LM_TC_GREEK1)
1391 lastcode_ = LM_TC_VAR;
1396 lastcode_ = LM_TC_TEX;
1397 //bv->owner()->message(_("TeX mode"));
1401 // no special circumstances, so insert the character without any fuss
1407 ////////////////////////////////////////////////////////////////////////
1410 bool operator==(MathCursorPos const & ti, MathCursorPos const & it)
1412 return ti.par_ == it.par_ && ti.idx_ == it.idx_ && ti.pos_ == it.pos_;
1416 bool operator<(MathCursorPos const & ti, MathCursorPos const & it)
1418 if (ti.par_ != it.par_) {
1419 lyxerr << "can't compare cursor and anchor in different insets\n";
1422 if (ti.idx_ != it.idx_)
1423 return ti.idx_ < it.idx_;
1424 return ti.pos_ < it.pos_;
1428 MathArray & MathCursorPos::cell(unsigned int idx) const
1430 return par_->cell(idx);
1434 MathArray & MathCursorPos::cell() const
1436 return par_->cell(idx_);
1440 MathXArray & MathCursorPos::xcell(unsigned int idx) const
1442 return par_->xcell(idx);
1446 MathXArray & MathCursorPos::xcell() const
1448 return par_->xcell(idx_);
1452 MathCursorPos MathCursor::normalAnchor() const
1454 // use Anchor on the same level as Cursor
1455 MathCursorPos normal = Anchor_[Cursor_.size() - 1];
1456 if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) {
1457 // anchor is behind cursor -> move anchor behind the inset