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"
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 MathWriteInfo 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 MathMatrixInset * p = formula()->par()->asMatrixInset();
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 const MathMatrixInset::idx_type i1 = p->index(r, c);
1109 const MathMatrixInset::idx_type i2 = p->index(r + 1, c);
1110 //lyxerr << "swapping cells " << i1 << " and " << i2 << "\n";
1111 p->cell(i1).swap(p->cell(i2));
1116 p->cell(idx()).swap(p->cell(idx() + p->ncols() - 1));
1121 char MathCursor::valign() const
1124 MathArrayInset * p = enclosingArray(idx);
1125 return p ? p->valign() : '\0';
1129 char MathCursor::halign() const
1132 MathArrayInset * p = enclosingArray(idx);
1133 return p ? p->halign(idx % p->ncols()) : '\0';
1137 void MathCursor::getSelection(MathCursorPos & i1, MathCursorPos & i2) const
1139 MathCursorPos anc = normalAnchor();
1140 if (anc < cursor()) {
1150 MathCursorPos & MathCursor::cursor()
1152 return Cursor_.back();
1156 MathCursorPos const & MathCursor::cursor() const
1158 return Cursor_.back();
1162 int MathCursor::cellXOffset() const
1164 return par()->cellXOffset(idx());
1168 int MathCursor::cellYOffset() const
1170 return par()->cellYOffset(idx());
1174 int MathCursor::xpos() const
1176 return cellXOffset() + xarray().pos2x(pos());
1180 int MathCursor::ypos() const
1182 return cellYOffset();
1187 void MathCursor::gotoX(int x)
1189 pos() = xarray().x2pos(x - cellXOffset());
1193 bool MathCursor::goUp()
1195 // first ask the inset if it knows better then we
1196 if (par()->idxUp(idx(), pos()))
1199 // leave subscript to the nearest side
1200 MathScriptInset * p = par()->asScriptInset();
1201 if (p && idx() == 0) {
1202 if (pos() <= size() / 2)
1209 // if not, apply brute force.
1213 std::vector<MathCursorPos> save = Cursor_;
1214 y0 -= xarray().ascent();
1215 for (int y = y0 - 4; y > formula()->upperY(); y -= 4) {
1217 if (save != Cursor_ && xarray().yo() < y0)
1225 bool MathCursor::goDown()
1227 // first ask the inset if it knows better then we
1228 if (par()->idxDown(idx(), pos()))
1231 // leave superscript to the nearest side
1232 MathScriptInset * p = par()->asScriptInset();
1233 if (p && idx() == 1) {
1234 if (pos() <= size() / 2)
1241 // if not, apply brute force.
1245 std::vector<MathCursorPos> save = Cursor_;
1246 y0 += xarray().descent();
1247 for (int y = y0 + 4; y < formula()->lowerY(); y += 4) {
1249 if (save != Cursor_ && xarray().yo() > y0)
1257 bool MathCursor::idxLeft()
1259 return par()->idxLeft(idx(), pos());
1263 bool MathCursor::idxRight()
1265 return par()->idxRight(idx(), pos());
1269 void MathCursor::interpret(string const & s)
1271 //lyxerr << "interpret 1: '" << s << "'\n";
1275 if (s.size() == 1) {
1280 //lyxerr << "char: '" << s[0] << "' int: " << int(s[0]) << endl;
1281 //owner_->getIntl()->getTrans().TranslateAndInsert(s[0], lt);
1282 //lyxerr << "trans: '" << s[0] << "' int: " << int(s[0]) << endl;
1284 if (s.size() > 7 && s.substr(0, 7) == "matrix ") {
1289 istringstream is(s.substr(7).c_str());
1290 is >> m >> n >> v_align >> h_align;
1291 m = std::max(1u, m);
1292 n = std::max(1u, n);
1294 niceInsert(MathAtom(new MathArrayInset(m, n, v_align[0], h_align)));
1298 if (s == "\\over" || s == "\\choose" || s == "\\atop") {
1299 MathArray ar = array();
1300 MathAtom t = createMathInset(s.substr(1));
1301 t->asNestInset()->cell(0).swap(array());
1309 niceInsert(createMathInset(s.substr(1)));
1313 void MathCursor::interpret(char c)
1315 //lyxerr << "interpret 2: '" << c << "'\n";
1317 if (inMacroMode()) {
1318 string name = macroName();
1320 if (name == "\\" && c == '#') {
1321 insert(c, LM_TC_TEX);
1325 if (name == "\\" && c == '\\') {
1327 interpret("\\backslash");
1331 if (name == "\\#" && '1' <= c && c <= '9') {
1332 insert(c, LM_TC_TEX);
1338 insert(c, LM_TC_TEX);
1343 insert(c, LM_TC_TEX);
1353 if (c == '^' || c == '_') {
1354 const bool up = (c == '^');
1356 if (hasPrevAtom() && prevAtom()->asScriptInset()) {
1357 prevAtom()->asScriptInset()->ensure(up);
1358 pushRight(prevAtom());
1361 } else if (hasNextAtom() && nextAtom()->asScriptInset()) {
1362 nextAtom()->asScriptInset()->ensure(up);
1363 pushLeft(nextAtom());
1367 plainInsert(MathAtom(new MathScriptInset(up)));
1368 prevAtom()->asScriptInset()->ensure(up);
1369 pushRight(prevAtom());
1381 if (lastcode_ == LM_TC_TEXTRM) {
1382 // suppress direct insertion of to spaces in a row
1383 // the still allows typing '<space>a<space>' and deleting the 'a', but
1384 // it is better than nothing
1385 if (hasPrevAtom() && prevAtom()->getChar() == ' ')
1387 insert(c, LM_TC_TEXTRM);
1392 if (hasPrevAtom() && prevAtom()->asSpaceInset()) {
1393 prevAtom()->asSpaceInset()->incSpace();
1397 mathcursor->popRight();
1402 if (strchr("{}", c)) {
1403 insert(c, LM_TC_TEX);
1409 niceInsert(MathAtom(new MathBraceInset));
1417 if (strchr("#$%", c)) {
1418 insert(MathAtom(new MathSpecialCharInset(c)));
1419 lastcode_ = LM_TC_VAR;
1423 if (isalpha(c) && lastcode_ == LM_TC_GREEK) {
1424 insert(c, LM_TC_VAR);
1428 if (isalpha(c) && lastcode_ == LM_TC_GREEK1) {
1429 insert(c, LM_TC_VAR);
1430 lastcode_ = LM_TC_VAR;
1435 insert(c, LM_TC_TEX);
1436 //bv->owner()->message(_("TeX mode"));
1440 // no special circumstances, so insert the character without any fuss
1441 insert(c, LM_TC_MIN);
1446 ////////////////////////////////////////////////////////////////////////
1449 bool operator==(MathCursorPos const & ti, MathCursorPos const & it)
1451 return ti.par_ == it.par_ && ti.idx_ == it.idx_ && ti.pos_ == it.pos_;
1455 bool operator<(MathCursorPos const & ti, MathCursorPos const & it)
1457 if (ti.par_ != it.par_) {
1458 lyxerr << "can't compare cursor and anchor in different insets\n";
1461 if (ti.idx_ != it.idx_)
1462 return ti.idx_ < it.idx_;
1463 return ti.pos_ < it.pos_;
1467 MathArray & MathCursorPos::cell(MathCursor::idx_type idx) const
1469 return (*par_)->cell(idx);
1473 MathArray & MathCursorPos::cell() const
1475 return (*par_)->cell(idx_);
1479 MathXArray & MathCursorPos::xcell(MathCursor::idx_type idx) const
1481 return (*par_)->xcell(idx);
1485 MathXArray & MathCursorPos::xcell() const
1487 return (*par_)->xcell(idx_);
1491 MathCursorPos MathCursor::normalAnchor() const
1493 // use Anchor on the same level as Cursor
1494 MathCursorPos normal = Anchor_[Cursor_.size() - 1];
1495 if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) {
1496 // anchor is behind cursor -> move anchor behind the inset
1503 void MathCursor::stripFromLastEqualSign()
1505 // find position of last '=' in the array
1506 MathArray & ar = cursor().cell();
1507 MathArray::const_iterator et = ar.end();
1508 for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it)
1509 if ((*it)->getChar() == '=')
1512 // delete everything behind this position
1513 ar.erase(et - ar.begin(), ar.size());