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
249 if (t->asScriptInset())
253 // we can't move into anything new during selection
254 if (Cursor_.size() == Anchor_.size())
256 if (&t != Anchor_[Cursor_.size()].par_)
263 bool MathCursor::positionable(MathAtom const & t, int x, int y) const
266 // we can't move into anything new during selection
267 if (Cursor_.size() == Anchor_.size())
269 //if (t != Anchor_[Cursor_.size()].par_)
273 return t->nargs() && t->covers(x, y);
277 bool MathCursor::posLeft()
286 bool MathCursor::posRight()
295 bool MathCursor::left(bool sel)
300 lastcode_ = LM_TC_VAR;
304 lastcode_ = LM_TC_VAR;
306 if (hasPrevAtom() && openable(prevAtom(), sel)) {
307 pushRight(prevAtom());
311 return posLeft() || idxLeft() || popLeft() || selection_;
315 bool MathCursor::right(bool sel)
320 lastcode_ = LM_TC_VAR;
324 lastcode_ = LM_TC_VAR;
326 if (hasNextAtom() && openable(nextAtom(), sel)) {
327 pushLeft(nextAtom());
331 return posRight() || idxRight() || popRight() || selection_;
335 void MathCursor::first()
338 pushLeft(formula_->par());
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_ = &formula_->par();
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 (hasNextAtom() && positionable(nextAtom(), x, y))
383 pushLeft(nextAtom());
384 else if (hasPrevAtom() && positionable(prevAtom(), x, y))
385 pushRight(prevAtom());
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::plainInsert(MathAtom const & t)
425 array().insert(pos(), t);
430 void MathCursor::insert(char c, MathTextCodes t)
432 //lyxerr << "inserting '" << c << "'\n";
433 plainInsert(MathAtom(new MathCharInset(c, t)));
437 void MathCursor::insert(MathAtom const & t)
452 void MathCursor::niceInsert(MathAtom const & t)
455 insert(t); // inserting invalidates the pointer!
456 MathAtom const & p = prevAtom();
459 right(); // do not push for e.g. MathSymbolInset
463 #warning "redraw disabled"
465 //p->metrics(p->size());
469 void MathCursor::insert(MathArray const & ar)
475 array().insert(pos(), ar);
480 void MathCursor::paste(MathArray const & ar)
484 array().insert(pos(), ar);
489 void MathCursor::backspace()
501 MathScriptInset * p = prevAtom()->asScriptInset();
503 p->removeScript(p->hasUp());
504 // Don't delete if there is anything left
505 if (p->hasUp() || p->hasDown())
514 void MathCursor::erase()
524 // delete empty cells if necessary
525 if (array().empty()) {
528 par()->idxDelete(idx(), popit, removeit);
529 if (popit && popLeft() && removeit)
537 MathScriptInset * p = nextAtom()->asScriptInset();
539 p->removeScript(p->hasUp());
540 // Don't delete if there is anything left
541 if (p->hasUp() || p->hasDown())
549 void MathCursor::delLine()
558 if (par()->nrows() > 1)
559 par()->delRow(row());
563 bool MathCursor::up(bool sel)
570 // check whether we could move into a superscript
572 MathAtom & p = prevAtom();
573 if (p->asScriptInset() && p->asScriptInset()->hasUp()) {
582 MathAtom & n = nextAtom();
583 if (n->asScriptInset() && n->asScriptInset()->hasUp()) {
592 return goUp() || selection_;
596 bool MathCursor::down(bool sel)
603 // check whether we could move into a subscript
605 MathAtom & p = prevAtom();
606 if (p->asScriptInset() && p->asScriptInset()->hasDown()) {
615 MathAtom & n = nextAtom();
616 if (n->asScriptInset() && n->asScriptInset()->hasDown()) {
625 return goDown() || selection_;
629 bool MathCursor::toggleLimits()
633 MathScriptInset * t = prevAtom()->asScriptInset();
636 int old = t->limits();
637 t->limits(old < 0 ? 1 : -1);
638 return old != t->limits();
642 void MathCursor::macroModeClose()
644 string s = macroName();
646 size_type old = pos();
648 array().erase(pos(), old);
654 int MathCursor::macroNamePos() const
656 for (int i = pos() - 1; i >= 0; --i) {
657 MathAtom & p = array().at(i);
658 if (p->code() == LM_TC_TEX && p->getChar() == '\\')
665 string MathCursor::macroName() const
668 for (int i = macroNamePos(); i >= 0 && i < int(pos()); ++i)
669 s += array().at(i)->getChar();
674 void MathCursor::selCopy()
678 theSelection.grab(*this);
684 void MathCursor::selCut()
688 theSelection.grab(*this);
689 theSelection.erase(*this);
692 theSelection.clear();
697 void MathCursor::selDel()
701 theSelection.erase(*this);
707 void MathCursor::selPaste()
710 theSelection.paste(*this);
711 theSelection.grab(*this);
716 void MathCursor::selHandle(bool sel)
718 if (sel == selection_)
721 theSelection.clear();
727 void MathCursor::selStart()
733 theSelection.clear();
739 void MathCursor::selClear()
746 void MathCursor::drawSelection(Painter & pain) const
753 getSelection(i1, i2);
755 //lyxerr << "selection from: " << i1 << " to " << i2 << "\n";
757 if (i1.idx_ == i2.idx_) {
758 MathXArray & c = i1.xcell();
759 int x1 = c.xo() + c.pos2x(i1.pos_);
760 int y1 = c.yo() - c.ascent();
761 int x2 = c.xo() + c.pos2x(i2.pos_);
762 int y2 = c.yo() + c.descent();
763 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
765 std::vector<MathInset::idx_type> indices
766 = (*i1.par_)->idxBetween(i1.idx_, i2.idx_);
767 for (unsigned i = 0; i < indices.size(); ++i) {
768 MathXArray & c = i1.xcell(indices[i]);
770 int y1 = c.yo() - c.ascent();
771 int x2 = c.xo() + c.width();
772 int y2 = c.yo() + c.descent();
773 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
779 void MathCursor::handleFont(MathTextCodes t)
785 getSelection(i1, i2);
786 if (i1.idx_ == i2.idx_) {
787 MathArray & ar = i1.cell();
788 for (MathInset::pos_type pos = i1.pos_; pos != i2.pos_; ++pos)
789 ar.at(pos)->handleFont(t);
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(MathAtom(p)); // this invalidates p!
809 pushRight(prevAtom());
813 void MathCursor::getPos(int & x, int & y)
816 #warning This should probably take cellXOffset and cellYOffset into account
818 x = xarray().xo() + xarray().pos2x(pos());
823 MathAtom & MathCursor::par() const
825 return *cursor().par_;
829 InsetFormulaBase const * MathCursor::formula()
835 MathCursor::idx_type MathCursor::idx() const
837 return cursor().idx_;
841 MathCursor::idx_type & MathCursor::idx()
843 return cursor().idx_;
847 MathCursor::pos_type MathCursor::pos() const
849 return cursor().pos_;
853 MathCursor::pos_type & MathCursor::pos()
855 return cursor().pos_;
859 bool MathCursor::inMacroMode() const
861 return macroNamePos() != -1;
865 bool MathCursor::selection() const
871 MathArrayInset * MathCursor::enclosingArray(MathCursor::idx_type & idx) const
873 for (int i = Cursor_.size() - 1; i >= 0; --i) {
874 MathArrayInset * p = (*Cursor_[i].par_)->asArrayInset();
876 idx = Cursor_[i].idx_;
884 void MathCursor::pullArg(bool goright)
887 MathArray a = array();
889 MathScriptInset const * p = par()->asScriptInset();
891 // special handling for scripts
892 const bool up = p->hasUp();
894 MathScriptInset * q = nextAtom()->asScriptInset();
898 array().insert(pos(), a);
904 array().insert(pos(), a);
911 void MathCursor::normalize() const
914 #warning This is evil!
916 MathCursor * it = const_cast<MathCursor *>(this);
918 if (idx() >= par()->nargs()) {
919 lyxerr << "this should not really happen - 1: "
920 << idx() << " " << par()->nargs() << "\n";
923 it->idx() = min(idx(), par()->nargs() - 1);
925 if (pos() > size()) {
926 lyxerr << "this should not really happen - 2: "
927 << pos() << " " << size() << " in idx: " << it->idx()
929 MathWriteInfo wi(0, lyxerr, false);
930 it->par()->write(wi);
934 it->pos() = min(pos(), size());
938 MathCursor::size_type MathCursor::size() const
940 return array().size();
944 MathCursor::col_type MathCursor::col() const
946 return par()->col(idx());
950 MathCursor::row_type MathCursor::row() const
952 return par()->row(idx());
956 bool MathCursor::hasPrevAtom() const
962 bool MathCursor::hasNextAtom() const
964 return pos() < size();
968 MathAtom const & MathCursor::prevAtom() const
970 lyx::Assert(pos() > 0);
971 return array().at(pos() - 1);
975 MathAtom & MathCursor::prevAtom()
977 lyx::Assert(pos() > 0);
978 return array().at(pos() - 1);
982 MathAtom const & MathCursor::nextAtom() const
984 lyx::Assert(pos() < size());
985 return array().at(pos());
989 MathAtom & MathCursor::nextAtom()
991 lyx::Assert(pos() < size());
992 return array().at(pos());
996 MathArray & MathCursor::array() const
998 static MathArray dummy;
1000 if (idx() >= par()->nargs()) {
1001 lyxerr << "############ idx_ " << idx() << " not valid\n";
1005 return cursor().cell();
1009 MathXArray & MathCursor::xarray() const
1011 return cursor().xcell();
1015 void MathCursor::idxNext()
1017 par()->idxNext(idx(), pos());
1021 void MathCursor::idxPrev()
1023 par()->idxPrev(idx(), pos());
1027 void MathCursor::splitCell()
1029 if (idx() == par()->nargs() - 1)
1031 MathArray ar = array();
1033 array().erase(pos(), size());
1036 array().insert(0, ar);
1040 void MathCursor::breakLine()
1042 // leave inner cells
1046 MathMatrixInset * p = formula()->par()->asMatrixInset();
1050 if (p->getType() == LM_OT_SIMPLE || p->getType() == LM_OT_EQUATION) {
1051 p->mutate(LM_OT_EQNARRAY);
1058 const row_type r = row();
1059 for (col_type c = col() + 1; c < p->ncols(); ++c) {
1060 const MathMatrixInset::idx_type i1 = p->index(r, c);
1061 const MathMatrixInset::idx_type i2 = p->index(r + 1, c);
1062 //lyxerr << "swapping cells " << i1 << " and " << i2 << "\n";
1063 p->cell(i1).swap(p->cell(i2));
1068 p->cell(idx()).swap(p->cell(idx() + p->ncols() - 1));
1070 // correct cursor position
1077 char MathCursor::valign() const
1080 MathArrayInset * p = enclosingArray(idx);
1081 return p ? p->valign() : '\0';
1085 char MathCursor::halign() const
1088 MathArrayInset * p = enclosingArray(idx);
1089 return p ? p->halign(idx % p->ncols()) : '\0';
1093 void MathCursor::getSelection(MathCursorPos & i1, MathCursorPos & i2) const
1095 MathCursorPos anc = normalAnchor();
1096 if (anc < cursor()) {
1106 MathCursorPos & MathCursor::cursor()
1108 return Cursor_.back();
1112 MathCursorPos const & MathCursor::cursor() const
1114 return Cursor_.back();
1118 int MathCursor::cellXOffset() const
1120 return par()->cellXOffset(idx());
1124 int MathCursor::cellYOffset() const
1126 return par()->cellYOffset(idx());
1130 int MathCursor::xpos() const
1132 return cellXOffset() + xarray().pos2x(pos());
1136 int MathCursor::ypos() const
1138 return cellYOffset();
1143 void MathCursor::gotoX(int x)
1145 pos() = xarray().x2pos(x - cellXOffset());
1149 bool MathCursor::goUp()
1151 // first ask the inset if it knows better then we
1152 if (par()->idxUp(idx(), pos()))
1155 // leave subscript to the nearest side
1156 MathScriptInset * p = par()->asScriptInset();
1157 if (p && idx() == 0) {
1158 if (pos() <= size() / 2)
1165 // if not, apply brute force.
1169 std::vector<MathCursorPos> save = Cursor_;
1170 MathAtom const & out = formula()->par();
1171 y0 -= xarray().ascent();
1172 for (int y = y0 - 4; y > out->yo() - out->ascent(); y -= 4) {
1174 if (save != Cursor_ && xarray().yo() < y0)
1182 bool MathCursor::goDown()
1184 // first ask the inset if it knows better then we
1185 if (par()->idxDown(idx(), pos()))
1188 // leave superscript to the nearest side
1189 MathScriptInset * p = par()->asScriptInset();
1190 if (p && idx() == 1) {
1191 if (pos() <= size() / 2)
1198 // if not, apply brute force.
1202 std::vector<MathCursorPos> save = Cursor_;
1203 MathAtom const & out = formula()->par();
1204 y0 += xarray().descent();
1205 for (int y = y0 + 4; y < out->yo() + out->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 void MathCursor::interpret(string const & s)
1229 //lyxerr << "interpret 1: '" << s << "'\n";
1233 if (s.size() == 1) {
1238 //lyxerr << "char: '" << s[0] << "' int: " << int(s[0]) << endl;
1239 //owner_->getIntl()->getTrans().TranslateAndInsert(s[0], lt);
1240 //lyxerr << "trans: '" << s[0] << "' int: " << int(s[0]) << endl;
1242 if (s.size() > 7 && s.substr(0, 7) == "matrix ") {
1247 istringstream is(s.substr(7).c_str());
1248 is >> m >> n >> v_align >> h_align;
1249 m = std::max(1u, m);
1250 n = std::max(1u, n);
1252 niceInsert(MathAtom(new MathArrayInset(m, n, v_align[0], h_align)));
1256 if (s == "\\over" || s == "\\choose" || s == "\\atop") {
1257 MathArray ar = array();
1258 MathAtom t = createMathInset(s.substr(1));
1259 t->asNestInset()->cell(0).swap(array());
1267 niceInsert(createMathInset(s.substr(1)));
1271 void MathCursor::interpret(char c)
1273 //lyxerr << "interpret 2: '" << c << "'\n";
1275 if (inMacroMode()) {
1276 string name = macroName();
1278 if (name == "\\" && c == '#') {
1279 insert(c, LM_TC_TEX);
1283 if (name == "\\" && c == '\\') {
1285 interpret("\\backslash");
1289 if (name == "\\#" && '1' <= c && c <= '9') {
1290 insert(c, LM_TC_TEX);
1296 insert(c, LM_TC_TEX);
1301 insert(c, LM_TC_TEX);
1311 if (c == '^' || c == '_') {
1312 const bool up = (c == '^');
1314 if (hasPrevAtom() && prevAtom()->asScriptInset()) {
1315 prevAtom()->asScriptInset()->ensure(up);
1316 pushRight(prevAtom());
1319 } else if (hasNextAtom() && nextAtom()->asScriptInset()) {
1320 nextAtom()->asScriptInset()->ensure(up);
1321 pushLeft(nextAtom());
1325 plainInsert(MathAtom(new MathScriptInset(up)));
1326 prevAtom()->asScriptInset()->ensure(up);
1327 pushRight(prevAtom());
1339 if (lastcode_ == LM_TC_TEXTRM) {
1340 insert(c, LM_TC_TEXTRM);
1345 if (hasPrevAtom() && prevAtom()->asSpaceInset()) {
1346 prevAtom()->asSpaceInset()->incSpace();
1350 if (mathcursor->popRight())
1354 // this would not work if the inset is in an table!
1355 //bv->text->cursorRight(bv, true);
1356 //result = FINISHED;
1360 if (strchr("{}", c)) {
1361 insert(c, LM_TC_TEX);
1365 if (strchr("#$%", c)) {
1366 insert(MathAtom(new MathSpecialCharInset(c)));
1367 lastcode_ = LM_TC_VAR;
1371 if (isalpha(c) && lastcode_ == LM_TC_GREEK) {
1372 insert(c, LM_TC_VAR);
1376 if (isalpha(c) && lastcode_ == LM_TC_GREEK1) {
1377 insert(c, LM_TC_VAR);
1378 lastcode_ = LM_TC_VAR;
1383 insert(c, LM_TC_TEX);
1384 //bv->owner()->message(_("TeX mode"));
1388 // no special circumstances, so insert the character without any fuss
1389 insert(c, LM_TC_MIN);
1394 ////////////////////////////////////////////////////////////////////////
1397 bool operator==(MathCursorPos const & ti, MathCursorPos const & it)
1399 return ti.par_ == it.par_ && ti.idx_ == it.idx_ && ti.pos_ == it.pos_;
1403 bool operator<(MathCursorPos const & ti, MathCursorPos const & it)
1405 if (ti.par_ != it.par_) {
1406 lyxerr << "can't compare cursor and anchor in different insets\n";
1409 if (ti.idx_ != it.idx_)
1410 return ti.idx_ < it.idx_;
1411 return ti.pos_ < it.pos_;
1415 MathArray & MathCursorPos::cell(MathCursor::idx_type idx) const
1417 return (*par_)->cell(idx);
1421 MathArray & MathCursorPos::cell() const
1423 return (*par_)->cell(idx_);
1427 MathXArray & MathCursorPos::xcell(MathCursor::idx_type idx) const
1429 return (*par_)->xcell(idx);
1433 MathXArray & MathCursorPos::xcell() const
1435 return (*par_)->xcell(idx_);
1439 MathCursorPos MathCursor::normalAnchor() const
1441 // use Anchor on the same level as Cursor
1442 MathCursorPos normal = Anchor_[Cursor_.size() - 1];
1443 if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) {
1444 // anchor is behind cursor -> move anchor behind the inset