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 bool MathCursor::isInside(MathInset const * p) const
237 for (unsigned i = 0; i < Cursor_.size(); ++i)
238 if (Cursor_[i].par_->nucleus() == p)
244 bool MathCursor::openable(MathAtom const & t, bool sel) const
246 if (t->isHyperActive())
252 if (t->asScriptInset())
256 // we can't move into anything new during selection
257 if (Cursor_.size() == Anchor_.size())
259 if (&t != Anchor_[Cursor_.size()].par_)
266 bool MathCursor::positionable(MathAtom const & t, int x, int y) const
269 // we can't move into anything new during selection
270 if (Cursor_.size() == Anchor_.size())
272 //if (t != Anchor_[Cursor_.size()].par_)
276 return t->nargs() && t->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 if (hasPrevAtom() && openable(prevAtom(), sel)) {
310 if (prevAtom()->isHyperActive()) {
311 lyxerr << "entering hyperactive inset\n";
313 pushRight(prevAtom());
317 return posLeft() || idxLeft() || popLeft() || selection_;
321 bool MathCursor::right(bool sel)
326 lastcode_ = LM_TC_VAR;
330 lastcode_ = LM_TC_VAR;
332 if (hasNextAtom() && openable(nextAtom(), sel)) {
333 if (nextAtom()->isHyperActive()) {
334 lyxerr << "entering hyperactive inset\n";
336 pushLeft(nextAtom());
340 return posRight() || idxRight() || popRight() || selection_;
344 void MathCursor::first()
347 pushLeft(formula_->par());
351 void MathCursor::last()
358 void MathCursor::setPos(int x, int y)
361 //lyxerr << "MathCursor::setPos x: " << x << " y: " << y << "\n";
364 lastcode_ = LM_TC_VAR;
367 cursor().par_ = &formula_->par();
372 //lyxerr << "found idx: " << idx() << " cursor: " << pos() << "\n";
373 int distmin = 1 << 30; // large enough
374 for (unsigned int i = 0; i < par()->nargs(); ++i) {
375 MathXArray const & ar = par()->xcell(i);
376 int x1 = x - ar.xo();
377 int y1 = y - ar.yo();
378 MathXArray::size_type c = ar.x2pos(x1);
379 int xx = abs(x1 - ar.pos2x(c));
381 //lyxerr << "idx: " << i << " xx: " << xx << " yy: " << yy
382 // << " c: " << c << " xo: " << ar.xo() << "\n";
383 if (yy + xx <= distmin) {
389 //lyxerr << "found idx: " << idx() << " cursor: "
391 if (hasNextAtom() && positionable(nextAtom(), x, y))
392 pushLeft(nextAtom());
393 else if (hasPrevAtom() && positionable(prevAtom(), x, y))
394 pushRight(prevAtom());
402 void MathCursor::home(bool sel)
407 lastcode_ = LM_TC_VAR;
408 if (!par()->idxHome(idx(), pos()))
414 void MathCursor::end(bool sel)
419 lastcode_ = LM_TC_VAR;
420 if (!par()->idxEnd(idx(), pos()))
426 void MathCursor::plainErase()
428 array().erase(pos());
432 void MathCursor::plainInsert(MathAtom const & t)
434 array().insert(pos(), t);
439 void MathCursor::insert(char c, MathTextCodes t)
441 //lyxerr << "inserting '" << c << "'\n";
442 plainInsert(MathAtom(new MathCharInset(c, t)));
446 void MathCursor::insert(MathAtom const & t)
461 void MathCursor::niceInsert(MathAtom const & t)
464 insert(t); // inserting invalidates the pointer!
465 MathAtom const & p = prevAtom();
468 right(); // do not push for e.g. MathSymbolInset
472 #warning "redraw disabled"
474 //p->metrics(p->size());
478 void MathCursor::insert(MathArray const & ar)
484 array().insert(pos(), ar);
489 void MathCursor::paste(MathArray const & ar)
493 array().insert(pos(), ar);
498 void MathCursor::backspace()
510 MathScriptInset * p = prevAtom()->asScriptInset();
512 p->removeScript(p->hasUp());
513 // Don't delete if there is anything left
514 if (p->hasUp() || p->hasDown())
523 void MathCursor::erase()
533 // delete empty cells if necessary
534 if (array().empty()) {
537 par()->idxDelete(idx(), popit, removeit);
538 if (popit && popLeft() && removeit)
546 MathScriptInset * p = nextAtom()->asScriptInset();
548 p->removeScript(p->hasUp());
549 // Don't delete if there is anything left
550 if (p->hasUp() || p->hasDown())
558 void MathCursor::delLine()
567 if (par()->nrows() > 1)
568 par()->delRow(row());
575 bool MathCursor::up(bool sel)
582 // check whether we could move into a superscript
584 MathAtom & p = prevAtom();
585 if (p->asScriptInset() && p->asScriptInset()->hasUp()) {
594 MathAtom & n = nextAtom();
595 if (n->asScriptInset() && n->asScriptInset()->hasUp()) {
604 return goUp() || selection_;
608 bool MathCursor::down(bool sel)
615 // check whether we could move into a subscript
617 MathAtom & p = prevAtom();
618 if (p->asScriptInset() && p->asScriptInset()->hasDown()) {
627 MathAtom & n = nextAtom();
628 if (n->asScriptInset() && n->asScriptInset()->hasDown()) {
637 return goDown() || selection_;
641 bool MathCursor::toggleLimits()
645 MathScriptInset * t = prevAtom()->asScriptInset();
648 int old = t->limits();
649 t->limits(old < 0 ? 1 : -1);
650 return old != t->limits();
654 void MathCursor::macroModeClose()
656 string s = macroName();
658 size_type old = pos();
660 array().erase(pos(), old);
666 int MathCursor::macroNamePos() const
668 for (int i = pos() - 1; i >= 0; --i) {
669 MathAtom & p = array().at(i);
670 if (p->code() == LM_TC_TEX && p->getChar() == '\\')
677 string MathCursor::macroName() const
680 for (int i = macroNamePos(); i >= 0 && i < int(pos()); ++i)
681 s += array().at(i)->getChar();
686 void MathCursor::selCopy()
690 theSelection.grab(*this);
696 void MathCursor::selCut()
700 theSelection.grab(*this);
701 theSelection.erase(*this);
704 theSelection.clear();
709 void MathCursor::selDel()
713 theSelection.erase(*this);
721 void MathCursor::selPaste()
724 theSelection.paste(*this);
725 theSelection.grab(*this);
730 void MathCursor::selHandle(bool sel)
732 if (sel == selection_)
735 theSelection.clear();
741 void MathCursor::selStart()
747 theSelection.clear();
753 void MathCursor::selClear()
760 void MathCursor::selGet(MathArray & ar)
766 theSelection.grab(*this);
767 ar = theSelection.glue();
772 void MathCursor::drawSelection(Painter & pain) const
779 getSelection(i1, i2);
781 //lyxerr << "selection from: " << i1 << " to " << i2 << "\n";
783 if (i1.idx_ == i2.idx_) {
784 MathXArray & c = i1.xcell();
785 int x1 = c.xo() + c.pos2x(i1.pos_);
786 int y1 = c.yo() - c.ascent();
787 int x2 = c.xo() + c.pos2x(i2.pos_);
788 int y2 = c.yo() + c.descent();
789 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
791 std::vector<MathInset::idx_type> indices
792 = (*i1.par_)->idxBetween(i1.idx_, i2.idx_);
793 for (unsigned i = 0; i < indices.size(); ++i) {
794 MathXArray & c = i1.xcell(indices[i]);
796 int y1 = c.yo() - c.ascent();
797 int x2 = c.xo() + c.width();
798 int y2 = c.yo() + c.descent();
799 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
805 void MathCursor::handleFont(MathTextCodes t)
811 getSelection(i1, i2);
812 if (i1.idx_ == i2.idx_) {
813 MathArray & ar = i1.cell();
814 for (MathInset::pos_type pos = i1.pos_; pos != i2.pos_; ++pos)
815 ar.at(pos)->handleFont(t);
818 lastcode_ = (lastcode_ == t) ? LM_TC_VAR : t;
822 void MathCursor::handleDelim(string const & l, string const & r)
824 handleNest(new MathDelimInset(l, r));
828 void MathCursor::handleNest(MathInset * p)
832 p->cell(0) = theSelection.glue();
834 insert(MathAtom(p)); // this invalidates p!
835 pushRight(prevAtom());
839 void MathCursor::getPos(int & x, int & y)
842 #warning This should probably take cellXOffset and cellYOffset into account
844 x = xarray().xo() + xarray().pos2x(pos());
849 MathAtom & MathCursor::par() const
851 return *cursor().par_;
855 InsetFormulaBase const * MathCursor::formula()
861 MathCursor::idx_type MathCursor::idx() const
863 return cursor().idx_;
867 MathCursor::idx_type & MathCursor::idx()
869 return cursor().idx_;
873 MathCursor::pos_type MathCursor::pos() const
875 return cursor().pos_;
879 MathCursor::pos_type & MathCursor::pos()
881 return cursor().pos_;
885 bool MathCursor::inMacroMode() const
887 return macroNamePos() != -1;
891 bool MathCursor::selection() const
897 MathArrayInset * MathCursor::enclosingArray(MathCursor::idx_type & idx) const
899 for (int i = Cursor_.size() - 1; i >= 0; --i) {
900 MathArrayInset * p = (*Cursor_[i].par_)->asArrayInset();
902 idx = Cursor_[i].idx_;
910 void MathCursor::pullArg(bool goright)
913 MathArray a = array();
915 MathScriptInset const * p = par()->asScriptInset();
917 // special handling for scripts
918 const bool up = p->hasUp();
920 MathScriptInset * q = nextAtom()->asScriptInset();
924 array().insert(pos(), a);
930 array().insert(pos(), a);
937 void MathCursor::normalize() const
940 #warning This is evil!
942 MathCursor * it = const_cast<MathCursor *>(this);
944 if (idx() >= par()->nargs()) {
945 lyxerr << "this should not really happen - 1: "
946 << idx() << " " << par()->nargs() << "\n";
949 it->idx() = min(idx(), par()->nargs() - 1);
951 if (pos() > size()) {
952 lyxerr << "this should not really happen - 2: "
953 << pos() << " " << size() << " in idx: " << it->idx()
955 MathWriteInfo wi(0, lyxerr, false);
956 it->par()->write(wi);
960 it->pos() = min(pos(), size());
964 MathCursor::size_type MathCursor::size() const
966 return array().size();
970 MathCursor::col_type MathCursor::col() const
972 return par()->col(idx());
976 MathCursor::row_type MathCursor::row() const
978 return par()->row(idx());
982 bool MathCursor::hasPrevAtom() const
988 bool MathCursor::hasNextAtom() const
990 return pos() < size();
994 MathAtom const & MathCursor::prevAtom() const
996 lyx::Assert(pos() > 0);
997 return array().at(pos() - 1);
1001 MathAtom & MathCursor::prevAtom()
1003 lyx::Assert(pos() > 0);
1004 return array().at(pos() - 1);
1008 MathAtom const & MathCursor::nextAtom() const
1010 lyx::Assert(pos() < size());
1011 return array().at(pos());
1015 MathAtom & MathCursor::nextAtom()
1017 lyx::Assert(pos() < size());
1018 return array().at(pos());
1022 MathArray & MathCursor::array() const
1024 static MathArray dummy;
1026 if (idx() >= par()->nargs()) {
1027 lyxerr << "############ idx_ " << idx() << " not valid\n";
1031 return cursor().cell();
1035 MathXArray & MathCursor::xarray() const
1037 return cursor().xcell();
1041 void MathCursor::idxNext()
1043 par()->idxNext(idx(), pos());
1047 void MathCursor::idxPrev()
1049 par()->idxPrev(idx(), pos());
1053 void MathCursor::splitCell()
1055 if (idx() == par()->nargs() - 1)
1057 MathArray ar = array();
1059 array().erase(pos(), size());
1062 array().insert(0, ar);
1066 void MathCursor::breakLine()
1068 // leave inner cells
1072 MathMatrixInset * p = formula()->par()->asMatrixInset();
1076 if (p->getType() == LM_OT_SIMPLE || p->getType() == LM_OT_EQUATION) {
1077 p->mutate(LM_OT_EQNARRAY);
1084 const row_type r = row();
1085 for (col_type c = col() + 1; c < p->ncols(); ++c) {
1086 const MathMatrixInset::idx_type i1 = p->index(r, c);
1087 const MathMatrixInset::idx_type i2 = p->index(r + 1, c);
1088 //lyxerr << "swapping cells " << i1 << " and " << i2 << "\n";
1089 p->cell(i1).swap(p->cell(i2));
1094 p->cell(idx()).swap(p->cell(idx() + p->ncols() - 1));
1099 char MathCursor::valign() const
1102 MathArrayInset * p = enclosingArray(idx);
1103 return p ? p->valign() : '\0';
1107 char MathCursor::halign() const
1110 MathArrayInset * p = enclosingArray(idx);
1111 return p ? p->halign(idx % p->ncols()) : '\0';
1115 void MathCursor::getSelection(MathCursorPos & i1, MathCursorPos & i2) const
1117 MathCursorPos anc = normalAnchor();
1118 if (anc < cursor()) {
1128 MathCursorPos & MathCursor::cursor()
1130 return Cursor_.back();
1134 MathCursorPos const & MathCursor::cursor() const
1136 return Cursor_.back();
1140 int MathCursor::cellXOffset() const
1142 return par()->cellXOffset(idx());
1146 int MathCursor::cellYOffset() const
1148 return par()->cellYOffset(idx());
1152 int MathCursor::xpos() const
1154 return cellXOffset() + xarray().pos2x(pos());
1158 int MathCursor::ypos() const
1160 return cellYOffset();
1165 void MathCursor::gotoX(int x)
1167 pos() = xarray().x2pos(x - cellXOffset());
1171 bool MathCursor::goUp()
1173 // first ask the inset if it knows better then we
1174 if (par()->idxUp(idx(), pos()))
1177 // leave subscript to the nearest side
1178 MathScriptInset * p = par()->asScriptInset();
1179 if (p && idx() == 0) {
1180 if (pos() <= size() / 2)
1187 // if not, apply brute force.
1191 std::vector<MathCursorPos> save = Cursor_;
1192 y0 -= xarray().ascent();
1193 for (int y = y0 - 4; y > formula()->upperY(); y -= 4) {
1195 if (save != Cursor_ && xarray().yo() < y0)
1203 bool MathCursor::goDown()
1205 // first ask the inset if it knows better then we
1206 if (par()->idxDown(idx(), pos()))
1209 // leave superscript to the nearest side
1210 MathScriptInset * p = par()->asScriptInset();
1211 if (p && idx() == 1) {
1212 if (pos() <= size() / 2)
1219 // if not, apply brute force.
1223 std::vector<MathCursorPos> save = Cursor_;
1224 y0 += xarray().descent();
1225 for (int y = y0 + 4; y < formula()->lowerY(); y += 4) {
1227 if (save != Cursor_ && xarray().yo() > y0)
1235 bool MathCursor::idxLeft()
1237 return par()->idxLeft(idx(), pos());
1241 bool MathCursor::idxRight()
1243 return par()->idxRight(idx(), pos());
1247 void MathCursor::interpret(string const & s)
1249 //lyxerr << "interpret 1: '" << s << "'\n";
1253 if (s.size() == 1) {
1258 //lyxerr << "char: '" << s[0] << "' int: " << int(s[0]) << endl;
1259 //owner_->getIntl()->getTrans().TranslateAndInsert(s[0], lt);
1260 //lyxerr << "trans: '" << s[0] << "' int: " << int(s[0]) << endl;
1262 if (s.size() > 7 && s.substr(0, 7) == "matrix ") {
1267 istringstream is(s.substr(7).c_str());
1268 is >> m >> n >> v_align >> h_align;
1269 m = std::max(1u, m);
1270 n = std::max(1u, n);
1272 niceInsert(MathAtom(new MathArrayInset(m, n, v_align[0], h_align)));
1276 if (s == "\\over" || s == "\\choose" || s == "\\atop") {
1277 MathArray ar = array();
1278 MathAtom t = createMathInset(s.substr(1));
1279 t->asNestInset()->cell(0).swap(array());
1287 niceInsert(createMathInset(s.substr(1)));
1291 void MathCursor::interpret(char c)
1293 //lyxerr << "interpret 2: '" << c << "'\n";
1295 if (inMacroMode()) {
1296 string name = macroName();
1298 if (name == "\\" && c == '#') {
1299 insert(c, LM_TC_TEX);
1303 if (name == "\\" && c == '\\') {
1305 interpret("\\backslash");
1309 if (name == "\\#" && '1' <= c && c <= '9') {
1310 insert(c, LM_TC_TEX);
1316 insert(c, LM_TC_TEX);
1321 insert(c, LM_TC_TEX);
1331 if (c == '^' || c == '_') {
1332 const bool up = (c == '^');
1334 if (hasPrevAtom() && prevAtom()->asScriptInset()) {
1335 prevAtom()->asScriptInset()->ensure(up);
1336 pushRight(prevAtom());
1339 } else if (hasNextAtom() && nextAtom()->asScriptInset()) {
1340 nextAtom()->asScriptInset()->ensure(up);
1341 pushLeft(nextAtom());
1345 plainInsert(MathAtom(new MathScriptInset(up)));
1346 prevAtom()->asScriptInset()->ensure(up);
1347 pushRight(prevAtom());
1359 if (lastcode_ == LM_TC_TEXTRM) {
1360 insert(c, LM_TC_TEXTRM);
1365 if (hasPrevAtom() && prevAtom()->asSpaceInset()) {
1366 prevAtom()->asSpaceInset()->incSpace();
1370 if (mathcursor->popRight())
1374 // this would not work if the inset is in an table!
1375 //bv->text->cursorRight(bv, true);
1376 //result = FINISHED;
1380 if (strchr("{}", c)) {
1381 insert(c, LM_TC_TEX);
1385 if (strchr("#$%", c)) {
1386 insert(MathAtom(new MathSpecialCharInset(c)));
1387 lastcode_ = LM_TC_VAR;
1391 if (isalpha(c) && lastcode_ == LM_TC_GREEK) {
1392 insert(c, LM_TC_VAR);
1396 if (isalpha(c) && lastcode_ == LM_TC_GREEK1) {
1397 insert(c, LM_TC_VAR);
1398 lastcode_ = LM_TC_VAR;
1403 insert(c, LM_TC_TEX);
1404 //bv->owner()->message(_("TeX mode"));
1408 // no special circumstances, so insert the character without any fuss
1409 insert(c, LM_TC_MIN);
1414 ////////////////////////////////////////////////////////////////////////
1417 bool operator==(MathCursorPos const & ti, MathCursorPos const & it)
1419 return ti.par_ == it.par_ && ti.idx_ == it.idx_ && ti.pos_ == it.pos_;
1423 bool operator<(MathCursorPos const & ti, MathCursorPos const & it)
1425 if (ti.par_ != it.par_) {
1426 lyxerr << "can't compare cursor and anchor in different insets\n";
1429 if (ti.idx_ != it.idx_)
1430 return ti.idx_ < it.idx_;
1431 return ti.pos_ < it.pos_;
1435 MathArray & MathCursorPos::cell(MathCursor::idx_type idx) const
1437 return (*par_)->cell(idx);
1441 MathArray & MathCursorPos::cell() const
1443 return (*par_)->cell(idx_);
1447 MathXArray & MathCursorPos::xcell(MathCursor::idx_type idx) const
1449 return (*par_)->xcell(idx);
1453 MathXArray & MathCursorPos::xcell() const
1455 return (*par_)->xcell(idx_);
1459 MathCursorPos MathCursor::normalAnchor() const
1461 // use Anchor on the same level as Cursor
1462 MathCursorPos normal = Anchor_[Cursor_.size() - 1];
1463 if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) {
1464 // anchor is behind cursor -> move anchor behind the inset