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_braceinset.h"
37 #include "math_charinset.h"
38 #include "math_deliminset.h"
39 #include "math_matrixinset.h"
40 #include "math_scriptinset.h"
41 #include "math_spaceinset.h"
42 #include "math_specialcharinset.h"
56 void grab(MathCursor const & cursor)
61 cursor.getSelection(i1, i2);
62 if (i1.idx_ == i2.idx_)
63 data_.push_back(MathArray(i1.cell(), i1.pos_, i2.pos_));
65 std::vector<MathInset::idx_type> indices =
66 (*i1.par_)->idxBetween(i1.idx_, i2.idx_);
67 for (MathInset::idx_type i = 0; i < indices.size(); ++i)
68 data_.push_back(i1.cell(indices[i]));
72 void erase(MathCursor & cursor)
76 cursor.getSelection(i1, i2);
77 if (i1.idx_ == i2.idx_)
78 i1.cell().erase(i1.pos_, i2.pos_);
80 std::vector<MathInset::idx_type> indices =
81 (*i1.par_)->idxBetween(i1.idx_, i2.idx_);
82 for (unsigned i = 0; i < indices.size(); ++i)
83 i1.cell(indices[i]).erase();
88 void paste(MathCursor & cursor) const
90 MathArray ar = glue();
94 // glues selection to one cell
95 MathArray glue() const
98 for (unsigned i = 0; i < data_.size(); ++i)
99 ar.push_back(data_[i]);
108 std::vector<MathArray> data_;
112 Selection theSelection;
116 std::ostream & operator<<(std::ostream & os, MathCursorPos const & p)
118 os << "(par: " << p.par_ << " idx: " << p.idx_ << " pos: " << p.pos_ << ")";
126 MathCursor::MathCursor(InsetFormulaBase * formula, bool left)
127 : formula_(formula), lastcode_(LM_TC_VAR), selection_(false)
129 left ? first() : last();
133 void MathCursor::push(MathAtom & t)
139 Cursor_.push_back(p);
143 void MathCursor::pushLeft(MathAtom & t)
145 //cerr << "Entering atom "; t->write(cerr, false); cerr << " left\n";
147 t->idxFirst(idx(), pos());
151 void MathCursor::pushRight(MathAtom & t)
153 //cerr << "Entering atom "; t->write(cerr, false); cerr << " right\n";
156 t->idxLast(idx(), pos());
160 bool MathCursor::popLeft()
162 //cerr << "Leaving atom "; par()->write(cerr, false); cerr << " left\n";
163 if (Cursor_.size() <= 1)
166 // nextInset()->removeEmptyScripts();
169 // nextAtom()->removeEmptyScripts();
174 bool MathCursor::popRight()
176 //cerr << "Leaving atom "; par()->write(cerr, false); cerr << " right\n";
177 if (Cursor_.size() <= 1)
180 // nextInset()->removeEmptyScripts();
183 // nextInset()->removeEmptyScripts();
191 void MathCursor::dump(char const * what) const
193 lyxerr << "MC: " << what << "\n";
194 for (unsigned i = 0; i < Cursor_.size(); ++i)
195 lyxerr << " i: " << i
196 << " Cursor: pos: " << Cursor_[i].pos_
197 << " idx: " << Cursor_[i].idx_
198 << " par: " << Cursor_[i].par_ << "\n";
200 for (unsigned i = 0; i < Anchor_.size(); ++i)
201 lyxerr << " i: " << i
202 << " Anchor: pos: " << Anchor_[i].pos_
203 << " idx: " << Anchor_[i].idx_
204 << " par: " << Anchor_[i].par_ << "\n";
206 lyxerr << " sel: " << selection_ << "\n";
210 void MathCursor::seldump(char const * str) const
212 //lyxerr << "SEL: " << str << ": '" << theSelection << "'\n";
215 lyxerr << "\n\n\n=================vvvvvvvvvvvvv======================= "
216 << str << "\ntheSelection: " << selection_
217 << " '" << theSelection.glue() << "'\n";
218 for (unsigned int i = 0; i < Cursor_.size(); ++i)
219 lyxerr << Cursor_[i].par_ << "\n'" << Cursor_[i].cell() << "'\n";
221 for (unsigned int i = 0; i < Anchor_.size(); ++i)
222 lyxerr << Anchor_[i].par_ << "\n'" << Anchor_[i].cell() << "'\n";
223 //lyxerr << "\ncursor.pos_: " << pos();
224 //lyxerr << "\nanchor.pos_: " << anchor().pos_;
225 lyxerr << "\n===================^^^^^^^^^^^^=====================\n\n\n";
230 void MathCursor::seldump(char const *) const {}
231 void MathCursor::dump(char const *) const {}
236 UpdatableInset * MathCursor::asHyperActiveInset() const
238 return par()->asHyperActiveInset();
242 bool MathCursor::isInside(MathInset const * p) const
244 for (unsigned i = 0; i < Cursor_.size(); ++i)
245 if (Cursor_[i].par_->nucleus() == p)
251 bool MathCursor::openable(MathAtom const & t, bool sel) const
253 if (t->isHyperActive())
259 if (t->asScriptInset())
263 // we can't move into anything new during selection
264 if (Cursor_.size() == Anchor_.size())
266 if (&t != Anchor_[Cursor_.size()].par_)
273 bool MathCursor::positionable(MathAtom const & t, int x, int y) const
276 // we can't move into anything new during selection
277 if (Cursor_.size() == Anchor_.size())
279 //if (t != Anchor_[Cursor_.size()].par_)
283 return t->nargs() && t->covers(x, y);
287 bool MathCursor::posLeft()
296 bool MathCursor::posRight()
305 bool MathCursor::left(bool sel)
310 lastcode_ = LM_TC_VAR;
314 lastcode_ = LM_TC_VAR;
316 if (hasPrevAtom() && openable(prevAtom(), sel)) {
317 if (prevAtom()->isHyperActive()) {
318 lyxerr << "entering hyperactive inset\n";
320 pushRight(prevAtom());
324 return posLeft() || idxLeft() || popLeft() || selection_;
328 bool MathCursor::right(bool sel)
333 lastcode_ = LM_TC_VAR;
337 lastcode_ = LM_TC_VAR;
339 if (hasNextAtom() && openable(nextAtom(), sel)) {
340 if (nextAtom()->isHyperActive()) {
341 lyxerr << "entering hyperactive inset\n";
344 nextAtom()->edit(formula()->view(), x, y, 0);
346 pushLeft(nextAtom());
350 return posRight() || idxRight() || popRight() || selection_;
354 void MathCursor::first()
357 pushLeft(formula_->par());
361 void MathCursor::last()
368 void MathCursor::setPos(int x, int y)
371 //lyxerr << "MathCursor::setPos x: " << x << " y: " << y << "\n";
374 lastcode_ = LM_TC_VAR;
377 cursor().par_ = &formula_->par();
382 //lyxerr << "found idx: " << idx() << " cursor: " << pos() << "\n";
383 int distmin = 1 << 30; // large enough
384 for (unsigned int i = 0; i < par()->nargs(); ++i) {
385 MathXArray const & ar = par()->xcell(i);
386 int x1 = x - ar.xo();
387 int y1 = y - ar.yo();
388 MathXArray::size_type c = ar.x2pos(x1);
389 int xx = abs(x1 - ar.pos2x(c));
391 //lyxerr << "idx: " << i << " xx: " << xx << " yy: " << yy
392 // << " c: " << c << " xo: " << ar.xo() << "\n";
393 if (yy + xx <= distmin) {
399 //lyxerr << "found idx: " << idx() << " cursor: "
401 if (hasNextAtom() && positionable(nextAtom(), x, y))
402 pushLeft(nextAtom());
403 else if (hasPrevAtom() && positionable(prevAtom(), x, y))
404 pushRight(prevAtom());
412 void MathCursor::home(bool sel)
417 lastcode_ = LM_TC_VAR;
418 if (!par()->idxHome(idx(), pos()))
424 void MathCursor::end(bool sel)
429 lastcode_ = LM_TC_VAR;
430 if (!par()->idxEnd(idx(), pos()))
436 void MathCursor::plainErase()
438 array().erase(pos());
442 void MathCursor::plainInsert(MathAtom const & t)
444 array().insert(pos(), t);
449 void MathCursor::insert(char c, MathTextCodes t)
451 //lyxerr << "inserting '" << c << "'\n";
452 plainInsert(MathAtom(new MathCharInset(c, t)));
456 void MathCursor::insert(MathAtom const & t)
471 void MathCursor::niceInsert(MathAtom const & t)
474 insert(t); // inserting invalidates the pointer!
475 MathAtom const & p = prevAtom();
478 right(); // do not push for e.g. MathSymbolInset
482 #warning "redraw disabled"
484 //p->metrics(p->size());
488 void MathCursor::insert(MathArray const & ar)
494 array().insert(pos(), ar);
499 void MathCursor::paste(MathArray const & ar)
503 array().insert(pos(), ar);
508 void MathCursor::backspace()
520 MathScriptInset * p = prevAtom()->asScriptInset();
522 p->removeScript(p->hasUp());
523 // Don't delete if there is anything left
524 if (p->hasUp() || p->hasDown())
533 void MathCursor::erase()
543 // delete empty cells if necessary
544 if (array().empty()) {
547 par()->idxDelete(idx(), popit, removeit);
548 if (popit && popLeft() && removeit)
556 MathScriptInset * p = nextAtom()->asScriptInset();
558 p->removeScript(p->hasUp());
559 // Don't delete if there is anything left
560 if (p->hasUp() || p->hasDown())
568 void MathCursor::delLine()
577 if (par()->nrows() > 1)
578 par()->delRow(row());
585 bool MathCursor::up(bool sel)
592 // check whether we could move into a superscript
594 MathAtom & p = prevAtom();
595 if (p->asScriptInset() && p->asScriptInset()->hasUp()) {
604 MathAtom & n = nextAtom();
605 if (n->asScriptInset() && n->asScriptInset()->hasUp()) {
614 return goUp() || selection_;
618 bool MathCursor::down(bool sel)
625 // check whether we could move into a subscript
627 MathAtom & p = prevAtom();
628 if (p->asScriptInset() && p->asScriptInset()->hasDown()) {
637 MathAtom & n = nextAtom();
638 if (n->asScriptInset() && n->asScriptInset()->hasDown()) {
647 return goDown() || selection_;
651 bool MathCursor::toggleLimits()
655 MathScriptInset * t = prevAtom()->asScriptInset();
658 int old = t->limits();
659 t->limits(old < 0 ? 1 : -1);
660 return old != t->limits();
664 void MathCursor::macroModeClose()
666 string s = macroName();
668 size_type old = pos();
670 array().erase(pos(), old);
676 int MathCursor::macroNamePos() const
678 for (int i = pos() - 1; i >= 0; --i) {
679 MathAtom & p = array().at(i);
680 if (p->code() == LM_TC_TEX && p->getChar() == '\\')
687 string MathCursor::macroName() const
690 for (int i = macroNamePos(); i >= 0 && i < int(pos()); ++i)
691 s += array().at(i)->getChar();
696 void MathCursor::selCopy()
700 theSelection.grab(*this);
706 void MathCursor::selCut()
710 theSelection.grab(*this);
711 theSelection.erase(*this);
714 theSelection.clear();
719 void MathCursor::selDel()
723 theSelection.erase(*this);
731 void MathCursor::selPaste()
734 theSelection.paste(*this);
735 theSelection.grab(*this);
740 void MathCursor::selHandle(bool sel)
742 if (sel == selection_)
745 theSelection.clear();
751 void MathCursor::selStart()
757 theSelection.clear();
763 void MathCursor::selClear()
770 void MathCursor::selGet(MathArray & ar)
776 theSelection.grab(*this);
777 ar = theSelection.glue();
782 void MathCursor::drawSelection(Painter & pain) const
789 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);
813 // draw anchor if different from selection boundary
814 MathCursorPos anc = Anchor_.back();
815 if (anc != i1 && anc != i2) {
816 MathXArray & c = anc.xcell();
817 int x = c.xo() + c.pos2x(anc.pos_);
818 int y1 = c.yo() - c.ascent();
819 int y2 = c.yo() + c.descent();
820 pain.line(x, y1, x, y2, LColor::mathline);
826 void MathCursor::handleFont(MathTextCodes t)
832 getSelection(i1, i2);
833 if (i1.idx_ == i2.idx_) {
834 MathArray & ar = i1.cell();
835 for (MathInset::pos_type pos = i1.pos_; pos != i2.pos_; ++pos)
836 ar.at(pos)->handleFont(t);
839 lastcode_ = (lastcode_ == t) ? LM_TC_VAR : t;
843 void MathCursor::handleDelim(string const & l, string const & r)
845 handleNest(new MathDelimInset(l, r));
849 void MathCursor::handleNest(MathInset * p)
853 p->cell(0) = theSelection.glue();
855 insert(MathAtom(p)); // this invalidates p!
856 pushRight(prevAtom());
860 void MathCursor::getPos(int & x, int & y)
863 #warning This should probably take cellXOffset and cellYOffset into account
865 x = xarray().xo() + xarray().pos2x(pos());
870 MathAtom & MathCursor::par() const
872 return *cursor().par_;
876 InsetFormulaBase const * MathCursor::formula()
882 MathCursor::idx_type MathCursor::idx() const
884 return cursor().idx_;
888 MathCursor::idx_type & MathCursor::idx()
890 return cursor().idx_;
894 MathCursor::pos_type MathCursor::pos() const
896 return cursor().pos_;
900 MathCursor::pos_type & MathCursor::pos()
902 return cursor().pos_;
906 bool MathCursor::inMacroMode() const
908 return macroNamePos() != -1;
912 bool MathCursor::selection() const
918 MathArrayInset * MathCursor::enclosingArray(MathCursor::idx_type & idx) const
920 for (int i = Cursor_.size() - 1; i >= 0; --i) {
921 MathArrayInset * p = (*Cursor_[i].par_)->asArrayInset();
923 idx = Cursor_[i].idx_;
931 void MathCursor::pullArg(bool goright)
934 MathArray a = array();
936 MathScriptInset const * p = par()->asScriptInset();
938 // special handling for scripts
939 const bool up = p->hasUp();
941 MathScriptInset * q = nextAtom()->asScriptInset();
945 array().insert(pos(), a);
951 array().insert(pos(), a);
958 void MathCursor::normalize() const
961 #warning This is evil!
963 MathCursor * it = const_cast<MathCursor *>(this);
965 if (idx() >= par()->nargs()) {
966 lyxerr << "this should not really happen - 1: "
967 << idx() << " " << par()->nargs() << "\n";
970 it->idx() = min(idx(), par()->nargs() - 1);
972 if (pos() > size()) {
973 lyxerr << "this should not really happen - 2: "
974 << pos() << " " << size() << " in idx: " << it->idx()
976 MathWriteInfo wi(0, lyxerr, false);
977 it->par()->write(wi);
981 it->pos() = min(pos(), size());
985 MathCursor::size_type MathCursor::size() const
987 return array().size();
991 MathCursor::col_type MathCursor::col() const
993 return par()->col(idx());
997 MathCursor::row_type MathCursor::row() const
999 return par()->row(idx());
1003 bool MathCursor::hasPrevAtom() const
1009 bool MathCursor::hasNextAtom() const
1011 return pos() < size();
1015 MathAtom const & MathCursor::prevAtom() const
1017 lyx::Assert(pos() > 0);
1018 return array().at(pos() - 1);
1022 MathAtom & MathCursor::prevAtom()
1024 lyx::Assert(pos() > 0);
1025 return array().at(pos() - 1);
1029 MathAtom const & MathCursor::nextAtom() const
1031 lyx::Assert(pos() < size());
1032 return array().at(pos());
1036 MathAtom & MathCursor::nextAtom()
1038 lyx::Assert(pos() < size());
1039 return array().at(pos());
1043 MathArray & MathCursor::array() const
1045 static MathArray dummy;
1047 if (idx() >= par()->nargs()) {
1048 lyxerr << "############ idx_ " << idx() << " not valid\n";
1052 return cursor().cell();
1056 MathXArray & MathCursor::xarray() const
1058 return cursor().xcell();
1062 void MathCursor::idxNext()
1064 par()->idxNext(idx(), pos());
1068 void MathCursor::idxPrev()
1070 par()->idxPrev(idx(), pos());
1074 void MathCursor::splitCell()
1076 if (idx() == par()->nargs() - 1)
1078 MathArray ar = array();
1080 array().erase(pos(), size());
1083 array().insert(0, ar);
1087 void MathCursor::breakLine()
1089 // leave inner cells
1093 MathMatrixInset * p = formula()->par()->asMatrixInset();
1097 if (p->getType() == LM_OT_SIMPLE || p->getType() == LM_OT_EQUATION) {
1098 p->mutate(LM_OT_EQNARRAY);
1105 const row_type r = row();
1106 for (col_type c = col() + 1; c < p->ncols(); ++c) {
1107 const MathMatrixInset::idx_type i1 = p->index(r, c);
1108 const MathMatrixInset::idx_type i2 = p->index(r + 1, c);
1109 //lyxerr << "swapping cells " << i1 << " and " << i2 << "\n";
1110 p->cell(i1).swap(p->cell(i2));
1115 p->cell(idx()).swap(p->cell(idx() + p->ncols() - 1));
1120 char MathCursor::valign() const
1123 MathArrayInset * p = enclosingArray(idx);
1124 return p ? p->valign() : '\0';
1128 char MathCursor::halign() const
1131 MathArrayInset * p = enclosingArray(idx);
1132 return p ? p->halign(idx % p->ncols()) : '\0';
1136 void MathCursor::getSelection(MathCursorPos & i1, MathCursorPos & i2) const
1138 MathCursorPos anc = normalAnchor();
1139 if (anc < cursor()) {
1149 MathCursorPos & MathCursor::cursor()
1151 return Cursor_.back();
1155 MathCursorPos const & MathCursor::cursor() const
1157 return Cursor_.back();
1161 int MathCursor::cellXOffset() const
1163 return par()->cellXOffset(idx());
1167 int MathCursor::cellYOffset() const
1169 return par()->cellYOffset(idx());
1173 int MathCursor::xpos() const
1175 return cellXOffset() + xarray().pos2x(pos());
1179 int MathCursor::ypos() const
1181 return cellYOffset();
1186 void MathCursor::gotoX(int x)
1188 pos() = xarray().x2pos(x - cellXOffset());
1192 bool MathCursor::goUp()
1194 // first ask the inset if it knows better then we
1195 if (par()->idxUp(idx(), pos()))
1198 // leave subscript to the nearest side
1199 MathScriptInset * p = par()->asScriptInset();
1200 if (p && idx() == 0) {
1201 if (pos() <= size() / 2)
1208 // if not, apply brute force.
1212 std::vector<MathCursorPos> save = Cursor_;
1213 y0 -= xarray().ascent();
1214 for (int y = y0 - 4; y > formula()->upperY(); y -= 4) {
1216 if (save != Cursor_ && xarray().yo() < y0)
1224 bool MathCursor::goDown()
1226 // first ask the inset if it knows better then we
1227 if (par()->idxDown(idx(), pos()))
1230 // leave superscript to the nearest side
1231 MathScriptInset * p = par()->asScriptInset();
1232 if (p && idx() == 1) {
1233 if (pos() <= size() / 2)
1240 // if not, apply brute force.
1244 std::vector<MathCursorPos> save = Cursor_;
1245 y0 += xarray().descent();
1246 for (int y = y0 + 4; y < formula()->lowerY(); y += 4) {
1248 if (save != Cursor_ && xarray().yo() > y0)
1256 bool MathCursor::idxLeft()
1258 return par()->idxLeft(idx(), pos());
1262 bool MathCursor::idxRight()
1264 return par()->idxRight(idx(), pos());
1268 void MathCursor::interpret(string const & s)
1270 //lyxerr << "interpret 1: '" << s << "'\n";
1274 if (s.size() == 1) {
1279 //lyxerr << "char: '" << s[0] << "' int: " << int(s[0]) << endl;
1280 //owner_->getIntl()->getTrans().TranslateAndInsert(s[0], lt);
1281 //lyxerr << "trans: '" << s[0] << "' int: " << int(s[0]) << endl;
1283 if (s.size() > 7 && s.substr(0, 7) == "matrix ") {
1288 istringstream is(s.substr(7).c_str());
1289 is >> m >> n >> v_align >> h_align;
1290 m = std::max(1u, m);
1291 n = std::max(1u, n);
1293 niceInsert(MathAtom(new MathArrayInset(m, n, v_align[0], h_align)));
1297 if (s == "\\over" || s == "\\choose" || s == "\\atop") {
1298 MathArray ar = array();
1299 MathAtom t = createMathInset(s.substr(1));
1300 t->asNestInset()->cell(0).swap(array());
1308 niceInsert(createMathInset(s.substr(1)));
1312 void MathCursor::interpret(char c)
1314 //lyxerr << "interpret 2: '" << c << "'\n";
1316 if (inMacroMode()) {
1317 string name = macroName();
1319 if (name == "\\" && c == '#') {
1320 insert(c, LM_TC_TEX);
1324 if (name == "\\" && c == '\\') {
1326 interpret("\\backslash");
1330 if (name == "\\#" && '1' <= c && c <= '9') {
1331 insert(c, LM_TC_TEX);
1337 insert(c, LM_TC_TEX);
1342 insert(c, LM_TC_TEX);
1352 if (c == '^' || c == '_') {
1353 const bool up = (c == '^');
1355 if (hasPrevAtom() && prevAtom()->asScriptInset()) {
1356 prevAtom()->asScriptInset()->ensure(up);
1357 pushRight(prevAtom());
1360 } else if (hasNextAtom() && nextAtom()->asScriptInset()) {
1361 nextAtom()->asScriptInset()->ensure(up);
1362 pushLeft(nextAtom());
1366 plainInsert(MathAtom(new MathScriptInset(up)));
1367 prevAtom()->asScriptInset()->ensure(up);
1368 pushRight(prevAtom());
1380 if (lastcode_ == LM_TC_TEXTRM) {
1381 // suppress direct insertion of to spaces in a row
1382 // the still allows typing '<space>a<space>' and deleting the 'a', but
1383 // it is better than nothing
1384 if (hasPrevAtom() && prevAtom()->getChar() == ' ')
1386 insert(c, LM_TC_TEXTRM);
1391 if (hasPrevAtom() && prevAtom()->asSpaceInset()) {
1392 prevAtom()->asSpaceInset()->incSpace();
1396 mathcursor->popRight();
1401 if (strchr("{}", c)) {
1402 insert(c, LM_TC_TEX);
1408 niceInsert(MathAtom(new MathBraceInset));
1416 if (strchr("#$%", c)) {
1417 insert(MathAtom(new MathSpecialCharInset(c)));
1418 lastcode_ = LM_TC_VAR;
1422 if (isalpha(c) && lastcode_ == LM_TC_GREEK) {
1423 insert(c, LM_TC_VAR);
1427 if (isalpha(c) && lastcode_ == LM_TC_GREEK1) {
1428 insert(c, LM_TC_VAR);
1429 lastcode_ = LM_TC_VAR;
1434 insert(c, LM_TC_TEX);
1435 //bv->owner()->message(_("TeX mode"));
1439 // no special circumstances, so insert the character without any fuss
1440 insert(c, LM_TC_MIN);
1445 ////////////////////////////////////////////////////////////////////////
1448 bool operator==(MathCursorPos const & ti, MathCursorPos const & it)
1450 return ti.par_ == it.par_ && ti.idx_ == it.idx_ && ti.pos_ == it.pos_;
1454 bool operator<(MathCursorPos const & ti, MathCursorPos const & it)
1456 if (ti.par_ != it.par_) {
1457 lyxerr << "can't compare cursor and anchor in different insets\n";
1460 if (ti.idx_ != it.idx_)
1461 return ti.idx_ < it.idx_;
1462 return ti.pos_ < it.pos_;
1466 MathArray & MathCursorPos::cell(MathCursor::idx_type idx) const
1468 return (*par_)->cell(idx);
1472 MathArray & MathCursorPos::cell() const
1474 return (*par_)->cell(idx_);
1478 MathXArray & MathCursorPos::xcell(MathCursor::idx_type idx) const
1480 return (*par_)->xcell(idx);
1484 MathXArray & MathCursorPos::xcell() const
1486 return (*par_)->xcell(idx_);
1490 MathCursorPos MathCursor::normalAnchor() const
1492 // use Anchor on the same level as Cursor
1493 MathCursorPos normal = Anchor_[Cursor_.size() - 1];
1494 if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) {
1495 // anchor is behind cursor -> move anchor behind the inset
1502 void MathCursor::stripFromLastEqualSign()
1504 // find position of last '=' in the array
1505 MathArray & ar = cursor().cell();
1506 MathArray::const_iterator et = ar.end();
1507 for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it)
1508 if ((*it)->getChar() == '=')
1511 // delete everything behind this position
1512 ar.erase(et - ar.begin(), ar.size());