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"
31 #include "math_support.h"
32 #include "formulabase.h"
33 #include "math_cursor.h"
34 #include "math_factory.h"
35 #include "math_arrayinset.h"
36 #include "math_braceinset.h"
37 #include "math_charinset.h"
38 #include "math_deliminset.h"
39 #include "math_hullinset.h"
40 #include "math_scriptinset.h"
41 #include "math_spaceinset.h"
42 #include "math_specialcharinset.h"
43 #include "math_mathmlstream.h"
57 void grab(MathCursor const & cursor)
62 cursor.getSelection(i1, i2);
63 if (i1.idx_ == i2.idx_)
64 data_.push_back(MathArray(i1.cell(), i1.pos_, i2.pos_));
66 std::vector<MathInset::idx_type> indices =
67 (*i1.par_)->idxBetween(i1.idx_, i2.idx_);
68 for (MathInset::idx_type i = 0; i < indices.size(); ++i)
69 data_.push_back(i1.cell(indices[i]));
73 void erase(MathCursor & cursor)
77 cursor.getSelection(i1, i2);
78 if (i1.idx_ == i2.idx_)
79 i1.cell().erase(i1.pos_, i2.pos_);
81 std::vector<MathInset::idx_type> indices =
82 (*i1.par_)->idxBetween(i1.idx_, i2.idx_);
83 for (unsigned i = 0; i < indices.size(); ++i)
84 i1.cell(indices[i]).erase();
89 void paste(MathCursor & cursor) const
91 MathArray ar = glue();
95 // glues selection to one cell
96 MathArray glue() const
99 for (unsigned i = 0; i < data_.size(); ++i)
100 ar.push_back(data_[i]);
109 std::vector<MathArray> data_;
113 Selection theSelection;
117 std::ostream & operator<<(std::ostream & os, MathCursorPos const & p)
119 os << "(par: " << p.par_ << " idx: " << p.idx_ << " pos: " << p.pos_ << ")";
127 MathCursor::MathCursor(InsetFormulaBase * formula, bool left)
128 : formula_(formula), lastcode_(LM_TC_VAR), selection_(false)
130 left ? first() : last();
134 void MathCursor::push(MathAtom & t)
140 Cursor_.push_back(p);
144 void MathCursor::pushLeft(MathAtom & t)
146 //cerr << "Entering atom "; t->write(cerr, false); cerr << " left\n";
148 t->idxFirst(idx(), pos());
152 void MathCursor::pushRight(MathAtom & t)
154 //cerr << "Entering atom "; t->write(cerr, false); cerr << " right\n";
157 t->idxLast(idx(), pos());
161 bool MathCursor::popLeft()
163 //cerr << "Leaving atom "; par()->write(cerr, false); cerr << " left\n";
164 if (Cursor_.size() <= 1)
167 // nextInset()->removeEmptyScripts();
170 // nextAtom()->removeEmptyScripts();
175 bool MathCursor::popRight()
177 //cerr << "Leaving atom "; par()->write(cerr, false); cerr << " right\n";
178 if (Cursor_.size() <= 1)
181 // nextInset()->removeEmptyScripts();
184 // nextInset()->removeEmptyScripts();
192 void MathCursor::dump(char const * what) const
194 lyxerr << "MC: " << what << "\n";
195 for (unsigned i = 0; i < Cursor_.size(); ++i)
196 lyxerr << " i: " << i
197 << " Cursor: pos: " << Cursor_[i].pos_
198 << " idx: " << Cursor_[i].idx_
199 << " par: " << Cursor_[i].par_ << "\n";
201 for (unsigned i = 0; i < Anchor_.size(); ++i)
202 lyxerr << " i: " << i
203 << " Anchor: pos: " << Anchor_[i].pos_
204 << " idx: " << Anchor_[i].idx_
205 << " par: " << Anchor_[i].par_ << "\n";
207 lyxerr << " sel: " << selection_ << "\n";
211 void MathCursor::seldump(char const * str) const
213 //lyxerr << "SEL: " << str << ": '" << theSelection << "'\n";
216 lyxerr << "\n\n\n=================vvvvvvvvvvvvv======================= "
217 << str << "\ntheSelection: " << selection_
218 << " '" << theSelection.glue() << "'\n";
219 for (unsigned int i = 0; i < Cursor_.size(); ++i)
220 lyxerr << Cursor_[i].par_ << "\n'" << Cursor_[i].cell() << "'\n";
222 for (unsigned int i = 0; i < Anchor_.size(); ++i)
223 lyxerr << Anchor_[i].par_ << "\n'" << Anchor_[i].cell() << "'\n";
224 //lyxerr << "\ncursor.pos_: " << pos();
225 //lyxerr << "\nanchor.pos_: " << anchor().pos_;
226 lyxerr << "\n===================^^^^^^^^^^^^=====================\n\n\n";
231 void MathCursor::seldump(char const *) const {}
232 void MathCursor::dump(char const *) const {}
237 UpdatableInset * MathCursor::asHyperActiveInset() const
239 return par()->asHyperActiveInset();
243 bool MathCursor::isInside(MathInset const * p) const
245 for (unsigned i = 0; i < Cursor_.size(); ++i)
246 if (Cursor_[i].par_->nucleus() == p)
252 bool MathCursor::openable(MathAtom const & t, bool sel) const
254 if (t->isHyperActive())
260 if (t->asScriptInset())
264 // we can't move into anything new during selection
265 if (Cursor_.size() == Anchor_.size())
267 if (&t != Anchor_[Cursor_.size()].par_)
274 bool MathCursor::positionable(MathAtom const & t, int x, int y) const
277 // we can't move into anything new during selection
278 if (Cursor_.size() == Anchor_.size())
280 //if (t != Anchor_[Cursor_.size()].par_)
284 return t->nargs() && t->covers(x, y);
288 bool MathCursor::posLeft()
297 bool MathCursor::posRight()
306 bool MathCursor::left(bool sel)
311 lastcode_ = LM_TC_VAR;
315 lastcode_ = LM_TC_VAR;
317 if (hasPrevAtom() && openable(prevAtom(), sel)) {
318 if (prevAtom()->isHyperActive()) {
319 lyxerr << "entering hyperactive inset\n";
321 pushRight(prevAtom());
325 return posLeft() || idxLeft() || popLeft() || selection_;
329 bool MathCursor::right(bool sel)
334 lastcode_ = LM_TC_VAR;
338 lastcode_ = LM_TC_VAR;
340 if (hasNextAtom() && openable(nextAtom(), sel)) {
341 if (nextAtom()->isHyperActive()) {
342 lyxerr << "entering hyperactive inset\n";
345 nextAtom()->edit(formula()->view(), x, y, 0);
347 pushLeft(nextAtom());
351 return posRight() || idxRight() || popRight() || selection_;
355 void MathCursor::first()
358 pushLeft(formula_->par());
362 void MathCursor::last()
369 void MathCursor::setPos(int x, int y)
372 //lyxerr << "MathCursor::setPos x: " << x << " y: " << y << "\n";
375 lastcode_ = LM_TC_VAR;
378 cursor().par_ = &formula_->par();
383 //lyxerr << "found idx: " << idx() << " cursor: " << pos() << "\n";
384 int distmin = 1 << 30; // large enough
385 for (unsigned int i = 0; i < par()->nargs(); ++i) {
386 MathXArray const & ar = par()->xcell(i);
387 int x1 = x - ar.xo();
388 int y1 = y - ar.yo();
389 MathXArray::size_type c = ar.x2pos(x1);
390 int xx = abs(x1 - ar.pos2x(c));
392 //lyxerr << "idx: " << i << " xx: " << xx << " yy: " << yy
393 // << " c: " << c << " xo: " << ar.xo() << "\n";
394 if (yy + xx <= distmin) {
400 //lyxerr << "found idx: " << idx() << " cursor: "
402 if (hasNextAtom() && positionable(nextAtom(), x, y))
403 pushLeft(nextAtom());
404 else if (hasPrevAtom() && positionable(prevAtom(), x, y))
405 pushRight(prevAtom());
413 void MathCursor::home(bool sel)
418 lastcode_ = LM_TC_VAR;
419 if (!par()->idxHome(idx(), pos()))
425 void MathCursor::end(bool sel)
430 lastcode_ = LM_TC_VAR;
431 if (!par()->idxEnd(idx(), pos()))
437 void MathCursor::plainErase()
439 array().erase(pos());
443 void MathCursor::plainInsert(MathAtom const & t)
445 array().insert(pos(), t);
450 void MathCursor::insert(char c, MathTextCodes t)
452 //lyxerr << "inserting '" << c << "'\n";
453 plainInsert(MathAtom(new MathCharInset(c, t)));
457 void MathCursor::insert(MathAtom const & t)
472 void MathCursor::niceInsert(MathAtom const & t)
475 insert(t); // inserting invalidates the pointer!
476 MathAtom const & p = prevAtom();
479 right(); // do not push for e.g. MathSymbolInset
483 #warning "redraw disabled"
485 //p->metrics(p->size());
489 void MathCursor::insert(MathArray const & ar)
495 array().insert(pos(), ar);
500 void MathCursor::paste(MathArray const & ar)
504 array().insert(pos(), ar);
509 void MathCursor::backspace()
521 MathScriptInset * p = prevAtom()->asScriptInset();
523 p->removeScript(p->hasUp());
524 // Don't delete if there is anything left
525 if (p->hasUp() || p->hasDown())
534 void MathCursor::erase()
544 // delete empty cells if necessary
545 if (array().empty()) {
548 par()->idxDelete(idx(), popit, removeit);
549 if (popit && popLeft() && removeit)
557 MathScriptInset * p = nextAtom()->asScriptInset();
559 p->removeScript(p->hasUp());
560 // Don't delete if there is anything left
561 if (p->hasUp() || p->hasDown())
569 void MathCursor::delLine()
578 if (par()->nrows() > 1)
579 par()->delRow(row());
586 bool MathCursor::up(bool sel)
593 // check whether we could move into a superscript
595 MathAtom & p = prevAtom();
596 if (p->asScriptInset() && p->asScriptInset()->hasUp()) {
605 MathAtom & n = nextAtom();
606 if (n->asScriptInset() && n->asScriptInset()->hasUp()) {
615 return goUp() || selection_;
619 bool MathCursor::down(bool sel)
626 // check whether we could move into a subscript
628 MathAtom & p = prevAtom();
629 if (p->asScriptInset() && p->asScriptInset()->hasDown()) {
638 MathAtom & n = nextAtom();
639 if (n->asScriptInset() && n->asScriptInset()->hasDown()) {
648 return goDown() || selection_;
652 bool MathCursor::toggleLimits()
656 MathScriptInset * t = prevAtom()->asScriptInset();
659 int old = t->limits();
660 t->limits(old < 0 ? 1 : -1);
661 return old != t->limits();
665 void MathCursor::macroModeClose()
667 string s = macroName();
669 size_type old = pos();
671 array().erase(pos(), old);
677 int MathCursor::macroNamePos() const
679 for (int i = pos() - 1; i >= 0; --i) {
680 MathAtom & p = array().at(i);
681 if (p->code() == LM_TC_TEX && p->getChar() == '\\')
688 string MathCursor::macroName() const
691 for (int i = macroNamePos(); i >= 0 && i < int(pos()); ++i)
692 s += array().at(i)->getChar();
697 void MathCursor::selCopy()
701 theSelection.grab(*this);
707 void MathCursor::selCut()
711 theSelection.grab(*this);
712 theSelection.erase(*this);
715 theSelection.clear();
720 void MathCursor::selDel()
724 theSelection.erase(*this);
732 void MathCursor::selPaste()
735 theSelection.paste(*this);
736 theSelection.grab(*this);
741 void MathCursor::selHandle(bool sel)
743 if (sel == selection_)
746 theSelection.clear();
752 void MathCursor::selStart()
758 theSelection.clear();
764 void MathCursor::selClear()
771 void MathCursor::selGet(MathArray & ar)
777 theSelection.grab(*this);
778 ar = theSelection.glue();
783 void MathCursor::drawSelection(Painter & pain) const
790 getSelection(i1, i2);
791 //lyxerr << "selection from: " << i1 << " to " << i2 << "\n";
793 if (i1.idx_ == i2.idx_) {
794 MathXArray & c = i1.xcell();
795 int x1 = c.xo() + c.pos2x(i1.pos_);
796 int y1 = c.yo() - c.ascent();
797 int x2 = c.xo() + c.pos2x(i2.pos_);
798 int y2 = c.yo() + c.descent();
799 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
801 std::vector<MathInset::idx_type> indices
802 = (*i1.par_)->idxBetween(i1.idx_, i2.idx_);
803 for (unsigned i = 0; i < indices.size(); ++i) {
804 MathXArray & c = i1.xcell(indices[i]);
806 int y1 = c.yo() - c.ascent();
807 int x2 = c.xo() + c.width();
808 int y2 = c.yo() + c.descent();
809 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
814 // draw anchor if different from selection boundary
815 MathCursorPos anc = Anchor_.back();
816 if (anc != i1 && anc != i2) {
817 MathXArray & c = anc.xcell();
818 int x = c.xo() + c.pos2x(anc.pos_);
819 int y1 = c.yo() - c.ascent();
820 int y2 = c.yo() + c.descent();
821 pain.line(x, y1, x, y2, LColor::mathline);
827 void MathCursor::handleFont(MathTextCodes t)
833 getSelection(i1, i2);
834 if (i1.idx_ == i2.idx_) {
835 MathArray & ar = i1.cell();
836 for (MathInset::pos_type pos = i1.pos_; pos != i2.pos_; ++pos)
837 ar.at(pos)->handleFont(t);
840 lastcode_ = (lastcode_ == t) ? LM_TC_VAR : t;
844 void MathCursor::handleDelim(string const & l, string const & r)
846 handleNest(new MathDelimInset(l, r));
850 void MathCursor::handleNest(MathInset * p)
854 p->cell(0) = theSelection.glue();
856 insert(MathAtom(p)); // this invalidates p!
857 pushRight(prevAtom());
861 void MathCursor::getPos(int & x, int & y)
864 #warning This should probably take cellXOffset and cellYOffset into account
866 x = xarray().xo() + xarray().pos2x(pos());
871 MathAtom & MathCursor::par() const
873 return *cursor().par_;
877 InsetFormulaBase const * MathCursor::formula()
883 MathCursor::idx_type MathCursor::idx() const
885 return cursor().idx_;
889 MathCursor::idx_type & MathCursor::idx()
891 return cursor().idx_;
895 MathCursor::pos_type MathCursor::pos() const
897 return cursor().pos_;
901 MathCursor::pos_type & MathCursor::pos()
903 return cursor().pos_;
907 bool MathCursor::inMacroMode() const
909 return macroNamePos() != -1;
913 bool MathCursor::selection() const
919 MathArrayInset * MathCursor::enclosingArray(MathCursor::idx_type & idx) const
921 for (int i = Cursor_.size() - 1; i >= 0; --i) {
922 MathArrayInset * p = (*Cursor_[i].par_)->asArrayInset();
924 idx = Cursor_[i].idx_;
932 void MathCursor::pullArg(bool goright)
935 MathArray a = array();
937 MathScriptInset const * p = par()->asScriptInset();
939 // special handling for scripts
940 const bool up = p->hasUp();
942 MathScriptInset * q = nextAtom()->asScriptInset();
946 array().insert(pos(), a);
952 array().insert(pos(), a);
959 void MathCursor::normalize() const
962 #warning This is evil!
964 MathCursor * it = const_cast<MathCursor *>(this);
966 if (idx() >= par()->nargs()) {
967 lyxerr << "this should not really happen - 1: "
968 << idx() << " " << par()->nargs() << "\n";
971 it->idx() = min(idx(), par()->nargs() - 1);
973 if (pos() > size()) {
974 lyxerr << "this should not really happen - 2: "
975 << pos() << " " << size() << " in idx: " << it->idx()
977 WriteStream wi(0, lyxerr, false);
978 it->par()->write(wi);
982 it->pos() = min(pos(), size());
986 MathCursor::size_type MathCursor::size() const
988 return array().size();
992 MathCursor::col_type MathCursor::col() const
994 return par()->col(idx());
998 MathCursor::row_type MathCursor::row() const
1000 return par()->row(idx());
1004 bool MathCursor::hasPrevAtom() const
1010 bool MathCursor::hasNextAtom() const
1012 return pos() < size();
1016 MathAtom const & MathCursor::prevAtom() const
1018 lyx::Assert(pos() > 0);
1019 return array().at(pos() - 1);
1023 MathAtom & MathCursor::prevAtom()
1025 lyx::Assert(pos() > 0);
1026 return array().at(pos() - 1);
1030 MathAtom const & MathCursor::nextAtom() const
1032 lyx::Assert(pos() < size());
1033 return array().at(pos());
1037 MathAtom & MathCursor::nextAtom()
1039 lyx::Assert(pos() < size());
1040 return array().at(pos());
1044 MathArray & MathCursor::array() const
1046 static MathArray dummy;
1048 if (idx() >= par()->nargs()) {
1049 lyxerr << "############ idx_ " << idx() << " not valid\n";
1053 return cursor().cell();
1057 MathXArray & MathCursor::xarray() const
1059 return cursor().xcell();
1063 void MathCursor::idxNext()
1065 par()->idxNext(idx(), pos());
1069 void MathCursor::idxPrev()
1071 par()->idxPrev(idx(), pos());
1075 void MathCursor::splitCell()
1077 if (idx() == par()->nargs() - 1)
1079 MathArray ar = array();
1081 array().erase(pos(), size());
1084 array().insert(0, ar);
1088 void MathCursor::breakLine()
1090 // leave inner cells
1094 MathHullInset * p = formula()->par()->asHullInset();
1098 if (p->getType() == LM_OT_SIMPLE || p->getType() == LM_OT_EQUATION) {
1099 p->mutate(LM_OT_EQNARRAY);
1106 const row_type r = row();
1107 for (col_type c = col() + 1; c < p->ncols(); ++c)
1108 p->cell(p->index(r, c)).swap(p->cell(p->index(r + 1, c)));
1112 p->cell(idx()).swap(p->cell(idx() + p->ncols() - 1));
1117 char MathCursor::valign() const
1120 MathArrayInset * p = enclosingArray(idx);
1121 return p ? p->valign() : '\0';
1125 char MathCursor::halign() const
1128 MathArrayInset * p = enclosingArray(idx);
1129 return p ? p->halign(idx % p->ncols()) : '\0';
1133 void MathCursor::getSelection(MathCursorPos & i1, MathCursorPos & i2) const
1135 MathCursorPos anc = normalAnchor();
1136 if (anc < cursor()) {
1146 MathCursorPos & MathCursor::cursor()
1148 return Cursor_.back();
1152 MathCursorPos const & MathCursor::cursor() const
1154 return Cursor_.back();
1158 int MathCursor::cellXOffset() const
1160 return par()->cellXOffset(idx());
1164 int MathCursor::cellYOffset() const
1166 return par()->cellYOffset(idx());
1170 int MathCursor::xpos() const
1172 return cellXOffset() + xarray().pos2x(pos());
1176 int MathCursor::ypos() const
1178 return cellYOffset();
1183 void MathCursor::gotoX(int x)
1185 pos() = xarray().x2pos(x - cellXOffset());
1189 bool MathCursor::goUp()
1191 // first ask the inset if it knows better then we
1192 if (par()->idxUp(idx(), pos()))
1195 // leave subscript to the nearest side
1196 MathScriptInset * p = par()->asScriptInset();
1197 if (p && idx() == 0) {
1198 if (pos() <= size() / 2)
1205 // if not, apply brute force.
1209 std::vector<MathCursorPos> save = Cursor_;
1210 y0 -= xarray().ascent();
1211 for (int y = y0 - 4; y > formula()->upperY(); y -= 4) {
1213 if (save != Cursor_ && xarray().yo() < y0)
1221 bool MathCursor::goDown()
1223 // first ask the inset if it knows better then we
1224 if (par()->idxDown(idx(), pos()))
1227 // leave superscript to the nearest side
1228 MathScriptInset * p = par()->asScriptInset();
1229 if (p && idx() == 1) {
1230 if (pos() <= size() / 2)
1237 // if not, apply brute force.
1241 std::vector<MathCursorPos> save = Cursor_;
1242 y0 += xarray().descent();
1243 for (int y = y0 + 4; y < formula()->lowerY(); y += 4) {
1245 if (save != Cursor_ && xarray().yo() > y0)
1253 bool MathCursor::idxLeft()
1255 return par()->idxLeft(idx(), pos());
1259 bool MathCursor::idxRight()
1261 return par()->idxRight(idx(), pos());
1265 void MathCursor::interpret(string const & s)
1267 //lyxerr << "interpret 1: '" << s << "'\n";
1271 if (s.size() == 1) {
1276 //lyxerr << "char: '" << s[0] << "' int: " << int(s[0]) << endl;
1277 //owner_->getIntl()->getTrans().TranslateAndInsert(s[0], lt);
1278 //lyxerr << "trans: '" << s[0] << "' int: " << int(s[0]) << endl;
1280 if (s.size() > 7 && s.substr(0, 7) == "matrix ") {
1285 istringstream is(s.substr(7).c_str());
1286 is >> m >> n >> v_align >> h_align;
1287 m = std::max(1u, m);
1288 n = std::max(1u, n);
1290 niceInsert(MathAtom(new MathArrayInset(m, n, v_align[0], h_align)));
1294 if (s == "\\over" || s == "\\choose" || s == "\\atop") {
1295 MathArray ar = array();
1296 MathAtom t = createMathInset(s.substr(1));
1297 t->asNestInset()->cell(0).swap(array());
1305 niceInsert(createMathInset(s.substr(1)));
1309 void MathCursor::interpret(char c)
1311 //lyxerr << "interpret 2: '" << c << "'\n";
1312 if (c == '^' || c == '_') {
1314 const bool up = (c == '^');
1316 if (hasPrevAtom() && prevAtom()->asScriptInset()) {
1317 prevAtom()->asScriptInset()->ensure(up);
1318 pushRight(prevAtom());
1321 } else if (hasNextAtom() && nextAtom()->asScriptInset()) {
1322 nextAtom()->asScriptInset()->ensure(up);
1323 pushLeft(nextAtom());
1327 plainInsert(MathAtom(new MathScriptInset(up)));
1328 prevAtom()->asScriptInset()->ensure(up);
1329 pushRight(prevAtom());
1340 if (inMacroMode()) {
1341 string name = macroName();
1343 if (name == "\\" && c == '#') {
1344 insert(c, LM_TC_TEX);
1348 if (name == "\\" && c == '\\') {
1350 interpret("\\backslash");
1354 if (name == "\\#" && '1' <= c && c <= '9') {
1355 insert(c, LM_TC_TEX);
1361 insert(c, LM_TC_TEX);
1366 insert(c, LM_TC_TEX);
1378 if (lastcode_ == LM_TC_TEXTRM) {
1379 // suppress direct insertion of to spaces in a row
1380 // the still allows typing '<space>a<space>' and deleting the 'a', but
1381 // it is better than nothing
1382 if (hasPrevAtom() && prevAtom()->getChar() == ' ')
1384 insert(c, LM_TC_TEXTRM);
1389 if (hasPrevAtom() && prevAtom()->asSpaceInset()) {
1390 prevAtom()->asSpaceInset()->incSpace();
1394 mathcursor->popRight();
1399 if (strchr("{}", c)) {
1400 insert(c, LM_TC_TEX);
1406 niceInsert(MathAtom(new MathBraceInset));
1414 if (strchr("#$%", c)) {
1415 insert(MathAtom(new MathSpecialCharInset(c)));
1416 lastcode_ = LM_TC_VAR;
1420 if (isalpha(c) && lastcode_ == LM_TC_GREEK) {
1421 insert(c, LM_TC_VAR);
1425 if (isalpha(c) && lastcode_ == LM_TC_GREEK1) {
1426 insert(c, LM_TC_VAR);
1427 lastcode_ = LM_TC_VAR;
1432 insert(c, LM_TC_TEX);
1433 //bv->owner()->message(_("TeX mode"));
1437 // no special circumstances, so insert the character without any fuss
1438 insert(c, LM_TC_MIN);
1443 ////////////////////////////////////////////////////////////////////////
1446 bool operator==(MathCursorPos const & ti, MathCursorPos const & it)
1448 return ti.par_ == it.par_ && ti.idx_ == it.idx_ && ti.pos_ == it.pos_;
1452 bool operator<(MathCursorPos const & ti, MathCursorPos const & it)
1454 if (ti.par_ != it.par_) {
1455 lyxerr << "can't compare cursor and anchor in different insets\n";
1458 if (ti.idx_ != it.idx_)
1459 return ti.idx_ < it.idx_;
1460 return ti.pos_ < it.pos_;
1464 MathArray & MathCursorPos::cell(MathCursor::idx_type idx) const
1466 return (*par_)->cell(idx);
1470 MathArray & MathCursorPos::cell() const
1472 return (*par_)->cell(idx_);
1476 MathXArray & MathCursorPos::xcell(MathCursor::idx_type idx) const
1478 return (*par_)->xcell(idx);
1482 MathXArray & MathCursorPos::xcell() const
1484 return (*par_)->xcell(idx_);
1488 MathCursorPos MathCursor::normalAnchor() const
1490 // use Anchor on the same level as Cursor
1491 MathCursorPos normal = Anchor_[Cursor_.size() - 1];
1492 if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) {
1493 // anchor is behind cursor -> move anchor behind the inset
1500 void MathCursor::stripFromLastEqualSign()
1502 // find position of last '=' in the array
1503 MathArray & ar = cursor().cell();
1504 MathArray::const_iterator et = ar.end();
1505 for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it)
1506 if ((*it)->getChar() == '=')
1509 // delete everything behind this position
1510 ar.erase(et - ar.begin(), ar.size());