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());
566 bool MathCursor::up(bool sel)
573 // check whether we could move into a superscript
575 MathAtom & p = prevAtom();
576 if (p->asScriptInset() && p->asScriptInset()->hasUp()) {
585 MathAtom & n = nextAtom();
586 if (n->asScriptInset() && n->asScriptInset()->hasUp()) {
595 return goUp() || selection_;
599 bool MathCursor::down(bool sel)
606 // check whether we could move into a subscript
608 MathAtom & p = prevAtom();
609 if (p->asScriptInset() && p->asScriptInset()->hasDown()) {
618 MathAtom & n = nextAtom();
619 if (n->asScriptInset() && n->asScriptInset()->hasDown()) {
628 return goDown() || selection_;
632 bool MathCursor::toggleLimits()
636 MathScriptInset * t = prevAtom()->asScriptInset();
639 int old = t->limits();
640 t->limits(old < 0 ? 1 : -1);
641 return old != t->limits();
645 void MathCursor::macroModeClose()
647 string s = macroName();
649 size_type old = pos();
651 array().erase(pos(), old);
657 int MathCursor::macroNamePos() const
659 for (int i = pos() - 1; i >= 0; --i) {
660 MathAtom & p = array().at(i);
661 if (p->code() == LM_TC_TEX && p->getChar() == '\\')
668 string MathCursor::macroName() const
671 for (int i = macroNamePos(); i >= 0 && i < int(pos()); ++i)
672 s += array().at(i)->getChar();
677 void MathCursor::selCopy()
681 theSelection.grab(*this);
687 void MathCursor::selCut()
691 theSelection.grab(*this);
692 theSelection.erase(*this);
695 theSelection.clear();
700 void MathCursor::selDel()
704 theSelection.erase(*this);
711 void MathCursor::selPaste()
714 theSelection.paste(*this);
715 theSelection.grab(*this);
720 void MathCursor::selHandle(bool sel)
722 if (sel == selection_)
725 theSelection.clear();
731 void MathCursor::selStart()
737 theSelection.clear();
743 void MathCursor::selClear()
750 void MathCursor::selGet(MathArray & ar)
756 theSelection.grab(*this);
757 ar = theSelection.glue();
762 void MathCursor::drawSelection(Painter & pain) const
769 getSelection(i1, i2);
771 //lyxerr << "selection from: " << i1 << " to " << i2 << "\n";
773 if (i1.idx_ == i2.idx_) {
774 MathXArray & c = i1.xcell();
775 int x1 = c.xo() + c.pos2x(i1.pos_);
776 int y1 = c.yo() - c.ascent();
777 int x2 = c.xo() + c.pos2x(i2.pos_);
778 int y2 = c.yo() + c.descent();
779 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
781 std::vector<MathInset::idx_type> indices
782 = (*i1.par_)->idxBetween(i1.idx_, i2.idx_);
783 for (unsigned i = 0; i < indices.size(); ++i) {
784 MathXArray & c = i1.xcell(indices[i]);
786 int y1 = c.yo() - c.ascent();
787 int x2 = c.xo() + c.width();
788 int y2 = c.yo() + c.descent();
789 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
795 void MathCursor::handleFont(MathTextCodes t)
801 getSelection(i1, i2);
802 if (i1.idx_ == i2.idx_) {
803 MathArray & ar = i1.cell();
804 for (MathInset::pos_type pos = i1.pos_; pos != i2.pos_; ++pos)
805 ar.at(pos)->handleFont(t);
808 lastcode_ = (lastcode_ == t) ? LM_TC_VAR : t;
812 void MathCursor::handleDelim(string const & l, string const & r)
814 handleNest(new MathDelimInset(l, r));
818 void MathCursor::handleNest(MathInset * p)
822 p->cell(0) = theSelection.glue();
824 insert(MathAtom(p)); // this invalidates p!
825 pushRight(prevAtom());
829 void MathCursor::getPos(int & x, int & y)
832 #warning This should probably take cellXOffset and cellYOffset into account
834 x = xarray().xo() + xarray().pos2x(pos());
839 MathAtom & MathCursor::par() const
841 return *cursor().par_;
845 InsetFormulaBase const * MathCursor::formula()
851 MathCursor::idx_type MathCursor::idx() const
853 return cursor().idx_;
857 MathCursor::idx_type & MathCursor::idx()
859 return cursor().idx_;
863 MathCursor::pos_type MathCursor::pos() const
865 return cursor().pos_;
869 MathCursor::pos_type & MathCursor::pos()
871 return cursor().pos_;
875 bool MathCursor::inMacroMode() const
877 return macroNamePos() != -1;
881 bool MathCursor::selection() const
887 MathArrayInset * MathCursor::enclosingArray(MathCursor::idx_type & idx) const
889 for (int i = Cursor_.size() - 1; i >= 0; --i) {
890 MathArrayInset * p = (*Cursor_[i].par_)->asArrayInset();
892 idx = Cursor_[i].idx_;
900 void MathCursor::pullArg(bool goright)
903 MathArray a = array();
905 MathScriptInset const * p = par()->asScriptInset();
907 // special handling for scripts
908 const bool up = p->hasUp();
910 MathScriptInset * q = nextAtom()->asScriptInset();
914 array().insert(pos(), a);
920 array().insert(pos(), a);
927 void MathCursor::normalize() const
930 #warning This is evil!
932 MathCursor * it = const_cast<MathCursor *>(this);
934 if (idx() >= par()->nargs()) {
935 lyxerr << "this should not really happen - 1: "
936 << idx() << " " << par()->nargs() << "\n";
939 it->idx() = min(idx(), par()->nargs() - 1);
941 if (pos() > size()) {
942 lyxerr << "this should not really happen - 2: "
943 << pos() << " " << size() << " in idx: " << it->idx()
945 MathWriteInfo wi(0, lyxerr, false);
946 it->par()->write(wi);
950 it->pos() = min(pos(), size());
954 MathCursor::size_type MathCursor::size() const
956 return array().size();
960 MathCursor::col_type MathCursor::col() const
962 return par()->col(idx());
966 MathCursor::row_type MathCursor::row() const
968 return par()->row(idx());
972 bool MathCursor::hasPrevAtom() const
978 bool MathCursor::hasNextAtom() const
980 return pos() < size();
984 MathAtom const & MathCursor::prevAtom() const
986 lyx::Assert(pos() > 0);
987 return array().at(pos() - 1);
991 MathAtom & MathCursor::prevAtom()
993 lyx::Assert(pos() > 0);
994 return array().at(pos() - 1);
998 MathAtom const & MathCursor::nextAtom() const
1000 lyx::Assert(pos() < size());
1001 return array().at(pos());
1005 MathAtom & MathCursor::nextAtom()
1007 lyx::Assert(pos() < size());
1008 return array().at(pos());
1012 MathArray & MathCursor::array() const
1014 static MathArray dummy;
1016 if (idx() >= par()->nargs()) {
1017 lyxerr << "############ idx_ " << idx() << " not valid\n";
1021 return cursor().cell();
1025 MathXArray & MathCursor::xarray() const
1027 return cursor().xcell();
1031 void MathCursor::idxNext()
1033 par()->idxNext(idx(), pos());
1037 void MathCursor::idxPrev()
1039 par()->idxPrev(idx(), pos());
1043 void MathCursor::splitCell()
1045 if (idx() == par()->nargs() - 1)
1047 MathArray ar = array();
1049 array().erase(pos(), size());
1052 array().insert(0, ar);
1056 void MathCursor::breakLine()
1058 // leave inner cells
1062 MathMatrixInset * p = formula()->par()->asMatrixInset();
1066 if (p->getType() == LM_OT_SIMPLE || p->getType() == LM_OT_EQUATION) {
1067 p->mutate(LM_OT_EQNARRAY);
1074 const row_type r = row();
1075 for (col_type c = col() + 1; c < p->ncols(); ++c) {
1076 const MathMatrixInset::idx_type i1 = p->index(r, c);
1077 const MathMatrixInset::idx_type i2 = p->index(r + 1, c);
1078 //lyxerr << "swapping cells " << i1 << " and " << i2 << "\n";
1079 p->cell(i1).swap(p->cell(i2));
1084 p->cell(idx()).swap(p->cell(idx() + p->ncols() - 1));
1089 char MathCursor::valign() const
1092 MathArrayInset * p = enclosingArray(idx);
1093 return p ? p->valign() : '\0';
1097 char MathCursor::halign() const
1100 MathArrayInset * p = enclosingArray(idx);
1101 return p ? p->halign(idx % p->ncols()) : '\0';
1105 void MathCursor::getSelection(MathCursorPos & i1, MathCursorPos & i2) const
1107 MathCursorPos anc = normalAnchor();
1108 if (anc < cursor()) {
1118 MathCursorPos & MathCursor::cursor()
1120 return Cursor_.back();
1124 MathCursorPos const & MathCursor::cursor() const
1126 return Cursor_.back();
1130 int MathCursor::cellXOffset() const
1132 return par()->cellXOffset(idx());
1136 int MathCursor::cellYOffset() const
1138 return par()->cellYOffset(idx());
1142 int MathCursor::xpos() const
1144 return cellXOffset() + xarray().pos2x(pos());
1148 int MathCursor::ypos() const
1150 return cellYOffset();
1155 void MathCursor::gotoX(int x)
1157 pos() = xarray().x2pos(x - cellXOffset());
1161 bool MathCursor::goUp()
1163 // first ask the inset if it knows better then we
1164 if (par()->idxUp(idx(), pos()))
1167 // leave subscript to the nearest side
1168 MathScriptInset * p = par()->asScriptInset();
1169 if (p && idx() == 0) {
1170 if (pos() <= size() / 2)
1177 // if not, apply brute force.
1181 std::vector<MathCursorPos> save = Cursor_;
1182 MathAtom const & out = formula()->par();
1183 y0 -= xarray().ascent();
1184 for (int y = y0 - 4; y > out->yo() - out->ascent(); y -= 4) {
1186 if (save != Cursor_ && xarray().yo() < y0)
1194 bool MathCursor::goDown()
1196 // first ask the inset if it knows better then we
1197 if (par()->idxDown(idx(), pos()))
1200 // leave superscript to the nearest side
1201 MathScriptInset * p = par()->asScriptInset();
1202 if (p && idx() == 1) {
1203 if (pos() <= size() / 2)
1210 // if not, apply brute force.
1214 std::vector<MathCursorPos> save = Cursor_;
1215 MathAtom const & out = formula()->par();
1216 y0 += xarray().descent();
1217 for (int y = y0 + 4; y < out->yo() + out->descent(); y += 4) {
1219 if (save != Cursor_ && xarray().yo() > y0)
1227 bool MathCursor::idxLeft()
1229 return par()->idxLeft(idx(), pos());
1233 bool MathCursor::idxRight()
1235 return par()->idxRight(idx(), pos());
1239 void MathCursor::interpret(string const & s)
1241 //lyxerr << "interpret 1: '" << s << "'\n";
1245 if (s.size() == 1) {
1250 //lyxerr << "char: '" << s[0] << "' int: " << int(s[0]) << endl;
1251 //owner_->getIntl()->getTrans().TranslateAndInsert(s[0], lt);
1252 //lyxerr << "trans: '" << s[0] << "' int: " << int(s[0]) << endl;
1254 if (s.size() > 7 && s.substr(0, 7) == "matrix ") {
1259 istringstream is(s.substr(7).c_str());
1260 is >> m >> n >> v_align >> h_align;
1261 m = std::max(1u, m);
1262 n = std::max(1u, n);
1264 niceInsert(MathAtom(new MathArrayInset(m, n, v_align[0], h_align)));
1268 if (s == "\\over" || s == "\\choose" || s == "\\atop") {
1269 MathArray ar = array();
1270 MathAtom t = createMathInset(s.substr(1));
1271 t->asNestInset()->cell(0).swap(array());
1279 niceInsert(createMathInset(s.substr(1)));
1283 void MathCursor::interpret(char c)
1285 //lyxerr << "interpret 2: '" << c << "'\n";
1287 if (inMacroMode()) {
1288 string name = macroName();
1290 if (name == "\\" && c == '#') {
1291 insert(c, LM_TC_TEX);
1295 if (name == "\\" && c == '\\') {
1297 interpret("\\backslash");
1301 if (name == "\\#" && '1' <= c && c <= '9') {
1302 insert(c, LM_TC_TEX);
1308 insert(c, LM_TC_TEX);
1313 insert(c, LM_TC_TEX);
1323 if (c == '^' || c == '_') {
1324 const bool up = (c == '^');
1326 if (hasPrevAtom() && prevAtom()->asScriptInset()) {
1327 prevAtom()->asScriptInset()->ensure(up);
1328 pushRight(prevAtom());
1331 } else if (hasNextAtom() && nextAtom()->asScriptInset()) {
1332 nextAtom()->asScriptInset()->ensure(up);
1333 pushLeft(nextAtom());
1337 plainInsert(MathAtom(new MathScriptInset(up)));
1338 prevAtom()->asScriptInset()->ensure(up);
1339 pushRight(prevAtom());
1351 if (lastcode_ == LM_TC_TEXTRM) {
1352 insert(c, LM_TC_TEXTRM);
1357 if (hasPrevAtom() && prevAtom()->asSpaceInset()) {
1358 prevAtom()->asSpaceInset()->incSpace();
1362 if (mathcursor->popRight())
1366 // this would not work if the inset is in an table!
1367 //bv->text->cursorRight(bv, true);
1368 //result = FINISHED;
1372 if (strchr("{}", c)) {
1373 insert(c, LM_TC_TEX);
1377 if (strchr("#$%", c)) {
1378 insert(MathAtom(new MathSpecialCharInset(c)));
1379 lastcode_ = LM_TC_VAR;
1383 if (isalpha(c) && lastcode_ == LM_TC_GREEK) {
1384 insert(c, LM_TC_VAR);
1388 if (isalpha(c) && lastcode_ == LM_TC_GREEK1) {
1389 insert(c, LM_TC_VAR);
1390 lastcode_ = LM_TC_VAR;
1395 insert(c, LM_TC_TEX);
1396 //bv->owner()->message(_("TeX mode"));
1400 // no special circumstances, so insert the character without any fuss
1401 insert(c, LM_TC_MIN);
1406 ////////////////////////////////////////////////////////////////////////
1409 bool operator==(MathCursorPos const & ti, MathCursorPos const & it)
1411 return ti.par_ == it.par_ && ti.idx_ == it.idx_ && ti.pos_ == it.pos_;
1415 bool operator<(MathCursorPos const & ti, MathCursorPos const & it)
1417 if (ti.par_ != it.par_) {
1418 lyxerr << "can't compare cursor and anchor in different insets\n";
1421 if (ti.idx_ != it.idx_)
1422 return ti.idx_ < it.idx_;
1423 return ti.pos_ < it.pos_;
1427 MathArray & MathCursorPos::cell(MathCursor::idx_type idx) const
1429 return (*par_)->cell(idx);
1433 MathArray & MathCursorPos::cell() const
1435 return (*par_)->cell(idx_);
1439 MathXArray & MathCursorPos::xcell(MathCursor::idx_type idx) const
1441 return (*par_)->xcell(idx);
1445 MathXArray & MathCursorPos::xcell() const
1447 return (*par_)->xcell(idx_);
1451 MathCursorPos MathCursor::normalAnchor() const
1453 // use Anchor on the same level as Cursor
1454 MathCursorPos normal = Anchor_[Cursor_.size() - 1];
1455 if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) {
1456 // anchor is behind cursor -> move anchor behind the inset