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"
27 #include "support/LAssert.h"
32 #include "formulabase.h"
33 #include "math_cursor.h"
34 #include "math_factory.h"
35 #include "math_arrayinset.h"
36 #include "math_charinset.h"
37 #include "math_deliminset.h"
38 #include "math_matrixinset.h"
39 #include "math_scriptinset.h"
40 #include "math_spaceinset.h"
41 #include "math_specialcharinset.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 =
80 (*i1.par_)->idxBetween(i1.idx_, i2.idx_);
81 for (unsigned i = 0; i < indices.size(); ++i)
82 i1.cell(indices[i]).erase();
87 void paste(MathCursor & cursor) const
89 MathArray ar = glue();
93 // glues selection to one cell
94 MathArray glue() const
97 for (unsigned i = 0; i < data_.size(); ++i)
98 ar.push_back(data_[i]);
107 std::vector<MathArray> data_;
111 Selection theSelection;
115 std::ostream & operator<<(std::ostream & os, MathCursorPos const & p)
117 os << "(par: " << p.par_ << " idx: " << p.idx_ << " pos: " << p.pos_ << ")";
125 MathCursor::MathCursor(InsetFormulaBase * formula, bool left)
126 : formula_(formula), lastcode_(LM_TC_VAR), selection_(false)
128 left ? first() : last();
132 void MathCursor::push(MathAtom & t)
138 Cursor_.push_back(p);
142 void MathCursor::pushLeft(MathAtom & t)
144 //cerr << "Entering atom "; t->write(cerr, false); cerr << " left\n";
146 t->idxFirst(idx(), pos());
150 void MathCursor::pushRight(MathAtom & t)
152 //cerr << "Entering atom "; t->write(cerr, false); cerr << " right\n";
155 t->idxLast(idx(), pos());
159 bool MathCursor::popLeft()
161 //cerr << "Leaving atom "; par()->write(cerr, false); cerr << " left\n";
162 if (Cursor_.size() <= 1)
165 // nextInset()->removeEmptyScripts();
168 // nextAtom()->removeEmptyScripts();
173 bool MathCursor::popRight()
175 //cerr << "Leaving atom "; par()->write(cerr, false); cerr << " right\n";
176 if (Cursor_.size() <= 1)
179 // nextInset()->removeEmptyScripts();
182 // nextInset()->removeEmptyScripts();
190 void MathCursor::dump(char const * what) const
192 lyxerr << "MC: " << what << "\n";
193 for (unsigned i = 0; i < Cursor_.size(); ++i)
194 lyxerr << " i: " << i
195 << " Cursor: pos: " << Cursor_[i].pos_
196 << " idx: " << Cursor_[i].idx_
197 << " par: " << Cursor_[i].par_ << "\n";
199 for (unsigned i = 0; i < Anchor_.size(); ++i)
200 lyxerr << " i: " << i
201 << " Anchor: pos: " << Anchor_[i].pos_
202 << " idx: " << Anchor_[i].idx_
203 << " par: " << Anchor_[i].par_ << "\n";
205 lyxerr << " sel: " << selection_ << "\n";
209 void MathCursor::seldump(char const * str) const
211 //lyxerr << "SEL: " << str << ": '" << theSelection << "'\n";
214 lyxerr << "\n\n\n=================vvvvvvvvvvvvv======================= "
215 << str << "\ntheSelection: " << selection_
216 << " '" << theSelection.glue() << "'\n";
217 for (unsigned int i = 0; i < Cursor_.size(); ++i)
218 lyxerr << Cursor_[i].par_ << "\n'" << Cursor_[i].cell() << "'\n";
220 for (unsigned int i = 0; i < Anchor_.size(); ++i)
221 lyxerr << Anchor_[i].par_ << "\n'" << Anchor_[i].cell() << "'\n";
222 //lyxerr << "\ncursor.pos_: " << pos();
223 //lyxerr << "\nanchor.pos_: " << anchor().pos_;
224 lyxerr << "\n===================^^^^^^^^^^^^=====================\n\n\n";
229 void MathCursor::seldump(char const *) const {}
230 void MathCursor::dump(char const *) const {}
235 UpdatableInset * MathCursor::asHyperActiveInset() const
237 return par()->asHyperActiveInset();
241 bool MathCursor::isInside(MathInset const * p) const
243 for (unsigned i = 0; i < Cursor_.size(); ++i)
244 if (Cursor_[i].par_->nucleus() == p)
250 bool MathCursor::openable(MathAtom const & t, bool sel) const
252 if (t->isHyperActive())
258 if (t->asScriptInset())
262 // we can't move into anything new during selection
263 if (Cursor_.size() == Anchor_.size())
265 if (&t != Anchor_[Cursor_.size()].par_)
272 bool MathCursor::positionable(MathAtom const & t, int x, int y) const
275 // we can't move into anything new during selection
276 if (Cursor_.size() == Anchor_.size())
278 //if (t != Anchor_[Cursor_.size()].par_)
282 return t->nargs() && t->covers(x, y);
286 bool MathCursor::posLeft()
295 bool MathCursor::posRight()
304 bool MathCursor::left(bool sel)
309 lastcode_ = LM_TC_VAR;
313 lastcode_ = LM_TC_VAR;
315 if (hasPrevAtom() && openable(prevAtom(), sel)) {
316 if (prevAtom()->isHyperActive()) {
317 lyxerr << "entering hyperactive inset\n";
319 pushRight(prevAtom());
323 return posLeft() || idxLeft() || popLeft() || selection_;
327 bool MathCursor::right(bool sel)
332 lastcode_ = LM_TC_VAR;
336 lastcode_ = LM_TC_VAR;
338 if (hasNextAtom() && openable(nextAtom(), sel)) {
339 if (nextAtom()->isHyperActive()) {
340 lyxerr << "entering hyperactive inset\n";
343 nextAtom()->edit(formula()->view(), x, y, 0);
345 pushLeft(nextAtom());
349 return posRight() || idxRight() || popRight() || selection_;
353 void MathCursor::first()
356 pushLeft(formula_->par());
360 void MathCursor::last()
367 void MathCursor::setPos(int x, int y)
370 //lyxerr << "MathCursor::setPos x: " << x << " y: " << y << "\n";
373 lastcode_ = LM_TC_VAR;
376 cursor().par_ = &formula_->par();
381 //lyxerr << "found idx: " << idx() << " cursor: " << pos() << "\n";
382 int distmin = 1 << 30; // large enough
383 for (unsigned int i = 0; i < par()->nargs(); ++i) {
384 MathXArray const & ar = par()->xcell(i);
385 int x1 = x - ar.xo();
386 int y1 = y - ar.yo();
387 MathXArray::size_type c = ar.x2pos(x1);
388 int xx = abs(x1 - ar.pos2x(c));
390 //lyxerr << "idx: " << i << " xx: " << xx << " yy: " << yy
391 // << " c: " << c << " xo: " << ar.xo() << "\n";
392 if (yy + xx <= distmin) {
398 //lyxerr << "found idx: " << idx() << " cursor: "
400 if (hasNextAtom() && positionable(nextAtom(), x, y))
401 pushLeft(nextAtom());
402 else if (hasPrevAtom() && positionable(prevAtom(), x, y))
403 pushRight(prevAtom());
411 void MathCursor::home(bool sel)
416 lastcode_ = LM_TC_VAR;
417 if (!par()->idxHome(idx(), pos()))
423 void MathCursor::end(bool sel)
428 lastcode_ = LM_TC_VAR;
429 if (!par()->idxEnd(idx(), pos()))
435 void MathCursor::plainErase()
437 array().erase(pos());
441 void MathCursor::plainInsert(MathAtom const & t)
443 array().insert(pos(), t);
448 void MathCursor::insert(char c, MathTextCodes t)
450 //lyxerr << "inserting '" << c << "'\n";
451 plainInsert(MathAtom(new MathCharInset(c, t)));
455 void MathCursor::insert(MathAtom const & t)
470 void MathCursor::niceInsert(MathAtom const & t)
473 insert(t); // inserting invalidates the pointer!
474 MathAtom const & p = prevAtom();
477 right(); // do not push for e.g. MathSymbolInset
481 #warning "redraw disabled"
483 //p->metrics(p->size());
487 void MathCursor::insert(MathArray const & ar)
493 array().insert(pos(), ar);
498 void MathCursor::paste(MathArray const & ar)
502 array().insert(pos(), ar);
507 void MathCursor::backspace()
519 MathScriptInset * p = prevAtom()->asScriptInset();
521 p->removeScript(p->hasUp());
522 // Don't delete if there is anything left
523 if (p->hasUp() || p->hasDown())
532 void MathCursor::erase()
542 // delete empty cells if necessary
543 if (array().empty()) {
546 par()->idxDelete(idx(), popit, removeit);
547 if (popit && popLeft() && removeit)
555 MathScriptInset * p = nextAtom()->asScriptInset();
557 p->removeScript(p->hasUp());
558 // Don't delete if there is anything left
559 if (p->hasUp() || p->hasDown())
567 void MathCursor::delLine()
576 if (par()->nrows() > 1)
577 par()->delRow(row());
584 bool MathCursor::up(bool sel)
591 // check whether we could move into a superscript
593 MathAtom & p = prevAtom();
594 if (p->asScriptInset() && p->asScriptInset()->hasUp()) {
603 MathAtom & n = nextAtom();
604 if (n->asScriptInset() && n->asScriptInset()->hasUp()) {
613 return goUp() || selection_;
617 bool MathCursor::down(bool sel)
624 // check whether we could move into a subscript
626 MathAtom & p = prevAtom();
627 if (p->asScriptInset() && p->asScriptInset()->hasDown()) {
636 MathAtom & n = nextAtom();
637 if (n->asScriptInset() && n->asScriptInset()->hasDown()) {
646 return goDown() || selection_;
650 bool MathCursor::toggleLimits()
654 MathScriptInset * t = prevAtom()->asScriptInset();
657 int old = t->limits();
658 t->limits(old < 0 ? 1 : -1);
659 return old != t->limits();
663 void MathCursor::macroModeClose()
665 string s = macroName();
667 size_type old = pos();
669 array().erase(pos(), old);
675 int MathCursor::macroNamePos() const
677 for (int i = pos() - 1; i >= 0; --i) {
678 MathAtom & p = array().at(i);
679 if (p->code() == LM_TC_TEX && p->getChar() == '\\')
686 string MathCursor::macroName() const
689 for (int i = macroNamePos(); i >= 0 && i < int(pos()); ++i)
690 s += array().at(i)->getChar();
695 void MathCursor::selCopy()
699 theSelection.grab(*this);
705 void MathCursor::selCut()
709 theSelection.grab(*this);
710 theSelection.erase(*this);
713 theSelection.clear();
718 void MathCursor::selDel()
722 theSelection.erase(*this);
730 void MathCursor::selPaste()
733 theSelection.paste(*this);
734 theSelection.grab(*this);
739 void MathCursor::selHandle(bool sel)
741 if (sel == selection_)
744 theSelection.clear();
750 void MathCursor::selStart()
756 theSelection.clear();
762 void MathCursor::selClear()
769 void MathCursor::selGet(MathArray & ar)
775 theSelection.grab(*this);
776 ar = theSelection.glue();
781 void MathCursor::drawSelection(Painter & pain) const
788 getSelection(i1, i2);
790 //lyxerr << "selection from: " << i1 << " to " << i2 << "\n";
792 if (i1.idx_ == i2.idx_) {
793 MathXArray & c = i1.xcell();
794 int x1 = c.xo() + c.pos2x(i1.pos_);
795 int y1 = c.yo() - c.ascent();
796 int x2 = c.xo() + c.pos2x(i2.pos_);
797 int y2 = c.yo() + c.descent();
798 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
800 std::vector<MathInset::idx_type> indices
801 = (*i1.par_)->idxBetween(i1.idx_, i2.idx_);
802 for (unsigned i = 0; i < indices.size(); ++i) {
803 MathXArray & c = i1.xcell(indices[i]);
805 int y1 = c.yo() - c.ascent();
806 int x2 = c.xo() + c.width();
807 int y2 = c.yo() + c.descent();
808 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
814 void MathCursor::handleFont(MathTextCodes t)
820 getSelection(i1, i2);
821 if (i1.idx_ == i2.idx_) {
822 MathArray & ar = i1.cell();
823 for (MathInset::pos_type pos = i1.pos_; pos != i2.pos_; ++pos)
824 ar.at(pos)->handleFont(t);
827 lastcode_ = (lastcode_ == t) ? LM_TC_VAR : t;
831 void MathCursor::handleDelim(string const & l, string const & r)
833 handleNest(new MathDelimInset(l, r));
837 void MathCursor::handleNest(MathInset * p)
841 p->cell(0) = theSelection.glue();
843 insert(MathAtom(p)); // this invalidates p!
844 pushRight(prevAtom());
848 void MathCursor::getPos(int & x, int & y)
851 #warning This should probably take cellXOffset and cellYOffset into account
853 x = xarray().xo() + xarray().pos2x(pos());
858 MathAtom & MathCursor::par() const
860 return *cursor().par_;
864 InsetFormulaBase const * MathCursor::formula()
870 MathCursor::idx_type MathCursor::idx() const
872 return cursor().idx_;
876 MathCursor::idx_type & MathCursor::idx()
878 return cursor().idx_;
882 MathCursor::pos_type MathCursor::pos() const
884 return cursor().pos_;
888 MathCursor::pos_type & MathCursor::pos()
890 return cursor().pos_;
894 bool MathCursor::inMacroMode() const
896 return macroNamePos() != -1;
900 bool MathCursor::selection() const
906 MathArrayInset * MathCursor::enclosingArray(MathCursor::idx_type & idx) const
908 for (int i = Cursor_.size() - 1; i >= 0; --i) {
909 MathArrayInset * p = (*Cursor_[i].par_)->asArrayInset();
911 idx = Cursor_[i].idx_;
919 void MathCursor::pullArg(bool goright)
922 MathArray a = array();
924 MathScriptInset const * p = par()->asScriptInset();
926 // special handling for scripts
927 const bool up = p->hasUp();
929 MathScriptInset * q = nextAtom()->asScriptInset();
933 array().insert(pos(), a);
939 array().insert(pos(), a);
946 void MathCursor::normalize() const
949 #warning This is evil!
951 MathCursor * it = const_cast<MathCursor *>(this);
953 if (idx() >= par()->nargs()) {
954 lyxerr << "this should not really happen - 1: "
955 << idx() << " " << par()->nargs() << "\n";
958 it->idx() = min(idx(), par()->nargs() - 1);
960 if (pos() > size()) {
961 lyxerr << "this should not really happen - 2: "
962 << pos() << " " << size() << " in idx: " << it->idx()
964 MathWriteInfo wi(0, lyxerr, false);
965 it->par()->write(wi);
969 it->pos() = min(pos(), size());
973 MathCursor::size_type MathCursor::size() const
975 return array().size();
979 MathCursor::col_type MathCursor::col() const
981 return par()->col(idx());
985 MathCursor::row_type MathCursor::row() const
987 return par()->row(idx());
991 bool MathCursor::hasPrevAtom() const
997 bool MathCursor::hasNextAtom() const
999 return pos() < size();
1003 MathAtom const & MathCursor::prevAtom() const
1005 lyx::Assert(pos() > 0);
1006 return array().at(pos() - 1);
1010 MathAtom & MathCursor::prevAtom()
1012 lyx::Assert(pos() > 0);
1013 return array().at(pos() - 1);
1017 MathAtom const & MathCursor::nextAtom() const
1019 lyx::Assert(pos() < size());
1020 return array().at(pos());
1024 MathAtom & MathCursor::nextAtom()
1026 lyx::Assert(pos() < size());
1027 return array().at(pos());
1031 MathArray & MathCursor::array() const
1033 static MathArray dummy;
1035 if (idx() >= par()->nargs()) {
1036 lyxerr << "############ idx_ " << idx() << " not valid\n";
1040 return cursor().cell();
1044 MathXArray & MathCursor::xarray() const
1046 return cursor().xcell();
1050 void MathCursor::idxNext()
1052 par()->idxNext(idx(), pos());
1056 void MathCursor::idxPrev()
1058 par()->idxPrev(idx(), pos());
1062 void MathCursor::splitCell()
1064 if (idx() == par()->nargs() - 1)
1066 MathArray ar = array();
1068 array().erase(pos(), size());
1071 array().insert(0, ar);
1075 void MathCursor::breakLine()
1077 // leave inner cells
1081 MathMatrixInset * p = formula()->par()->asMatrixInset();
1085 if (p->getType() == LM_OT_SIMPLE || p->getType() == LM_OT_EQUATION) {
1086 p->mutate(LM_OT_EQNARRAY);
1093 const row_type r = row();
1094 for (col_type c = col() + 1; c < p->ncols(); ++c) {
1095 const MathMatrixInset::idx_type i1 = p->index(r, c);
1096 const MathMatrixInset::idx_type i2 = p->index(r + 1, c);
1097 //lyxerr << "swapping cells " << i1 << " and " << i2 << "\n";
1098 p->cell(i1).swap(p->cell(i2));
1103 p->cell(idx()).swap(p->cell(idx() + p->ncols() - 1));
1108 char MathCursor::valign() const
1111 MathArrayInset * p = enclosingArray(idx);
1112 return p ? p->valign() : '\0';
1116 char MathCursor::halign() const
1119 MathArrayInset * p = enclosingArray(idx);
1120 return p ? p->halign(idx % p->ncols()) : '\0';
1124 void MathCursor::getSelection(MathCursorPos & i1, MathCursorPos & i2) const
1126 MathCursorPos anc = normalAnchor();
1127 if (anc < cursor()) {
1137 MathCursorPos & MathCursor::cursor()
1139 return Cursor_.back();
1143 MathCursorPos const & MathCursor::cursor() const
1145 return Cursor_.back();
1149 int MathCursor::cellXOffset() const
1151 return par()->cellXOffset(idx());
1155 int MathCursor::cellYOffset() const
1157 return par()->cellYOffset(idx());
1161 int MathCursor::xpos() const
1163 return cellXOffset() + xarray().pos2x(pos());
1167 int MathCursor::ypos() const
1169 return cellYOffset();
1174 void MathCursor::gotoX(int x)
1176 pos() = xarray().x2pos(x - cellXOffset());
1180 bool MathCursor::goUp()
1182 // first ask the inset if it knows better then we
1183 if (par()->idxUp(idx(), pos()))
1186 // leave subscript to the nearest side
1187 MathScriptInset * p = par()->asScriptInset();
1188 if (p && idx() == 0) {
1189 if (pos() <= size() / 2)
1196 // if not, apply brute force.
1200 std::vector<MathCursorPos> save = Cursor_;
1201 y0 -= xarray().ascent();
1202 for (int y = y0 - 4; y > formula()->upperY(); y -= 4) {
1204 if (save != Cursor_ && xarray().yo() < y0)
1212 bool MathCursor::goDown()
1214 // first ask the inset if it knows better then we
1215 if (par()->idxDown(idx(), pos()))
1218 // leave superscript to the nearest side
1219 MathScriptInset * p = par()->asScriptInset();
1220 if (p && idx() == 1) {
1221 if (pos() <= size() / 2)
1228 // if not, apply brute force.
1232 std::vector<MathCursorPos> save = Cursor_;
1233 y0 += xarray().descent();
1234 for (int y = y0 + 4; y < formula()->lowerY(); y += 4) {
1236 if (save != Cursor_ && xarray().yo() > y0)
1244 bool MathCursor::idxLeft()
1246 return par()->idxLeft(idx(), pos());
1250 bool MathCursor::idxRight()
1252 return par()->idxRight(idx(), pos());
1256 void MathCursor::interpret(string const & s)
1258 //lyxerr << "interpret 1: '" << s << "'\n";
1262 if (s.size() == 1) {
1267 //lyxerr << "char: '" << s[0] << "' int: " << int(s[0]) << endl;
1268 //owner_->getIntl()->getTrans().TranslateAndInsert(s[0], lt);
1269 //lyxerr << "trans: '" << s[0] << "' int: " << int(s[0]) << endl;
1271 if (s.size() > 7 && s.substr(0, 7) == "matrix ") {
1276 istringstream is(s.substr(7).c_str());
1277 is >> m >> n >> v_align >> h_align;
1278 m = std::max(1u, m);
1279 n = std::max(1u, n);
1281 niceInsert(MathAtom(new MathArrayInset(m, n, v_align[0], h_align)));
1285 if (s == "\\over" || s == "\\choose" || s == "\\atop") {
1286 MathArray ar = array();
1287 MathAtom t = createMathInset(s.substr(1));
1288 t->asNestInset()->cell(0).swap(array());
1296 niceInsert(createMathInset(s.substr(1)));
1300 void MathCursor::interpret(char c)
1302 //lyxerr << "interpret 2: '" << c << "'\n";
1304 if (inMacroMode()) {
1305 string name = macroName();
1307 if (name == "\\" && c == '#') {
1308 insert(c, LM_TC_TEX);
1312 if (name == "\\" && c == '\\') {
1314 interpret("\\backslash");
1318 if (name == "\\#" && '1' <= c && c <= '9') {
1319 insert(c, LM_TC_TEX);
1325 insert(c, LM_TC_TEX);
1330 insert(c, LM_TC_TEX);
1340 if (c == '^' || c == '_') {
1341 const bool up = (c == '^');
1343 if (hasPrevAtom() && prevAtom()->asScriptInset()) {
1344 prevAtom()->asScriptInset()->ensure(up);
1345 pushRight(prevAtom());
1348 } else if (hasNextAtom() && nextAtom()->asScriptInset()) {
1349 nextAtom()->asScriptInset()->ensure(up);
1350 pushLeft(nextAtom());
1354 plainInsert(MathAtom(new MathScriptInset(up)));
1355 prevAtom()->asScriptInset()->ensure(up);
1356 pushRight(prevAtom());
1368 if (lastcode_ == LM_TC_TEXTRM) {
1369 // suppress direct insertion of to spaces in a row
1370 // the still allows typing '<space>a<space>' and deleting the 'a', but
1371 // it is better than nothing
1372 if (hasPrevAtom() && prevAtom()->getChar() == ' ')
1374 insert(c, LM_TC_TEXTRM);
1379 if (hasPrevAtom() && prevAtom()->asSpaceInset()) {
1380 prevAtom()->asSpaceInset()->incSpace();
1384 mathcursor->popRight();
1388 if (strchr("{}", c)) {
1389 insert(c, LM_TC_TEX);
1393 if (strchr("#$%", c)) {
1394 insert(MathAtom(new MathSpecialCharInset(c)));
1395 lastcode_ = LM_TC_VAR;
1399 if (isalpha(c) && lastcode_ == LM_TC_GREEK) {
1400 insert(c, LM_TC_VAR);
1404 if (isalpha(c) && lastcode_ == LM_TC_GREEK1) {
1405 insert(c, LM_TC_VAR);
1406 lastcode_ = LM_TC_VAR;
1411 insert(c, LM_TC_TEX);
1412 //bv->owner()->message(_("TeX mode"));
1416 // no special circumstances, so insert the character without any fuss
1417 insert(c, LM_TC_MIN);
1422 ////////////////////////////////////////////////////////////////////////
1425 bool operator==(MathCursorPos const & ti, MathCursorPos const & it)
1427 return ti.par_ == it.par_ && ti.idx_ == it.idx_ && ti.pos_ == it.pos_;
1431 bool operator<(MathCursorPos const & ti, MathCursorPos const & it)
1433 if (ti.par_ != it.par_) {
1434 lyxerr << "can't compare cursor and anchor in different insets\n";
1437 if (ti.idx_ != it.idx_)
1438 return ti.idx_ < it.idx_;
1439 return ti.pos_ < it.pos_;
1443 MathArray & MathCursorPos::cell(MathCursor::idx_type idx) const
1445 return (*par_)->cell(idx);
1449 MathArray & MathCursorPos::cell() const
1451 return (*par_)->cell(idx_);
1455 MathXArray & MathCursorPos::xcell(MathCursor::idx_type idx) const
1457 return (*par_)->xcell(idx);
1461 MathXArray & MathCursorPos::xcell() const
1463 return (*par_)->xcell(idx_);
1467 MathCursorPos MathCursor::normalAnchor() const
1469 // use Anchor on the same level as Cursor
1470 MathCursorPos normal = Anchor_[Cursor_.size() - 1];
1471 if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) {
1472 // anchor is behind cursor -> move anchor behind the inset