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"
42 #include "math_parser.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)
135 //cerr << "Entering atom "; t->write(cerr, false); cerr << " left\n";
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()
288 bool MathCursor::posRight()
299 bool MathCursor::left(bool sel)
304 lastcode_ = LM_TC_VAR;
308 lastcode_ = LM_TC_VAR;
310 if (hasPrevAtom() && openable(prevAtom(), sel)) {
311 pushRight(prevAtom());
315 return posLeft() || idxLeft() || popLeft();
319 bool MathCursor::right(bool sel)
324 lastcode_ = LM_TC_VAR;
328 lastcode_ = LM_TC_VAR;
330 if (hasNextAtom() && openable(nextAtom(), sel)) {
331 pushLeft(nextAtom());
335 return posRight() || idxRight() || popRight();
339 void MathCursor::first()
342 pushLeft(formula_->par());
346 void MathCursor::last()
353 void MathCursor::setPos(int x, int y)
356 //lyxerr << "MathCursor::setPos x: " << x << " y: " << y << "\n";
359 lastcode_ = LM_TC_VAR;
362 cursor().par_ = &formula_->par();
367 //lyxerr << "found idx: " << idx() << " cursor: " << pos() << "\n";
368 int distmin = 1 << 30; // large enough
369 for (unsigned int i = 0; i < par()->nargs(); ++i) {
370 MathXArray const & ar = par()->xcell(i);
371 int x1 = x - ar.xo();
372 int y1 = y - ar.yo();
373 MathXArray::size_type c = ar.x2pos(x1);
374 int xx = abs(x1 - ar.pos2x(c));
376 //lyxerr << "idx: " << i << " xx: " << xx << " yy: " << yy
377 // << " c: " << c << " xo: " << ar.xo() << "\n";
378 if (yy + xx <= distmin) {
384 //lyxerr << "found idx: " << idx() << " cursor: "
386 if (hasNextAtom() && positionable(nextAtom(), x, y))
387 pushLeft(nextAtom());
388 else if (hasPrevAtom() && positionable(prevAtom(), x, y))
389 pushRight(prevAtom());
397 void MathCursor::home(bool sel)
402 lastcode_ = LM_TC_VAR;
403 if (!par()->idxHome(idx(), pos()))
409 void MathCursor::end(bool sel)
414 lastcode_ = LM_TC_VAR;
415 if (!par()->idxEnd(idx(), pos()))
421 void MathCursor::plainErase()
423 array().erase(pos());
427 void MathCursor::plainInsert(MathAtom const & t)
429 array().insert(pos(), t);
434 void MathCursor::insert(char c, MathTextCodes t)
436 //lyxerr << "inserting '" << c << "'\n";
437 plainInsert(MathAtom(new MathCharInset(c, t)));
441 void MathCursor::insert(MathAtom const & t)
456 void MathCursor::niceInsert(MathAtom const & t)
459 insert(t); // inserting invalidates the pointer!
460 MathAtom const & p = prevAtom();
463 right(); // do not push for e.g. MathSymbolInset
466 p->metrics(p->size());
470 void MathCursor::insert(MathArray const & ar)
476 array().insert(pos(), ar);
481 void MathCursor::paste(MathArray const & ar)
485 array().insert(pos(), ar);
490 void MathCursor::backspace()
502 MathScriptInset * p = prevAtom()->asScriptInset();
504 p->removeScript(p->hasUp());
505 // Don't delete if there is anything left
506 if (p->hasUp() || p->hasDown())
515 void MathCursor::erase()
525 // delete empty cells if necessary
526 if (array().empty()) {
529 par()->idxDelete(idx(), popit, removeit);
530 if (popit && popLeft() && removeit)
538 MathScriptInset * p = nextAtom()->asScriptInset();
540 p->removeScript(p->hasUp());
541 // Don't delete if there is anything left
542 if (p->hasUp() || p->hasDown())
550 void MathCursor::delLine()
559 if (par()->nrows() > 1)
560 par()->delRow(row());
564 bool MathCursor::up(bool sel)
571 // check whether we could move into a superscript
573 MathAtom & p = prevAtom();
574 if (p->asScriptInset() && p->asScriptInset()->hasUp()) {
582 MathAtom & n = nextAtom();
583 if (n->asScriptInset() && n->asScriptInset()->hasUp()) {
595 bool MathCursor::down(bool sel)
602 // check whether we could move into a subscript
604 MathAtom & p = prevAtom();
605 if (p->asScriptInset() && p->asScriptInset()->hasDown()) {
613 MathAtom & n = nextAtom();
614 if (n->asScriptInset() && n->asScriptInset()->hasDown()) {
626 bool MathCursor::toggleLimits()
630 MathScriptInset * t = prevAtom()->asScriptInset();
633 int old = t->limits();
634 t->limits(old < 0 ? 1 : -1);
635 return old != t->limits();
639 void MathCursor::setSize(MathStyles size)
641 par()->userSetSize(size);
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);
710 void MathCursor::selPaste()
713 theSelection.paste(*this);
714 theSelection.grab(*this);
719 void MathCursor::selHandle(bool sel)
721 if (sel == selection_)
724 theSelection.clear();
730 void MathCursor::selStart()
736 theSelection.clear();
742 void MathCursor::selClear()
749 void MathCursor::drawSelection(Painter & pain) const
756 getSelection(i1, i2);
758 //lyxerr << "selection from: " << i1 << " to " << i2 << "\n";
760 if (i1.idx_ == i2.idx_) {
761 MathXArray & c = i1.xcell();
762 int x1 = c.xo() + c.pos2x(i1.pos_);
763 int y1 = c.yo() - c.ascent();
764 int x2 = c.xo() + c.pos2x(i2.pos_);
765 int y2 = c.yo() + c.descent();
766 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
768 std::vector<MathInset::idx_type> indices
769 = (*i1.par_)->idxBetween(i1.idx_, i2.idx_);
770 for (unsigned i = 0; i < indices.size(); ++i) {
771 MathXArray & c = i1.xcell(indices[i]);
773 int y1 = c.yo() - c.ascent();
774 int x2 = c.xo() + c.width();
775 int y2 = c.yo() + c.descent();
776 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
782 void MathCursor::handleFont(MathTextCodes t)
788 getSelection(i1, i2);
789 if (i1.idx_ == i2.idx_) {
790 MathArray & ar = i1.cell();
791 for (MathInset::pos_type pos = i1.pos_; pos != i2.pos_; ++pos)
792 ar.at(pos)->handleFont(t);
795 lastcode_ = (lastcode_ == t) ? LM_TC_VAR : t;
799 void MathCursor::handleDelim(string const & l, string const & r)
801 handleNest(new MathDelimInset(l, r));
805 void MathCursor::handleNest(MathInset * p)
809 p->cell(0) = theSelection.glue();
811 insert(MathAtom(p)); // this invalidates p!
812 pushRight(prevAtom());
816 void MathCursor::getPos(int & x, int & y)
819 #warning This should probably take cellXOffset and cellYOffset into account
821 x = xarray().xo() + xarray().pos2x(pos());
826 MathAtom & MathCursor::par() const
828 return *cursor().par_;
832 InsetFormulaBase const * MathCursor::formula()
838 MathCursor::idx_type MathCursor::idx() const
840 return cursor().idx_;
844 MathCursor::idx_type & MathCursor::idx()
846 return cursor().idx_;
850 MathCursor::pos_type MathCursor::pos() const
852 return cursor().pos_;
856 MathCursor::pos_type & MathCursor::pos()
858 return cursor().pos_;
862 bool MathCursor::inMacroMode() const
864 return macroNamePos() != -1;
868 bool MathCursor::selection() const
874 MathArrayInset * MathCursor::enclosingArray(MathCursor::idx_type & idx) const
876 for (int i = Cursor_.size() - 1; i >= 0; --i) {
877 MathArrayInset * p = (*Cursor_[i].par_)->asArrayInset();
879 idx = Cursor_[i].idx_;
887 void MathCursor::pullArg(bool goright)
890 MathArray a = array();
892 MathScriptInset const * p = par()->asScriptInset();
894 // special handling for scripts
895 const bool up = p->hasUp();
897 MathScriptInset * q = nextAtom()->asScriptInset();
901 array().insert(pos(), a);
907 array().insert(pos(), a);
914 MathStyles MathCursor::style() const
916 return xarray().style();
920 void MathCursor::normalize() const
923 #warning This is evil!
925 MathCursor * it = const_cast<MathCursor *>(this);
927 if (idx() >= par()->nargs()) {
928 lyxerr << "this should not really happen - 1: "
929 << idx() << " " << par()->nargs() << "\n";
932 it->idx() = min(idx(), par()->nargs() - 1);
934 if (pos() > size()) {
935 lyxerr << "this should not really happen - 2: "
936 << pos() << " " << size() << "\n";
939 it->pos() = min(pos(), size());
943 MathCursor::size_type MathCursor::size() const
945 return array().size();
949 MathCursor::col_type MathCursor::col() const
951 return par()->col(idx());
955 MathCursor::row_type MathCursor::row() const
957 return par()->row(idx());
961 bool MathCursor::hasPrevAtom() const
967 bool MathCursor::hasNextAtom() const
969 return pos() < size();
973 MathAtom const & MathCursor::prevAtom() const
975 lyx::Assert(pos() > 0);
976 return array().at(pos() - 1);
980 MathAtom & MathCursor::prevAtom()
982 lyx::Assert(pos() > 0);
983 return array().at(pos() - 1);
987 MathAtom const & MathCursor::nextAtom() const
989 lyx::Assert(pos() < size());
990 return array().at(pos());
994 MathAtom & MathCursor::nextAtom()
996 lyx::Assert(pos() < size());
997 return array().at(pos());
1001 MathArray & MathCursor::array() const
1003 static MathArray dummy;
1005 if (idx() >= par()->nargs()) {
1006 lyxerr << "############ idx_ " << idx() << " not valid\n";
1010 return cursor().cell();
1014 MathXArray & MathCursor::xarray() const
1016 return cursor().xcell();
1020 void MathCursor::idxNext()
1022 par()->idxNext(idx(), pos());
1026 void MathCursor::idxPrev()
1028 par()->idxPrev(idx(), pos());
1032 void MathCursor::splitCell()
1034 if (idx() == par()->nargs() - 1)
1036 MathArray ar = array();
1038 array().erase(pos(), size());
1041 array().insert(0, ar);
1045 void MathCursor::breakLine()
1047 // leave inner cells
1051 MathMatrixInset * p = formula()->par()->asMatrixInset();
1055 if (p->getType() == LM_OT_SIMPLE || p->getType() == LM_OT_EQUATION) {
1056 p->mutate(LM_OT_EQNARRAY);
1063 const row_type r = row();
1064 for (col_type c = col() + 1; c < p->ncols(); ++c) {
1065 const MathMatrixInset::idx_type i1 = p->index(r, c);
1066 const MathMatrixInset::idx_type i2 = p->index(r + 1, c);
1067 lyxerr << "swapping cells " << i1 << " and " << i2 << "\n";
1068 p->cell(i1).swap(p->cell(i2));
1073 p->cell(idx()).swap(p->cell(idx() + p->ncols() - 1));
1078 char MathCursor::valign() const
1081 MathArrayInset * p = enclosingArray(idx);
1082 return p ? p->valign() : '\0';
1086 char MathCursor::halign() const
1089 MathArrayInset * p = enclosingArray(idx);
1090 return p ? p->halign(idx % p->ncols()) : '\0';
1094 void MathCursor::getSelection(MathCursorPos & i1, MathCursorPos & i2) const
1096 MathCursorPos anc = normalAnchor();
1097 if (anc < cursor()) {
1107 MathCursorPos & MathCursor::cursor()
1109 return Cursor_.back();
1113 MathCursorPos const & MathCursor::cursor() const
1115 return Cursor_.back();
1119 int MathCursor::cellXOffset() const
1121 return par()->cellXOffset(idx());
1125 int MathCursor::cellYOffset() const
1127 return par()->cellYOffset(idx());
1131 int MathCursor::xpos() const
1133 return cellXOffset() + xarray().pos2x(pos());
1137 int MathCursor::ypos() const
1139 return cellYOffset();
1144 void MathCursor::gotoX(int x)
1146 pos() = xarray().x2pos(x - cellXOffset());
1150 bool MathCursor::goUp()
1152 // first ask the inset if it knows better then we
1153 if (par()->idxUp(idx(), pos()))
1156 // leave subscript to the nearest side
1157 MathScriptInset * p = par()->asScriptInset();
1158 if (p && p->hasDown()) {
1159 if (pos() <= size() / 2)
1166 // if not, apply brute force.
1170 std::vector<MathCursorPos> save = Cursor_;
1171 MathAtom const & out = formula()->par();
1172 y0 -= xarray().ascent();
1173 for (int y = y0 - 4; y > out->yo() - out->ascent(); y -= 4) {
1175 if (save != Cursor_ && xarray().yo() < y0)
1183 bool MathCursor::goDown()
1185 // first ask the inset if it knows better then we
1186 if (par()->idxDown(idx(), pos()))
1189 // leave superscript to the nearest side
1190 MathScriptInset * p = par()->asScriptInset();
1191 if (p && p->hasUp()) {
1192 if (pos() <= size() / 2)
1199 // if not, apply brute force.
1203 std::vector<MathCursorPos> save = Cursor_;
1204 MathAtom const & out = formula()->par();
1205 y0 += xarray().descent();
1206 for (int y = y0 + 4; y < out->yo() + out->descent(); y += 4) {
1208 if (save != Cursor_ && xarray().yo() > y0)
1216 bool MathCursor::idxLeft()
1218 return par()->idxLeft(idx(), pos());
1222 bool MathCursor::idxRight()
1224 return par()->idxRight(idx(), pos());
1228 void MathCursor::interpret(string const & s)
1230 //lyxerr << "interpret 1: '" << s << "'\n";
1231 //lyxerr << "in: " << in_word_set(s) << " \n";
1236 if (s.size() == 1) {
1241 //lyxerr << "char: '" << s[0] << "' int: " << int(s[0]) << endl;
1242 //owner_->getIntl()->getTrans().TranslateAndInsert(s[0], lt);
1243 //lyxerr << "trans: '" << s[0] << "' int: " << int(s[0]) << endl;
1245 if (s.size() > 7 && s.substr(0, 7) == "matrix ") {
1250 istringstream is(s.substr(7).c_str());
1251 is >> m >> n >> v_align >> h_align;
1252 m = std::max(1u, m);
1253 n = std::max(1u, n);
1255 niceInsert(MathAtom(new MathArrayInset(m, n, v_align[0], h_align)));
1259 if (s == "\\over" || s == "\\choose" || s == "\\atop") {
1260 MathArray ar = array();
1261 MathAtom t = createMathInset(s.substr(1));
1262 t->asNestInset()->cell(0).swap(array());
1270 niceInsert(createMathInset(s.substr(1)));
1274 void MathCursor::interpret(char c)
1276 //lyxerr << "interpret 2: '" << c << "'\n";
1278 if (inMacroMode()) {
1279 string name = macroName();
1281 if (name == "\\" && c == '#') {
1282 insert(c, LM_TC_TEX);
1286 if (name == "\\" && c == '\\') {
1288 interpret("\\backslash");
1292 if (name == "\\#" && '1' <= c && c <= '9') {
1293 insert(c, LM_TC_TEX);
1299 insert(c, LM_TC_TEX);
1304 insert(c, LM_TC_TEX);
1314 if (c == '^' || c == '_') {
1315 const bool up = (c == '^');
1317 if (hasPrevAtom() && prevAtom()->asScriptInset()) {
1318 prevAtom()->asScriptInset()->ensure(up);
1319 pushRight(prevAtom());
1321 } else if (hasNextAtom() && nextAtom()->asScriptInset()) {
1322 nextAtom()->asScriptInset()->ensure(up);
1323 pushLeft(nextAtom());
1326 plainInsert(MathAtom(new MathScriptInset(up)));
1327 pushRight(prevAtom());
1337 if (lastcode_ == LM_TC_TEXTRM) {
1338 insert(c, LM_TC_TEXTRM);
1343 if (hasPrevAtom() && prevAtom()->asSpaceInset()) {
1344 prevAtom()->asSpaceInset()->incSpace();
1348 if (mathcursor->popRight())
1352 // this would not work if the inset is in an table!
1353 //bv->text->cursorRight(bv, true);
1354 //result = FINISHED;
1358 if (strchr("{}", c)) {
1359 insert(c, LM_TC_TEX);
1363 if (strchr("#$%", c)) {
1364 insert(MathAtom(new MathSpecialCharInset(c)));
1365 lastcode_ = LM_TC_VAR;
1369 if (isalpha(c) && (lastcode_ == LM_TC_GREEK || lastcode_ == LM_TC_GREEK1)) {
1370 static char const greekl[][26] =
1371 {"alpha", "beta", "chi", "delta", "epsilon", "phi",
1372 "gamma", "eta", "iota", "iota", "kappa", "lambda", "mu",
1373 "nu", "omikron", "pi", "omega", "rho", "sigma",
1374 "tau", "upsilon", "theta", "omega", "xi", "upsilon", "zeta"};
1375 static char const greeku[][26] =
1376 {"Alpha", "Beta", "Chi", "Delta", "Epsilon", "Phi",
1377 "Gamma", "Eta", "Iota", "Iota", "Kappa", "Lambda", "Mu",
1378 "Nu", "Omikron", "Pi", "Omega", "Rho", "Sigma", "Tau",
1379 "Upsilon", "Theta", "Omega", "xi", "Upsilon", "Zeta"};
1381 latexkeys const * l = 0;
1382 if ('a' <= c && c <= 'z')
1383 l = in_word_set(greekl[c - 'a']);
1384 if ('A' <= c && c <= 'Z')
1385 l = in_word_set(greeku[c - 'A']);
1388 insert(createMathInset(l));
1390 insert(c, LM_TC_VAR);
1392 #warning greek insert problem? look here!
1393 if (lastcode_ == LM_TC_GREEK1)
1394 lastcode_ = LM_TC_VAR;
1399 insert(c, LM_TC_TEX);
1400 //bv->owner()->message(_("TeX mode"));
1404 // no special circumstances, so insert the character without any fuss
1405 insert(c, LM_TC_MIN);
1410 ////////////////////////////////////////////////////////////////////////
1413 bool operator==(MathCursorPos const & ti, MathCursorPos const & it)
1415 return ti.par_ == it.par_ && ti.idx_ == it.idx_ && ti.pos_ == it.pos_;
1419 bool operator<(MathCursorPos const & ti, MathCursorPos const & it)
1421 if (ti.par_ != it.par_) {
1422 lyxerr << "can't compare cursor and anchor in different insets\n";
1425 if (ti.idx_ != it.idx_)
1426 return ti.idx_ < it.idx_;
1427 return ti.pos_ < it.pos_;
1431 MathArray & MathCursorPos::cell(MathCursor::idx_type idx) const
1433 return (*par_)->cell(idx);
1437 MathArray & MathCursorPos::cell() const
1439 return (*par_)->cell(idx_);
1443 MathXArray & MathCursorPos::xcell(MathCursor::idx_type idx) const
1445 return (*par_)->xcell(idx);
1449 MathXArray & MathCursorPos::xcell() const
1451 return (*par_)->xcell(idx_);
1455 MathCursorPos MathCursor::normalAnchor() const
1457 // use Anchor on the same level as Cursor
1458 MathCursorPos normal = Anchor_[Cursor_.size() - 1];
1459 if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) {
1460 // anchor is behind cursor -> move anchor behind the inset