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_casesinset.h"
35 #include "math_factory.h"
36 #include "math_arrayinset.h"
37 #include "math_braceinset.h"
38 #include "math_charinset.h"
39 #include "math_deliminset.h"
40 #include "math_hullinset.h"
41 #include "math_scriptinset.h"
42 #include "math_spaceinset.h"
43 #include "math_specialcharinset.h"
44 #include "math_mathmlstream.h"
58 void grab(MathCursor const & cursor)
63 cursor.getSelection(i1, i2);
64 if (i1.idx_ == i2.idx_)
65 data_.push_back(MathArray(i1.cell(), i1.pos_, i2.pos_));
67 std::vector<MathInset::idx_type> indices =
68 (*i1.par_)->idxBetween(i1.idx_, i2.idx_);
69 for (MathInset::idx_type i = 0; i < indices.size(); ++i)
70 data_.push_back(i1.cell(indices[i]));
74 void erase(MathCursor & cursor)
78 cursor.getSelection(i1, i2);
79 if (i1.idx_ == i2.idx_)
80 i1.cell().erase(i1.pos_, i2.pos_);
82 std::vector<MathInset::idx_type> indices =
83 (*i1.par_)->idxBetween(i1.idx_, i2.idx_);
84 for (unsigned i = 0; i < indices.size(); ++i)
85 i1.cell(indices[i]).erase();
90 void paste(MathCursor & cursor) const
92 MathArray ar = glue();
96 // glues selection to one cell
97 MathArray glue() const
100 for (unsigned i = 0; i < data_.size(); ++i)
101 ar.push_back(data_[i]);
110 std::vector<MathArray> data_;
114 Selection theSelection;
118 std::ostream & operator<<(std::ostream & os, MathCursorPos const & p)
120 os << "(par: " << p.par_ << " idx: " << p.idx_ << " pos: " << p.pos_ << ")";
128 MathCursor::MathCursor(InsetFormulaBase * formula, bool left)
129 : formula_(formula), lastcode_(LM_TC_VAR), selection_(false)
131 left ? first() : last();
135 void MathCursor::push(MathAtom & t)
141 Cursor_.push_back(p);
145 void MathCursor::pushLeft(MathAtom & t)
147 //cerr << "Entering atom "; t->write(cerr, false); cerr << " left\n";
149 t->idxFirst(idx(), pos());
153 void MathCursor::pushRight(MathAtom & t)
155 //cerr << "Entering atom "; t->write(cerr, false); cerr << " right\n";
158 t->idxLast(idx(), pos());
162 bool MathCursor::popLeft()
164 //cerr << "Leaving atom "; par()->write(cerr, false); cerr << " left\n";
165 if (Cursor_.size() <= 1)
168 // nextInset()->removeEmptyScripts();
171 // nextAtom()->removeEmptyScripts();
176 bool MathCursor::popRight()
178 //cerr << "Leaving atom "; par()->write(cerr, false); cerr << " right\n";
179 if (Cursor_.size() <= 1)
182 // nextInset()->removeEmptyScripts();
185 // nextInset()->removeEmptyScripts();
193 void MathCursor::dump(char const * what) const
195 lyxerr << "MC: " << what << "\n";
196 for (unsigned i = 0; i < Cursor_.size(); ++i)
197 lyxerr << " i: " << i
198 << " Cursor: pos: " << Cursor_[i].pos_
199 << " idx: " << Cursor_[i].idx_
200 << " par: " << Cursor_[i].par_ << "\n";
202 for (unsigned i = 0; i < Anchor_.size(); ++i)
203 lyxerr << " i: " << i
204 << " Anchor: pos: " << Anchor_[i].pos_
205 << " idx: " << Anchor_[i].idx_
206 << " par: " << Anchor_[i].par_ << "\n";
208 lyxerr << " sel: " << selection_ << "\n";
212 void MathCursor::seldump(char const * str) const
214 //lyxerr << "SEL: " << str << ": '" << theSelection << "'\n";
217 lyxerr << "\n\n\n=================vvvvvvvvvvvvv======================= "
218 << str << "\ntheSelection: " << selection_
219 << " '" << theSelection.glue() << "'\n";
220 for (unsigned int i = 0; i < Cursor_.size(); ++i)
221 lyxerr << Cursor_[i].par_ << "\n'" << Cursor_[i].cell() << "'\n";
223 for (unsigned int i = 0; i < Anchor_.size(); ++i)
224 lyxerr << Anchor_[i].par_ << "\n'" << Anchor_[i].cell() << "'\n";
225 //lyxerr << "\ncursor.pos_: " << pos();
226 //lyxerr << "\nanchor.pos_: " << anchor().pos_;
227 lyxerr << "\n===================^^^^^^^^^^^^=====================\n\n\n";
232 void MathCursor::seldump(char const *) const {}
233 void MathCursor::dump(char const *) const {}
238 UpdatableInset * MathCursor::asHyperActiveInset() const
240 return par()->asHyperActiveInset();
244 bool MathCursor::isInside(MathInset const * p) const
246 for (unsigned i = 0; i < Cursor_.size(); ++i)
247 if (Cursor_[i].par_->nucleus() == p)
253 bool MathCursor::openable(MathAtom const & t, bool sel) const
255 if (t->isHyperActive())
261 if (t->asScriptInset())
265 // we can't move into anything new during selection
266 if (Cursor_.size() == Anchor_.size())
268 if (&t != Anchor_[Cursor_.size()].par_)
275 bool MathCursor::positionable(MathAtom const & t, int x, int y) const
278 // we can't move into anything new during selection
279 if (Cursor_.size() == Anchor_.size())
281 //if (t != Anchor_[Cursor_.size()].par_)
285 return t->nargs() && t->covers(x, y);
289 bool MathCursor::posLeft()
298 bool MathCursor::posRight()
307 bool MathCursor::left(bool sel)
312 lastcode_ = LM_TC_VAR;
316 lastcode_ = LM_TC_VAR;
318 if (hasPrevAtom() && openable(prevAtom(), sel)) {
319 if (prevAtom()->isHyperActive()) {
320 lyxerr << "entering hyperactive inset\n";
322 pushRight(prevAtom());
326 return posLeft() || idxLeft() || popLeft() || selection_;
330 bool MathCursor::right(bool sel)
335 lastcode_ = LM_TC_VAR;
339 lastcode_ = LM_TC_VAR;
341 if (hasNextAtom() && openable(nextAtom(), sel)) {
342 if (nextAtom()->isHyperActive()) {
343 lyxerr << "entering hyperactive inset\n";
346 nextAtom()->edit(formula()->view(), x, y, 0);
348 pushLeft(nextAtom());
352 return posRight() || idxRight() || popRight() || selection_;
356 void MathCursor::first()
359 pushLeft(formula_->par());
363 void MathCursor::last()
370 void MathCursor::setPos(int x, int y)
373 //lyxerr << "MathCursor::setPos x: " << x << " y: " << y << "\n";
376 lastcode_ = LM_TC_VAR;
379 cursor().par_ = &formula_->par();
384 //lyxerr << "found idx: " << idx() << " cursor: " << pos() << "\n";
385 int distmin = 1 << 30; // large enough
386 for (unsigned int i = 0; i < par()->nargs(); ++i) {
387 MathXArray const & ar = par()->xcell(i);
388 int x1 = x - ar.xo();
389 int y1 = y - ar.yo();
390 MathXArray::size_type c = ar.x2pos(x1);
391 int xx = abs(x1 - ar.pos2x(c));
393 //lyxerr << "idx: " << i << " xx: " << xx << " yy: " << yy
394 // << " c: " << c << " xo: " << ar.xo() << "\n";
395 if (yy + xx <= distmin) {
401 //lyxerr << "found idx: " << idx() << " cursor: "
403 if (hasNextAtom() && positionable(nextAtom(), x, y))
404 pushLeft(nextAtom());
405 else if (hasPrevAtom() && positionable(prevAtom(), x, y))
406 pushRight(prevAtom());
414 void MathCursor::home(bool sel)
419 lastcode_ = LM_TC_VAR;
420 if (!par()->idxHome(idx(), pos()))
426 void MathCursor::end(bool sel)
431 lastcode_ = LM_TC_VAR;
432 if (!par()->idxEnd(idx(), pos()))
438 void MathCursor::plainErase()
440 array().erase(pos());
444 void MathCursor::plainInsert(MathAtom const & t)
446 array().insert(pos(), t);
451 void MathCursor::insert(char c, MathTextCodes t)
453 //lyxerr << "inserting '" << c << "'\n";
454 plainInsert(MathAtom(new MathCharInset(c, t)));
458 void MathCursor::insert(MathAtom const & t)
473 void MathCursor::niceInsert(MathAtom const & t)
476 insert(t); // inserting invalidates the pointer!
477 MathAtom const & p = prevAtom();
480 right(); // do not push for e.g. MathSymbolInset
484 #warning "redraw disabled"
486 //p->metrics(p->size());
490 void MathCursor::insert(MathArray const & ar)
496 array().insert(pos(), ar);
501 void MathCursor::paste(MathArray const & ar)
505 array().insert(pos(), ar);
510 void MathCursor::backspace()
522 MathScriptInset * p = prevAtom()->asScriptInset();
524 p->removeScript(p->hasUp());
525 // Don't delete if there is anything left
526 if (p->hasUp() || p->hasDown())
535 void MathCursor::erase()
545 // delete empty cells if necessary
546 if (array().empty()) {
549 par()->idxDelete(idx(), popit, removeit);
550 if (popit && popLeft() && removeit)
558 MathScriptInset * p = nextAtom()->asScriptInset();
560 p->removeScript(p->hasUp());
561 // Don't delete if there is anything left
562 if (p->hasUp() || p->hasDown())
570 void MathCursor::delLine()
579 if (par()->nrows() > 1)
580 par()->delRow(row());
587 bool MathCursor::up(bool sel)
594 MathInset::idx_type i = 0;
595 MathInset::pos_type p = 0;
597 // check whether we could move into the inset
598 if (hasPrevAtom() && prevAtom()->idxLastUp(i, p)) {
599 pushRight(prevAtom());
605 if (hasNextAtom() && nextAtom()->idxFirstUp(i, p)) {
606 pushLeft(nextAtom());
613 return goUp() || selection_;
617 bool MathCursor::down(bool sel)
624 MathInset::idx_type i = 0;
625 MathInset::pos_type p = 0;
627 // check whether we could move into the inset
628 if (hasPrevAtom() && prevAtom()->idxLastDown(i, p)) {
629 pushRight(prevAtom());
635 if (hasNextAtom() && nextAtom()->idxFirstDown(i, p)) {
636 pushLeft(nextAtom());
643 return goDown() || selection_;
647 bool MathCursor::toggleLimits()
651 MathScriptInset * t = prevAtom()->asScriptInset();
654 int old = t->limits();
655 t->limits(old < 0 ? 1 : -1);
656 return old != t->limits();
660 void MathCursor::macroModeClose()
662 string s = macroName();
664 size_type old = pos();
666 array().erase(pos(), old);
672 int MathCursor::macroNamePos() const
674 for (int i = pos() - 1; i >= 0; --i) {
675 MathAtom & p = array().at(i);
676 if (p->code() == LM_TC_TEX && p->getChar() == '\\')
683 string MathCursor::macroName() const
686 for (int i = macroNamePos(); i >= 0 && i < int(pos()); ++i)
687 s += array().at(i)->getChar();
692 void MathCursor::selCopy()
696 theSelection.grab(*this);
702 void MathCursor::selCut()
706 theSelection.grab(*this);
707 theSelection.erase(*this);
710 theSelection.clear();
715 void MathCursor::selDel()
719 theSelection.erase(*this);
727 void MathCursor::selPaste()
730 theSelection.paste(*this);
731 theSelection.grab(*this);
736 void MathCursor::selHandle(bool sel)
738 if (sel == selection_)
741 theSelection.clear();
747 void MathCursor::selStart()
753 theSelection.clear();
759 void MathCursor::selClear()
766 void MathCursor::selGet(MathArray & ar)
772 theSelection.grab(*this);
773 ar = theSelection.glue();
778 void MathCursor::drawSelection(Painter & pain) const
785 getSelection(i1, i2);
786 //lyxerr << "selection from: " << i1 << " to " << i2 << "\n";
788 if (i1.idx_ == i2.idx_) {
789 MathXArray & c = i1.xcell();
790 int x1 = c.xo() + c.pos2x(i1.pos_);
791 int y1 = c.yo() - c.ascent();
792 int x2 = c.xo() + c.pos2x(i2.pos_);
793 int y2 = c.yo() + c.descent();
794 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
796 std::vector<MathInset::idx_type> indices
797 = (*i1.par_)->idxBetween(i1.idx_, i2.idx_);
798 for (unsigned i = 0; i < indices.size(); ++i) {
799 MathXArray & c = i1.xcell(indices[i]);
801 int y1 = c.yo() - c.ascent();
802 int x2 = c.xo() + c.width();
803 int y2 = c.yo() + c.descent();
804 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
809 // draw anchor if different from selection boundary
810 MathCursorPos anc = Anchor_.back();
811 if (anc != i1 && anc != i2) {
812 MathXArray & c = anc.xcell();
813 int x = c.xo() + c.pos2x(anc.pos_);
814 int y1 = c.yo() - c.ascent();
815 int y2 = c.yo() + c.descent();
816 pain.line(x, y1, x, y2, LColor::mathline);
822 void MathCursor::handleFont(MathTextCodes t)
828 getSelection(i1, i2);
829 if (i1.idx_ == i2.idx_) {
830 MathArray & ar = i1.cell();
831 for (MathInset::pos_type pos = i1.pos_; pos != i2.pos_; ++pos)
832 ar.at(pos)->handleFont(t);
835 lastcode_ = (lastcode_ == t) ? LM_TC_VAR : t;
839 void MathCursor::handleDelim(string const & l, string const & r)
841 handleNest(new MathDelimInset(l, r));
845 void MathCursor::handleNest(MathInset * p)
849 p->cell(0) = theSelection.glue();
851 insert(MathAtom(p)); // this invalidates p!
852 pushRight(prevAtom());
856 void MathCursor::getPos(int & x, int & y)
859 #warning This should probably take cellXOffset and cellYOffset into account
861 x = xarray().xo() + xarray().pos2x(pos());
866 MathAtom & MathCursor::par() const
868 return *cursor().par_;
872 InsetFormulaBase const * MathCursor::formula()
878 MathCursor::idx_type MathCursor::idx() const
880 return cursor().idx_;
884 MathCursor::idx_type & MathCursor::idx()
886 return cursor().idx_;
890 MathCursor::pos_type MathCursor::pos() const
892 return cursor().pos_;
896 MathCursor::pos_type & MathCursor::pos()
898 return cursor().pos_;
902 bool MathCursor::inMacroMode() const
904 return macroNamePos() != -1;
908 bool MathCursor::selection() const
914 MathGridInset * MathCursor::enclosingGrid(MathCursor::idx_type & idx) const
916 for (int i = Cursor_.size() - 1; i >= 0; --i) {
917 MathGridInset * p = (*Cursor_[i].par_)->asGridInset();
919 idx = Cursor_[i].idx_;
927 void MathCursor::pullArg(bool goright)
930 MathArray a = array();
932 MathScriptInset const * p = par()->asScriptInset();
934 // special handling for scripts
935 const bool up = p->hasUp();
937 MathScriptInset * q = nextAtom()->asScriptInset();
941 array().insert(pos(), a);
947 array().insert(pos(), a);
954 void MathCursor::normalize() const
957 #warning This is evil!
959 MathCursor * it = const_cast<MathCursor *>(this);
961 if (idx() >= par()->nargs()) {
962 lyxerr << "this should not really happen - 1: "
963 << idx() << " " << par()->nargs() << "\n";
966 it->idx() = min(idx(), par()->nargs() - 1);
968 if (pos() > size()) {
969 lyxerr << "this should not really happen - 2: "
970 << pos() << " " << size() << " in idx: " << it->idx()
972 WriteStream wi(0, lyxerr, false);
973 it->par()->write(wi);
977 it->pos() = min(pos(), size());
981 MathCursor::size_type MathCursor::size() const
983 return array().size();
987 MathCursor::col_type MathCursor::col() const
989 return par()->col(idx());
993 MathCursor::row_type MathCursor::row() const
995 return par()->row(idx());
999 bool MathCursor::hasPrevAtom() const
1005 bool MathCursor::hasNextAtom() const
1007 return pos() < size();
1011 MathAtom const & MathCursor::prevAtom() const
1013 lyx::Assert(pos() > 0);
1014 return array().at(pos() - 1);
1018 MathAtom & MathCursor::prevAtom()
1020 lyx::Assert(pos() > 0);
1021 return array().at(pos() - 1);
1025 MathAtom const & MathCursor::nextAtom() const
1027 lyx::Assert(pos() < size());
1028 return array().at(pos());
1032 MathAtom & MathCursor::nextAtom()
1034 lyx::Assert(pos() < size());
1035 return array().at(pos());
1039 MathArray & MathCursor::array() const
1041 static MathArray dummy;
1043 if (idx() >= par()->nargs()) {
1044 lyxerr << "############ idx_ " << idx() << " not valid\n";
1048 return cursor().cell();
1052 MathXArray & MathCursor::xarray() const
1054 return cursor().xcell();
1058 void MathCursor::idxNext()
1060 par()->idxNext(idx(), pos());
1064 void MathCursor::idxPrev()
1066 par()->idxPrev(idx(), pos());
1070 void MathCursor::splitCell()
1072 if (idx() == par()->nargs() - 1)
1074 MathArray ar = array();
1076 array().erase(pos(), size());
1079 array().insert(0, ar);
1083 void MathCursor::breakLine()
1085 // leave inner cells
1089 MathHullInset * p = formula()->par()->asHullInset();
1093 if (p->getType() == LM_OT_SIMPLE || p->getType() == LM_OT_EQUATION) {
1094 p->mutate(LM_OT_EQNARRAY);
1101 const row_type r = row();
1102 for (col_type c = col() + 1; c < p->ncols(); ++c)
1103 p->cell(p->index(r, c)).swap(p->cell(p->index(r + 1, c)));
1107 p->cell(idx()).swap(p->cell(idx() + p->ncols() - 1));
1112 void MathCursor::readLine(MathArray & ar) const
1114 idx_type base = row() * par()->ncols();
1115 for (idx_type off = 0; off < par()->ncols(); ++off)
1116 ar.push_back(par()->cell(base + off));
1120 char MathCursor::valign() const
1123 MathGridInset * p = enclosingGrid(idx);
1124 return p ? p->valign() : '\0';
1128 char MathCursor::halign() const
1131 MathGridInset * p = enclosingGrid(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 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 y0 -= xarray().ascent();
1183 for (int y = y0 - 4; y > formula()->upperY(); y -= 4) {
1185 if (save != Cursor_ && xarray().yo() < y0)
1193 bool MathCursor::goDown()
1195 // first ask the inset if it knows better then we
1196 if (par()->idxDown(idx(), pos()))
1199 // leave superscript to the nearest side
1200 MathScriptInset * p = par()->asScriptInset();
1201 if (p && idx() == 1) {
1202 if (pos() <= size() / 2)
1209 // does the inset know
1211 // if not, apply brute force.
1215 std::vector<MathCursorPos> save = Cursor_;
1216 y0 += xarray().descent();
1217 for (int y = y0 + 4; y < formula()->lowerY(); 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 bool MathCursor::interpret(string const & s)
1241 //lyxerr << "interpret 1: '" << s << "'\n";
1246 return interpret(s[0]);
1248 //lyxerr << "char: '" << s[0] << "' int: " << int(s[0]) << endl;
1249 //owner_->getIntl()->getTrans().TranslateAndInsert(s[0], lt);
1250 //lyxerr << "trans: '" << s[0] << "' int: " << int(s[0]) << endl;
1252 if (s.size() >= 5 && s.substr(0, 5) == "cases") {
1254 istringstream is(s.substr(5).c_str());
1256 n = std::max(1u, n);
1257 niceInsert(MathAtom(new MathCasesInset(n)));
1261 if (s.size() >= 6 && s.substr(0, 6) == "matrix") {
1266 istringstream is(s.substr(6).c_str());
1267 is >> m >> n >> v_align >> h_align;
1268 m = std::max(1u, m);
1269 n = std::max(1u, n);
1271 niceInsert(MathAtom(new MathArrayInset(m, n, v_align[0], h_align)));
1275 if (s == "\\over" || s == "\\choose" || s == "\\atop") {
1276 MathArray ar = array();
1277 MathAtom t = createMathInset(s.substr(1));
1278 t->asNestInset()->cell(0).swap(array());
1286 niceInsert(createMathInset(s.substr(1)));
1291 bool MathCursor::interpret(char c)
1293 //lyxerr << "interpret 2: '" << c << "'\n";
1294 if (c == '^' || c == '_') {
1296 const bool up = (c == '^');
1298 if (hasPrevAtom() && prevAtom()->asScriptInset()) {
1299 prevAtom()->asScriptInset()->ensure(up);
1300 pushRight(prevAtom());
1303 } else if (hasNextAtom() && nextAtom()->asScriptInset()) {
1304 nextAtom()->asScriptInset()->ensure(up);
1305 pushLeft(nextAtom());
1309 plainInsert(MathAtom(new MathScriptInset(up)));
1310 prevAtom()->asScriptInset()->ensure(up);
1311 pushRight(prevAtom());
1322 if (inMacroMode()) {
1323 string name = macroName();
1325 if (name == "\\" && c == '#') {
1326 insert(c, LM_TC_TEX);
1330 if (name == "\\" && c == '\\') {
1332 interpret("\\backslash");
1336 if (name == "\\#" && '1' <= c && c <= '9') {
1337 insert(c, LM_TC_TEX);
1343 insert(c, LM_TC_TEX);
1348 insert(c, LM_TC_TEX);
1360 if (lastcode_ == LM_TC_TEXTRM) {
1361 // suppress direct insertion of to spaces in a row
1362 // the still allows typing '<space>a<space>' and deleting the 'a', but
1363 // it is better than nothing
1364 if (c == ' ' && hasPrevAtom() && prevAtom()->getChar() == ' ')
1366 insert(c, LM_TC_TEXTRM);
1371 if (hasPrevAtom() && prevAtom()->asSpaceInset()) {
1372 prevAtom()->asSpaceInset()->incSpace();
1376 if (mathcursor->popRight())
1379 // if are at the very end, leave the formula
1380 return pos() != size();
1384 if (strchr("{}", c)) {
1385 insert(c, LM_TC_TEX);
1391 niceInsert(MathAtom(new MathBraceInset));
1399 if (strchr("#$%", c)) {
1400 insert(MathAtom(new MathSpecialCharInset(c)));
1401 lastcode_ = LM_TC_VAR;
1405 if (isalpha(c) && lastcode_ == LM_TC_GREEK) {
1406 insert(c, LM_TC_VAR);
1410 if (isalpha(c) && lastcode_ == LM_TC_GREEK1) {
1411 insert(c, LM_TC_VAR);
1412 lastcode_ = LM_TC_VAR;
1417 insert(c, LM_TC_TEX);
1418 //bv->owner()->message(_("TeX mode"));
1422 // no special circumstances, so insert the character without any fuss
1423 insert(c, LM_TC_MIN);
1429 ////////////////////////////////////////////////////////////////////////
1432 bool operator==(MathCursorPos const & ti, MathCursorPos const & it)
1434 return ti.par_ == it.par_ && ti.idx_ == it.idx_ && ti.pos_ == it.pos_;
1438 bool operator<(MathCursorPos const & ti, MathCursorPos const & it)
1440 if (ti.par_ != it.par_) {
1441 lyxerr << "can't compare cursor and anchor in different insets\n";
1444 if (ti.idx_ != it.idx_)
1445 return ti.idx_ < it.idx_;
1446 return ti.pos_ < it.pos_;
1450 MathArray & MathCursorPos::cell(MathCursor::idx_type idx) const
1452 return (*par_)->cell(idx);
1456 MathArray & MathCursorPos::cell() const
1458 return (*par_)->cell(idx_);
1462 MathXArray & MathCursorPos::xcell(MathCursor::idx_type idx) const
1464 return (*par_)->xcell(idx);
1468 MathXArray & MathCursorPos::xcell() const
1470 return (*par_)->xcell(idx_);
1474 MathCursorPos MathCursor::normalAnchor() const
1476 // use Anchor on the same level as Cursor
1477 MathCursorPos normal = Anchor_[Cursor_.size() - 1];
1478 if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) {
1479 // anchor is behind cursor -> move anchor behind the inset
1486 void MathCursor::stripFromLastEqualSign()
1488 // find position of last '=' in the array
1489 MathArray & ar = cursor().cell();
1490 MathArray::const_iterator et = ar.end();
1491 for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it)
1492 if ((*it)->getChar() == '=')
1495 // delete everything behind this position
1496 ar.erase(et - ar.begin(), ar.size());