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<MathInset::idx_type> 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();
179 void MathCursor::dump(char const *) const
181 lyxerr << "MC: " << what << "\n";
182 for (unsigned i = 0; i < Cursor_.size(); ++i)
183 lyxerr << " i: " << i
184 << " pos: " << Cursor_[i].pos_
185 << " idx: " << Cursor_[i].idx_
186 << " par: " << Cursor_[i].par_ << "\n";
187 //lyxerr << " sel: " << selection_ << " data: " << array() << "\n";
190 void MathCursor::seldump(char const * str) const
192 //lyxerr << "SEL: " << str << ": '" << theSelection << "'\n";
195 lyxerr << "\n\n\n=================vvvvvvvvvvvvv======================= "
196 << str << "\ntheSelection: " << selection_
197 << " '" << theSelection.glue() << "'\n";
198 for (unsigned int i = 0; i < Cursor_.size(); ++i)
199 lyxerr << Cursor_[i].par_ << "\n'" << Cursor_[i].cell() << "'\n";
201 for (unsigned int i = 0; i < Anchor_.size(); ++i)
202 lyxerr << Anchor_[i].par_ << "\n'" << Anchor_[i].cell() << "'\n";
203 //lyxerr << "\ncursor.pos_: " << pos();
204 //lyxerr << "\nanchor.pos_: " << anchor().pos_;
205 lyxerr << "\n===================^^^^^^^^^^^^=====================\n\n\n";
210 void MathCursor::seldump(char const *) const {}
211 void MathCursor::dump(char const *) const {}
216 bool MathCursor::isInside(MathInset const * p) const
218 for (unsigned i = 0; i < Cursor_.size(); ++i)
219 if (Cursor_[i].par_ == p)
225 bool MathCursor::openable(MathInset * p, bool sel) const
234 // we can't move into anything new during selection
235 if (Cursor_.size() == Anchor_.size())
237 if (p != Anchor_[Cursor_.size()].par_)
244 MathInset * MathCursor::positionable(MathAtom * t, int x, int y) const
250 // we can't move into anything new during selection
251 if (Cursor_.size() == Anchor_.size())
253 //if (t != Anchor_[Cursor_.size()].par_)
260 if (p && p->nargs() && p->covers(x, y))
264 if (p && p->nargs() && p->covers(x, y))
268 if (p && p->nargs() && p->covers(x, y))
275 bool MathCursor::posLeft()
284 bool MathCursor::posRight()
293 bool MathCursor::left(bool sel)
298 lastcode_ = LM_TC_VAR;
302 lastcode_ = LM_TC_VAR;
304 MathInset * p = prevInset();
305 if (openable(p, sel)) {
310 return posLeft() || idxLeft() || popLeft();
314 bool MathCursor::right(bool sel)
319 lastcode_ = LM_TC_VAR;
323 lastcode_ = LM_TC_VAR;
325 MathInset * p = nextInset();
326 if (openable(p, sel)) {
331 return posRight() || idxRight() || popRight();
335 void MathCursor::first()
338 pushLeft(outerPar());
342 void MathCursor::last()
349 void MathCursor::setPos(int x, int y)
352 //lyxerr << "MathCursor::setPos x: " << x << " y: " << y << "\n";
355 lastcode_ = LM_TC_VAR;
358 cursor().par_ = outerPar();
363 //lyxerr << "found idx: " << idx() << " cursor: " << pos() << "\n";
364 int distmin = 1 << 30; // large enough
365 for (unsigned int i = 0; i < par()->nargs(); ++i) {
366 MathXArray const & ar = par()->xcell(i);
367 int x1 = x - ar.xo();
368 int y1 = y - ar.yo();
369 MathXArray::size_type c = ar.x2pos(x1);
370 int xx = abs(x1 - ar.pos2x(c));
372 //lyxerr << "idx: " << i << " xx: " << xx << " yy: " << yy
373 // << " c: " << c << " xo: " << ar.xo() << "\n";
374 if (yy + xx <= distmin) {
380 //lyxerr << "found idx: " << idx() << " cursor: "
382 if (MathInset * p = positionable(nextAtom(), x, y))
384 else if (MathInset * p = positionable(prevAtom(), x, y))
393 void MathCursor::home(bool sel)
398 lastcode_ = LM_TC_VAR;
399 if (!par()->idxHome(idx(), pos()))
405 void MathCursor::end(bool sel)
410 lastcode_ = LM_TC_VAR;
411 if (!par()->idxEnd(idx(), pos()))
417 void MathCursor::plainErase()
419 array().erase(pos());
423 void MathCursor::insert(char c, MathTextCodes t)
425 //lyxerr << "inserting '" << c << "'\n";
426 array().insert(pos(), new MathCharInset(c, t));
431 void MathCursor::insert(MathInset * p)
442 array().insert(pos(), p); // this invalidates the pointer!
443 p = array().at(pos())->nucleus();
448 void MathCursor::niceInsert(MathInset * p)
451 lyxerr << "should not happen\n";
455 //cerr << "\n2: "; p->write(cerr, true); cerr << "\n";
456 insert(p); // inserting invalidates the pointer!
457 p = prevAtom()->nucleus();
458 //cerr << "\n3: "; p->write(cerr, true); cerr << "\n";
461 right(); // do not push for e.g. MathSymbolInset
464 p->metrics(p->size());
468 void MathCursor::insert(MathArray const & ar)
474 array().insert(pos(), ar);
479 void MathCursor::backspace()
495 void MathCursor::erase()
506 // delete empty cells if necessary
507 if (pos() == 0 && array().empty()) {
510 par()->idxDelete(idx(), popit, removeit);
511 if (popit && popLeft() && removeit)
519 // delete nucleus, keep scripts if possible
520 MathAtom * p = prevAtom();
521 MathAtom * n = nextAtom();
523 bool need_parans = (p->up() && n->up()) || (p->down() && n->down());
526 insert('{', LM_TC_TEX);
527 insert('}', LM_TC_TEX);
531 // move indices to the left
533 swap(p->up(), n->up());
535 swap(p->down(), n->down());
541 if (n->up() || n->down()) {
542 insert('{', LM_TC_TEX);
543 insert('}', LM_TC_TEX);
546 swap(p->up(), n->up());
547 swap(p->down(), n->down());
555 void MathCursor::delLine()
564 if (par()->nrows() > 1)
565 par()->delRow(row());
569 bool MathCursor::up(bool sel)
578 // check whether we could move into a superscript on the right or on the left
579 if (prevAtom() && prevAtom()->up()) {
580 pushRight(prevAtom()->up());
584 if (nextAtom() && nextAtom()->up()) {
585 pushLeft(nextAtom()->up());
593 bool MathCursor::down(bool sel)
602 // check whether we could move into an subscript on the right or on the left
603 if (prevAtom() && prevAtom()->down()) {
604 pushRight(prevAtom()->down());
608 if (nextAtom() && nextAtom()->down()) {
609 pushLeft(nextAtom()->down());
617 bool MathCursor::toggleLimits()
619 MathAtom * t = prevAtom();
622 int old = t->limits();
623 t->limits(old < 0 ? 1 : -1);
624 return old != t->limits();
628 void MathCursor::setSize(MathStyles size)
630 par()->userSetSize(size);
634 void MathCursor::macroModeClose()
636 string s = macroName();
638 pos() = pos() - s.size() - 1;
639 for (unsigned i = 0; i <= s.size(); ++i)
641 lastcode_ = LM_TC_VAR;
647 string MathCursor::macroName() const
650 for (int i = pos() - 1; i >= 0; --i) {
651 MathInset * p = array().at(i)->nucleus();
652 if (!p || p->code() != LM_TC_TEX || p->getChar() == '\\')
654 s = p->getChar() + s;
660 void MathCursor::selCopy()
664 theSelection.grab(*this);
670 void MathCursor::selCut()
674 theSelection.grab(*this);
675 theSelection.erase(*this);
678 theSelection.clear();
683 void MathCursor::selDel()
687 theSelection.erase(*this);
693 void MathCursor::selPaste()
696 theSelection.paste(*this);
701 void MathCursor::selHandle(bool sel)
703 if (sel == selection_)
706 theSelection.clear();
712 void MathCursor::selStart()
718 theSelection.clear();
724 void MathCursor::selClear()
731 void MathCursor::drawSelection(Painter & pain) const
738 getSelection(i1, i2);
740 //lyxerr << "selection from: " << i1 << " to " << i2 << "\n";
742 if (i1.idx_ == i2.idx_) {
743 MathXArray & c = i1.xcell();
744 int x1 = c.xo() + c.pos2x(i1.pos_);
745 int y1 = c.yo() - c.ascent();
746 int x2 = c.xo() + c.pos2x(i2.pos_);
747 int y2 = c.yo() + c.descent();
748 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
750 std::vector<MathInset::idx_type> indices = i1.par_->idxBetween(i1.idx_, i2.idx_);
751 for (unsigned i = 0; i < indices.size(); ++i) {
752 MathXArray & c = i1.xcell(indices[i]);
754 int y1 = c.yo() - c.ascent();
755 int x2 = c.xo() + c.width();
756 int y2 = c.yo() + c.descent();
757 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
763 MathTextCodes MathCursor::nextCode() const
765 //return (pos() == size()) ? LM_TC_VAR : nextInset()->code();
770 void MathCursor::handleFont(MathTextCodes t)
776 getSelection(i1, i2);
777 if (i1.idx_ == i2.idx_) {
778 MathArray & ar = i1.cell();
779 for (MathInset::pos_type pos = i1.pos_;
780 pos != i2.pos_; ++pos) {
781 MathInset * p = ar.at(pos)->nucleus();
787 lastcode_ = (lastcode_ == t) ? LM_TC_VAR : t;
791 void MathCursor::handleDelim(string const & l, string const & r)
793 handleNest(new MathDelimInset(l, r));
797 void MathCursor::handleNest(MathInset * p)
801 p->cell(0) = theSelection.glue();
803 insert(p); // this invalidates p!
804 p = prevAtom()->nucleus();
809 void MathCursor::getPos(int & x, int & y)
812 #warning This should probably take cellXOffset and cellYOffset into account
814 x = xarray().xo() + xarray().pos2x(pos());
819 MathInset * MathCursor::par() const
821 return cursor().par_;
825 InsetFormulaBase const * MathCursor::formula()
831 MathCursor::idx_type MathCursor::idx() const
833 return cursor().idx_;
837 MathCursor::idx_type & MathCursor::idx()
839 return cursor().idx_;
843 MathCursor::pos_type MathCursor::pos() const
845 return cursor().pos_;
849 MathCursor::pos_type & MathCursor::pos()
851 return cursor().pos_;
855 bool MathCursor::inMacroMode() const
857 return lastcode_ == LM_TC_TEX;
861 bool MathCursor::selection() const
867 MathArrayInset * MathCursor::enclosingArray(MathCursor::idx_type & idx) const
869 for (int i = Cursor_.size() - 1; i >= 0; --i) {
870 if (Cursor_[i].par_->isArray()) {
871 idx = Cursor_[i].idx_;
872 return static_cast<MathArrayInset *>(Cursor_[i].par_);
879 void MathCursor::pullArg(bool goright)
883 MathArray a = array();
886 array().insert(pos(), a);
893 MathStyles MathCursor::style() const
895 return xarray().style();
899 void MathCursor::normalize() const
902 #warning This is evil!
904 MathCursor * it = const_cast<MathCursor *>(this);
906 if (idx() >= par()->nargs()) {
907 lyxerr << "this should not really happen - 1: "
908 << idx() << " " << par()->nargs() << "\n";
911 it->idx() = min(idx(), par()->nargs() - 1);
913 if (pos() > size()) {
914 lyxerr << "this should not really happen - 2: "
915 << pos() << " " << size() << "\n";
918 it->pos() = min(pos(), size());
922 MathCursor::size_type MathCursor::size() const
924 return array().size();
928 MathCursor::col_type MathCursor::col() const
930 return par()->col(idx());
934 MathCursor::row_type MathCursor::row() const
936 return par()->row(idx());
941 char MathCursorPos::getChar() const
943 return array().getChar(pos());
947 string MathCursorPos::readString()
950 int code = nextCode();
951 for ( ; OK() && nextCode() == code; Next())
959 MathInset * MathCursor::prevInset() const
961 return prevAtom() ? prevAtom()->nucleus() : 0;
965 MathInset * MathCursor::nextInset() const
967 return nextAtom() ? nextAtom()->nucleus() : 0;
971 MathSpaceInset * MathCursor::prevSpaceInset() const
973 MathInset * p = prevInset();
974 return (p && p->isSpaceInset()) ? static_cast<MathSpaceInset *>(p) : 0;
978 MathAtom const * MathCursor::prevAtom() const
980 return array().at(pos() - 1);
984 MathAtom * MathCursor::prevAtom()
986 return array().at(pos() - 1);
990 MathAtom const * MathCursor::nextAtom() const
992 return array().at(pos());
996 MathAtom * MathCursor::nextAtom()
998 return array().at(pos());
1002 MathArray & MathCursor::array() const
1004 static MathArray dummy;
1006 lyxerr << "############ par_ not valid\n";
1010 if (idx() >= par()->nargs()) {
1011 lyxerr << "############ idx_ " << idx() << " not valid\n";
1015 return cursor().cell();
1019 MathXArray & MathCursor::xarray() const
1021 return cursor().xcell();
1025 void MathCursor::idxNext()
1027 par()->idxNext(idx(), pos());
1031 void MathCursor::idxPrev()
1033 par()->idxPrev(idx(), pos());
1037 void MathCursor::splitCell()
1039 if (idx() == par()->nargs() - 1)
1041 MathArray ar = array();
1043 array().erase(pos(), size());
1046 array().insert(0, ar);
1050 void MathCursor::breakLine()
1052 // leave inner cells
1056 MathMatrixInset * p = outerPar();
1057 if (p->getType() == LM_OT_SIMPLE || p->getType() == LM_OT_EQUATION) {
1058 p->mutate(LM_OT_EQNARRAY);
1065 const row_type r = row();
1066 for (col_type c = col() + 1; c < p->ncols(); ++c) {
1067 const MathMatrixInset::idx_type i1 = p->index(r, c);
1068 const MathMatrixInset::idx_type i2 = p->index(r + 1, c);
1069 lyxerr << "swapping cells " << i1 << " and " << i2 << "\n";
1070 p->cell(i1).swap(p->cell(i2));
1075 p->cell(idx()).swap(p->cell(idx() + p->ncols() - 1));
1080 char MathCursor::valign() const
1083 MathArrayInset * p = enclosingArray(idx);
1084 return p ? p->valign() : '\0';
1088 char MathCursor::halign() const
1091 MathArrayInset * p = enclosingArray(idx);
1092 return p ? p->halign(idx % p->ncols()) : '\0';
1096 void MathCursor::getSelection(MathCursorPos & i1, MathCursorPos & i2) const
1098 MathCursorPos anc = normalAnchor();
1099 if (anc < cursor()) {
1109 MathCursorPos & MathCursor::cursor()
1111 return Cursor_.back();
1115 MathCursorPos const & MathCursor::cursor() const
1117 return Cursor_.back();
1121 int MathCursor::cellXOffset() const
1123 return par()->cellXOffset(idx());
1127 int MathCursor::cellYOffset() const
1129 return par()->cellYOffset(idx());
1133 int MathCursor::xpos() const
1135 return cellXOffset() + xarray().pos2x(pos());
1139 int MathCursor::ypos() const
1141 return cellYOffset();
1146 void MathCursor::gotoX(int x)
1148 pos() = xarray().x2pos(x - cellXOffset());
1152 bool MathCursor::goUp()
1154 // first ask the inset if it knows better then we
1155 if (par()->idxUp(idx(), pos()))
1158 // leave subscript to the nearest side
1159 if (par()->asScriptInset() && par()->asScriptInset()->down()) {
1160 if (pos() <= size() / 2)
1167 // if not, apply brute force.
1171 std::vector<MathCursorPos> save = Cursor_;
1172 y0 -= xarray().ascent();
1173 for (int y = y0 - 4; y > outerPar()->yo() - outerPar()->ascent(); y -= 4) {
1175 if (save != Cursor_ && xarray().yo() < y0)
1183 bool MathCursor::goDown()
1185 // first ask the inset if it knows better then we
1186 if (par()->idxDown(idx(), pos()))
1189 // leave superscript to the nearest side
1190 if (par()->asScriptInset() && par()->asScriptInset()->up()) {
1191 if (pos() <= size() / 2)
1198 // if not, apply brute force.
1202 std::vector<MathCursorPos> save = Cursor_;
1203 y0 += xarray().descent();
1204 for (int y = y0 + 4; y < outerPar()->yo() + outerPar()->descent(); y += 4) {
1206 if (save != Cursor_ && xarray().yo() > y0)
1214 bool MathCursor::idxLeft()
1216 return par()->idxLeft(idx(), pos());
1220 bool MathCursor::idxRight()
1222 return par()->idxRight(idx(), pos());
1226 MathMatrixInset * MathCursor::outerPar() const
1229 static_cast<MathMatrixInset *>(const_cast<MathInset *>(formula_->par()));
1233 void MathCursor::interpret(string const & s)
1235 //lyxerr << "interpret: '" << s << "'\n";
1236 //lyxerr << "in: " << in_word_set(s) << " \n";
1243 //lyxerr << "char: '" << c << "' int: " << int(c) << endl;
1244 //owner_->getIntl()->getTrans().TranslateAndInsert(c, lt);
1245 //lyxerr << "trans: '" << c << "' int: " << int(c) << endl;
1247 if (s.size() > 7 && s.substr(0, 7) == "matrix ") {
1252 istringstream is(s.substr(7).c_str());
1253 is >> m >> n >> v_align >> h_align;
1254 m = std::max(1u, m);
1255 n = std::max(1u, n);
1257 MathArrayInset * p = new MathArrayInset(m, n);
1258 p->valign(v_align[0]);
1264 if (s == "\\over" || s == "\\choose" || s == "\\atop") {
1265 MathArray ar = array();
1266 MathInset * p = createMathInset(s.substr(1));
1267 p->cell(0).swap(array());
1276 niceInsert(createMathInset(s.substr(1)));
1281 // we got just a single char now
1283 if (c == '^' || c == '_') {
1284 bool const up = (s[0] == '^');
1287 insert('{', LM_TC_TEX);
1288 insert('}', LM_TC_TEX);
1290 MathInset * par = prevAtom()->ensure(up);
1299 if (lastcode_ == LM_TC_TEXTRM) {
1300 insert(c, LM_TC_TEXTRM);
1305 if (inMacroMode()) {
1307 lastcode_ = LM_TC_VAR;
1311 MathSpaceInset * p = prevSpaceInset();
1317 if (mathcursor->popRight())
1321 // this would not work if the inset is in an table!
1322 //bv->text->cursorRight(bv, true);
1323 //result = FINISHED;
1327 if (lastcode_ != LM_TC_TEX && strchr("#$%{}", c)) {
1328 insert(new MathSpecialCharInset(c));
1329 lastcode_ = LM_TC_VAR;
1333 if (lastcode_ == LM_TC_TEX) {
1334 if (macroName().empty()) {
1335 insert(c, LM_TC_TEX);
1336 if (!isalpha(c) && c != '#') {
1338 lastcode_ = LM_TC_VAR;
1341 if ('1' <= c && c <= '9' && macroName() == "#") {
1342 insert(c, LM_TC_TEX);
1344 lastcode_ = LM_TC_VAR;
1346 else if (isalpha(c))
1347 insert(c, LM_TC_TEX);
1350 lastcode_ = LM_TC_VAR;
1356 if (isalpha(c) && (lastcode_ == LM_TC_GREEK || lastcode_ == LM_TC_GREEK1)) {
1357 static char const greekl[][26] =
1358 {"alpha", "beta", "chi", "delta", "epsilon", "phi",
1359 "gamma", "eta", "iota", "iota", "kappa", "lambda", "mu",
1360 "nu", "omikron", "pi", "omega", "rho", "sigma",
1361 "tau", "upsilon", "theta", "omega", "xi", "upsilon", "zeta"};
1362 static char const greeku[][26] =
1363 {"Alpha", "Beta", "Chi", "Delta", "Epsilon", "Phi",
1364 "Gamma", "Eta", "Iota", "Iota", "Kappa", "Lambda", "Mu",
1365 "Nu", "Omikron", "Pi", "Omega", "Rho", "Sigma", "Tau",
1366 "Upsilon", "Theta", "Omega", "xi", "Upsilon", "Zeta"};
1368 latexkeys const * l = 0;
1369 if ('a' <= c && c <= 'z')
1370 l = in_word_set(greekl[c - 'a']);
1371 if ('A' <= c && c <= 'Z')
1372 l = in_word_set(greeku[c - 'A']);
1375 insert(createMathInset(l));
1377 insert(c, LM_TC_VAR);
1379 #warning greek insert problem? look here!
1380 if (lastcode_ == LM_TC_GREEK1)
1381 lastcode_ = LM_TC_VAR;
1386 lastcode_ = LM_TC_TEX;
1387 insert(c, LM_TC_TEX);
1388 //bv->owner()->message(_("TeX mode"));
1392 // no special circumstances, so insert the character without any fuss
1398 ////////////////////////////////////////////////////////////////////////
1401 bool operator==(MathCursorPos const & ti, MathCursorPos const & it)
1403 return ti.par_ == it.par_ && ti.idx_ == it.idx_ && ti.pos_ == it.pos_;
1407 bool operator<(MathCursorPos const & ti, MathCursorPos const & it)
1409 if (ti.par_ != it.par_) {
1410 lyxerr << "can't compare cursor and anchor in different insets\n";
1413 if (ti.idx_ != it.idx_)
1414 return ti.idx_ < it.idx_;
1415 return ti.pos_ < it.pos_;
1419 MathArray & MathCursorPos::cell(MathCursor::idx_type idx) const
1421 return par_->cell(idx);
1425 MathArray & MathCursorPos::cell() const
1427 return par_->cell(idx_);
1431 MathXArray & MathCursorPos::xcell(MathCursor::idx_type idx) const
1433 return par_->xcell(idx);
1437 MathXArray & MathCursorPos::xcell() const
1439 return par_->xcell(idx_);
1443 MathCursorPos MathCursor::normalAnchor() const
1445 // use Anchor on the same level as Cursor
1446 MathCursorPos normal = Anchor_[Cursor_.size() - 1];
1447 if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) {
1448 // anchor is behind cursor -> move anchor behind the inset