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();
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)
653 s = p->getChar() + s;
661 void MathCursor::selCopy()
665 theSelection.grab(*this);
671 void MathCursor::selCut()
675 theSelection.grab(*this);
676 theSelection.erase(*this);
679 theSelection.clear();
684 void MathCursor::selDel()
688 theSelection.erase(*this);
694 void MathCursor::selPaste()
697 theSelection.paste(*this);
702 void MathCursor::selHandle(bool sel)
704 if (sel == selection_)
707 theSelection.clear();
713 void MathCursor::selStart()
719 theSelection.clear();
725 void MathCursor::selClear()
732 void MathCursor::drawSelection(Painter & pain) const
739 getSelection(i1, i2);
741 //lyxerr << "selection from: " << i1 << " to " << i2 << "\n";
743 if (i1.idx_ == i2.idx_) {
744 MathXArray & c = i1.xcell();
745 int x1 = c.xo() + c.pos2x(i1.pos_);
746 int y1 = c.yo() - c.ascent();
747 int x2 = c.xo() + c.pos2x(i2.pos_);
748 int y2 = c.yo() + c.descent();
749 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
751 std::vector<MathInset::idx_type> indices = i1.par_->idxBetween(i1.idx_, i2.idx_);
752 for (unsigned i = 0; i < indices.size(); ++i) {
753 MathXArray & c = i1.xcell(indices[i]);
755 int y1 = c.yo() - c.ascent();
756 int x2 = c.xo() + c.width();
757 int y2 = c.yo() + c.descent();
758 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
764 MathTextCodes MathCursor::nextCode() const
766 //return (pos() == size()) ? LM_TC_VAR : nextInset()->code();
771 void MathCursor::handleFont(MathTextCodes t)
777 getSelection(i1, i2);
778 if (i1.idx_ == i2.idx_) {
779 MathArray & ar = i1.cell();
780 for (MathInset::pos_type pos = i1.pos_;
781 pos != i2.pos_; ++pos) {
782 MathInset * p = ar.at(pos)->nucleus();
788 lastcode_ = (lastcode_ == t) ? LM_TC_VAR : t;
792 void MathCursor::handleDelim(string const & l, string const & r)
794 handleNest(new MathDelimInset(l, r));
798 void MathCursor::handleNest(MathInset * p)
802 p->cell(0) = theSelection.glue();
804 insert(p); // this invalidates p!
805 p = prevAtom()->nucleus();
810 void MathCursor::getPos(int & x, int & y)
813 #warning This should probably take cellXOffset and cellYOffset into account
815 x = xarray().xo() + xarray().pos2x(pos());
820 MathInset * MathCursor::par() const
822 return cursor().par_;
826 InsetFormulaBase const * MathCursor::formula()
832 MathCursor::idx_type MathCursor::idx() const
834 return cursor().idx_;
838 MathCursor::idx_type & MathCursor::idx()
840 return cursor().idx_;
844 MathCursor::pos_type MathCursor::pos() const
846 return cursor().pos_;
850 MathCursor::pos_type & MathCursor::pos()
852 return cursor().pos_;
856 bool MathCursor::inMacroMode() const
858 return lastcode_ == LM_TC_TEX;
862 bool MathCursor::selection() const
868 MathArrayInset * MathCursor::enclosingArray(MathCursor::idx_type & idx) const
870 for (int i = Cursor_.size() - 1; i >= 0; --i) {
871 if (Cursor_[i].par_->isArray()) {
872 idx = Cursor_[i].idx_;
873 return static_cast<MathArrayInset *>(Cursor_[i].par_);
880 void MathCursor::pullArg(bool goright)
884 MathArray a = array();
887 array().insert(pos(), a);
894 MathStyles MathCursor::style() const
896 return xarray().style();
900 void MathCursor::normalize() const
903 #warning This is evil!
905 MathCursor * it = const_cast<MathCursor *>(this);
907 if (idx() >= par()->nargs()) {
908 lyxerr << "this should not really happen - 1: "
909 << idx() << " " << par()->nargs() << "\n";
912 it->idx() = min(idx(), par()->nargs() - 1);
914 if (pos() > size()) {
915 lyxerr << "this should not really happen - 2: "
916 << pos() << " " << size() << "\n";
919 it->pos() = min(pos(), size());
923 MathCursor::size_type MathCursor::size() const
925 return array().size();
929 MathCursor::col_type MathCursor::col() const
931 return par()->col(idx());
935 MathCursor::row_type MathCursor::row() const
937 return par()->row(idx());
942 char MathCursorPos::getChar() const
944 return array().getChar(pos());
948 string MathCursorPos::readString()
951 int code = nextCode();
952 for ( ; OK() && nextCode() == code; Next())
960 MathInset * MathCursor::prevInset() const
962 return prevAtom() ? prevAtom()->nucleus() : 0;
966 MathInset * MathCursor::nextInset() const
968 return nextAtom() ? nextAtom()->nucleus() : 0;
972 MathSpaceInset * MathCursor::prevSpaceInset() const
974 MathInset * p = prevInset();
975 return (p && p->isSpaceInset()) ? static_cast<MathSpaceInset *>(p) : 0;
979 MathAtom const * MathCursor::prevAtom() const
981 return array().at(pos() - 1);
985 MathAtom * MathCursor::prevAtom()
987 return array().at(pos() - 1);
991 MathAtom const * MathCursor::nextAtom() const
993 return array().at(pos());
997 MathAtom * MathCursor::nextAtom()
999 return array().at(pos());
1003 MathArray & MathCursor::array() const
1005 static MathArray dummy;
1007 lyxerr << "############ par_ not valid\n";
1011 if (idx() >= par()->nargs()) {
1012 lyxerr << "############ idx_ " << idx() << " not valid\n";
1016 return cursor().cell();
1020 MathXArray & MathCursor::xarray() const
1022 return cursor().xcell();
1026 void MathCursor::idxNext()
1028 par()->idxNext(idx(), pos());
1032 void MathCursor::idxPrev()
1034 par()->idxPrev(idx(), pos());
1038 void MathCursor::splitCell()
1040 if (idx() == par()->nargs() - 1)
1042 MathArray ar = array();
1044 array().erase(pos(), size());
1047 array().insert(0, ar);
1051 void MathCursor::breakLine()
1053 // leave inner cells
1057 MathMatrixInset * p = outerPar();
1058 if (p->getType() == LM_OT_SIMPLE || p->getType() == LM_OT_EQUATION) {
1059 p->mutate(LM_OT_EQNARRAY);
1066 const row_type r = row();
1067 for (col_type c = col() + 1; c < p->ncols(); ++c) {
1068 const MathMatrixInset::idx_type i1 = p->index(r, c);
1069 const MathMatrixInset::idx_type i2 = p->index(r + 1, c);
1070 lyxerr << "swapping cells " << i1 << " and " << i2 << "\n";
1071 p->cell(i1).swap(p->cell(i2));
1076 p->cell(idx()).swap(p->cell(idx() + p->ncols() - 1));
1081 char MathCursor::valign() const
1084 MathArrayInset * p = enclosingArray(idx);
1085 return p ? p->valign() : '\0';
1089 char MathCursor::halign() const
1092 MathArrayInset * p = enclosingArray(idx);
1093 return p ? p->halign(idx % p->ncols()) : '\0';
1097 void MathCursor::getSelection(MathCursorPos & i1, MathCursorPos & i2) const
1099 MathCursorPos anc = normalAnchor();
1100 if (anc < cursor()) {
1110 MathCursorPos & MathCursor::cursor()
1112 return Cursor_.back();
1116 MathCursorPos const & MathCursor::cursor() const
1118 return Cursor_.back();
1122 int MathCursor::cellXOffset() const
1124 return par()->cellXOffset(idx());
1128 int MathCursor::cellYOffset() const
1130 return par()->cellYOffset(idx());
1134 int MathCursor::xpos() const
1136 return cellXOffset() + xarray().pos2x(pos());
1140 int MathCursor::ypos() const
1142 return cellYOffset();
1147 void MathCursor::gotoX(int x)
1149 pos() = xarray().x2pos(x - cellXOffset());
1153 bool MathCursor::goUp()
1155 // first ask the inset if it knows better then we
1156 if (par()->idxUp(idx(), pos()))
1159 // leave subscript to the nearest side
1160 if (par()->asScriptInset() && par()->asScriptInset()->down()) {
1161 if (pos() <= size() / 2)
1168 // if not, apply brute force.
1172 std::vector<MathCursorPos> save = Cursor_;
1173 y0 -= xarray().ascent();
1174 for (int y = y0 - 4; y > outerPar()->yo() - outerPar()->ascent(); y -= 4) {
1176 if (save != Cursor_ && xarray().yo() < y0)
1184 bool MathCursor::goDown()
1186 // first ask the inset if it knows better then we
1187 if (par()->idxDown(idx(), pos()))
1190 // leave superscript to the nearest side
1191 if (par()->asScriptInset() && par()->asScriptInset()->up()) {
1192 if (pos() <= size() / 2)
1199 // if not, apply brute force.
1203 std::vector<MathCursorPos> save = Cursor_;
1204 y0 += xarray().descent();
1205 for (int y = y0 + 4; y < outerPar()->yo() + outerPar()->descent(); y += 4) {
1207 if (save != Cursor_ && xarray().yo() > y0)
1215 bool MathCursor::idxLeft()
1217 return par()->idxLeft(idx(), pos());
1221 bool MathCursor::idxRight()
1223 return par()->idxRight(idx(), pos());
1227 MathMatrixInset * MathCursor::outerPar() const
1230 static_cast<MathMatrixInset *>(const_cast<MathInset *>(formula_->par()));
1234 void MathCursor::interpret(string const & s)
1236 //lyxerr << "interpret: '" << s << "'\n";
1237 //lyxerr << "in: " << in_word_set(s) << " \n";
1244 //lyxerr << "char: '" << c << "' int: " << int(c) << endl;
1245 //owner_->getIntl()->getTrans().TranslateAndInsert(c, lt);
1246 //lyxerr << "trans: '" << c << "' int: " << int(c) << endl;
1248 if (s.size() > 7 && s.substr(0, 7) == "matrix ") {
1253 istringstream is(s.substr(7).c_str());
1254 is >> m >> n >> v_align >> h_align;
1255 m = std::max(1u, m);
1256 n = std::max(1u, n);
1258 MathArrayInset * p = new MathArrayInset(m, n);
1259 p->valign(v_align[0]);
1265 if (s == "\\over" || s == "\\choose" || s == "\\atop") {
1266 MathArray ar = array();
1267 MathInset * p = createMathInset(s.substr(1));
1268 p->cell(0).swap(array());
1277 niceInsert(createMathInset(s.substr(1)));
1282 // we got just a single char now
1284 if (c == '^' || c == '_') {
1285 bool const up = (s[0] == '^');
1288 insert('{', LM_TC_TEX);
1289 insert('}', LM_TC_TEX);
1291 MathInset * par = prevAtom()->ensure(up);
1300 if (lastcode_ == LM_TC_TEXTRM) {
1301 insert(c, LM_TC_TEXTRM);
1306 if (inMacroMode()) {
1308 lastcode_ = LM_TC_VAR;
1312 MathSpaceInset * p = prevSpaceInset();
1318 if (mathcursor->popRight())
1322 // this would not work if the inset is in an table!
1323 //bv->text->cursorRight(bv, true);
1324 //result = FINISHED;
1328 if (lastcode_ != LM_TC_TEX && strchr("#$%{}", c)) {
1329 insert(new MathSpecialCharInset(c));
1330 lastcode_ = LM_TC_VAR;
1334 if (lastcode_ == LM_TC_TEX) {
1335 if (macroName().empty()) {
1336 if (strchr("$%{}", c)) {
1337 insert(new MathCharInset(c, LM_TC_TEX));
1338 lastcode_ = LM_TC_VAR;
1341 insert(c, LM_TC_TEX);
1342 if (!isalpha(c) && c != '#') {
1344 lastcode_ = LM_TC_VAR;
1347 if ('1' <= c && c <= '9' && macroName() == "#") {
1348 insert(c, LM_TC_TEX);
1350 lastcode_ = LM_TC_VAR;
1352 else if (isalpha(c))
1353 insert(c, LM_TC_TEX);
1356 lastcode_ = LM_TC_VAR;
1362 if (isalpha(c) && (lastcode_ == LM_TC_GREEK || lastcode_ == LM_TC_GREEK1)) {
1363 static char const greekl[][26] =
1364 {"alpha", "beta", "chi", "delta", "epsilon", "phi",
1365 "gamma", "eta", "iota", "", "kappa", "lambda", "mu",
1366 "nu", "omikron", "pi", "omega", "rho", "sigma",
1367 "tau", "upsilon", "theta", "", "xi", "upsilon", "zeta"};
1368 static char const greeku[][26] =
1369 {"Alpha", "Beta", "Chi", "Delta", "Epsilon", "Phi",
1370 "Gamma", "Eta", "Iota", "", "Kappa", "Lambda", "Mu",
1371 "Nu", "Omikron", "Pi", "Omega", "Rho", "Sigma", "Tau",
1372 "Upsilon", "Theta", "", "xi", "Upsilon", "Zeta"};
1374 latexkeys const * l = 0;
1375 if ('a' <= c && c <= 'z')
1376 l = in_word_set(greekl[c - 'a']);
1377 if ('A' <= c && c <= 'Z')
1378 l = in_word_set(greeku[c - 'A']);
1381 insert(createMathInset(l));
1383 insert(c, LM_TC_VAR);
1385 #warning greek insert problem? look here!
1386 if (lastcode_ == LM_TC_GREEK1)
1387 lastcode_ = LM_TC_VAR;
1392 lastcode_ = LM_TC_TEX;
1393 //bv->owner()->message(_("TeX mode"));
1397 // no special circumstances, so insert the character without any fuss
1403 ////////////////////////////////////////////////////////////////////////
1406 bool operator==(MathCursorPos const & ti, MathCursorPos const & it)
1408 return ti.par_ == it.par_ && ti.idx_ == it.idx_ && ti.pos_ == it.pos_;
1412 bool operator<(MathCursorPos const & ti, MathCursorPos const & it)
1414 if (ti.par_ != it.par_) {
1415 lyxerr << "can't compare cursor and anchor in different insets\n";
1418 if (ti.idx_ != it.idx_)
1419 return ti.idx_ < it.idx_;
1420 return ti.pos_ < it.pos_;
1424 MathArray & MathCursorPos::cell(MathCursor::idx_type idx) const
1426 return par_->cell(idx);
1430 MathArray & MathCursorPos::cell() const
1432 return par_->cell(idx_);
1436 MathXArray & MathCursorPos::xcell(MathCursor::idx_type idx) const
1438 return par_->xcell(idx);
1442 MathXArray & MathCursorPos::xcell() const
1444 return par_->xcell(idx_);
1448 MathCursorPos MathCursor::normalAnchor() const
1450 // use Anchor on the same level as Cursor
1451 MathCursorPos normal = Anchor_[Cursor_.size() - 1];
1452 if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) {
1453 // anchor is behind cursor -> move anchor behind the inset