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()) {
583 MathAtom & n = nextAtom();
584 if (n->asScriptInset() && n->asScriptInset()->hasUp()) {
597 bool MathCursor::down(bool sel)
604 // check whether we could move into a subscript
606 MathAtom & p = prevAtom();
607 if (p->asScriptInset() && p->asScriptInset()->hasDown()) {
616 MathAtom & n = nextAtom();
617 if (n->asScriptInset() && n->asScriptInset()->hasDown()) {
630 bool MathCursor::toggleLimits()
634 MathScriptInset * t = prevAtom()->asScriptInset();
637 int old = t->limits();
638 t->limits(old < 0 ? 1 : -1);
639 return old != t->limits();
643 void MathCursor::setSize(MathStyles size)
645 par()->userSetSize(size);
649 void MathCursor::macroModeClose()
651 string s = macroName();
653 size_type old = pos();
655 array().erase(pos(), old);
661 int MathCursor::macroNamePos() const
663 for (int i = pos() - 1; i >= 0; --i) {
664 MathAtom & p = array().at(i);
665 if (p->code() == LM_TC_TEX && p->getChar() == '\\')
672 string MathCursor::macroName() const
675 for (int i = macroNamePos(); i >= 0 && i < int(pos()); ++i)
676 s += array().at(i)->getChar();
681 void MathCursor::selCopy()
685 theSelection.grab(*this);
691 void MathCursor::selCut()
695 theSelection.grab(*this);
696 theSelection.erase(*this);
699 theSelection.clear();
704 void MathCursor::selDel()
708 theSelection.erase(*this);
714 void MathCursor::selPaste()
717 theSelection.paste(*this);
718 theSelection.grab(*this);
723 void MathCursor::selHandle(bool sel)
725 if (sel == selection_)
728 theSelection.clear();
734 void MathCursor::selStart()
740 theSelection.clear();
746 void MathCursor::selClear()
753 void MathCursor::drawSelection(Painter & pain) const
760 getSelection(i1, i2);
762 //lyxerr << "selection from: " << i1 << " to " << i2 << "\n";
764 if (i1.idx_ == i2.idx_) {
765 MathXArray & c = i1.xcell();
766 int x1 = c.xo() + c.pos2x(i1.pos_);
767 int y1 = c.yo() - c.ascent();
768 int x2 = c.xo() + c.pos2x(i2.pos_);
769 int y2 = c.yo() + c.descent();
770 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
772 std::vector<MathInset::idx_type> indices
773 = (*i1.par_)->idxBetween(i1.idx_, i2.idx_);
774 for (unsigned i = 0; i < indices.size(); ++i) {
775 MathXArray & c = i1.xcell(indices[i]);
777 int y1 = c.yo() - c.ascent();
778 int x2 = c.xo() + c.width();
779 int y2 = c.yo() + c.descent();
780 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
786 void MathCursor::handleFont(MathTextCodes t)
792 getSelection(i1, i2);
793 if (i1.idx_ == i2.idx_) {
794 MathArray & ar = i1.cell();
795 for (MathInset::pos_type pos = i1.pos_; pos != i2.pos_; ++pos)
796 ar.at(pos)->handleFont(t);
799 lastcode_ = (lastcode_ == t) ? LM_TC_VAR : t;
803 void MathCursor::handleDelim(string const & l, string const & r)
805 handleNest(new MathDelimInset(l, r));
809 void MathCursor::handleNest(MathInset * p)
813 p->cell(0) = theSelection.glue();
815 insert(MathAtom(p)); // this invalidates p!
816 pushRight(prevAtom());
820 void MathCursor::getPos(int & x, int & y)
823 #warning This should probably take cellXOffset and cellYOffset into account
825 x = xarray().xo() + xarray().pos2x(pos());
830 MathAtom & MathCursor::par() const
832 return *cursor().par_;
836 InsetFormulaBase const * MathCursor::formula()
842 MathCursor::idx_type MathCursor::idx() const
844 return cursor().idx_;
848 MathCursor::idx_type & MathCursor::idx()
850 return cursor().idx_;
854 MathCursor::pos_type MathCursor::pos() const
856 return cursor().pos_;
860 MathCursor::pos_type & MathCursor::pos()
862 return cursor().pos_;
866 bool MathCursor::inMacroMode() const
868 return macroNamePos() != -1;
872 bool MathCursor::selection() const
878 MathArrayInset * MathCursor::enclosingArray(MathCursor::idx_type & idx) const
880 for (int i = Cursor_.size() - 1; i >= 0; --i) {
881 MathArrayInset * p = (*Cursor_[i].par_)->asArrayInset();
883 idx = Cursor_[i].idx_;
891 void MathCursor::pullArg(bool goright)
894 MathArray a = array();
896 MathScriptInset const * p = par()->asScriptInset();
898 // special handling for scripts
899 const bool up = p->hasUp();
901 MathScriptInset * q = nextAtom()->asScriptInset();
905 array().insert(pos(), a);
911 array().insert(pos(), a);
918 MathStyles MathCursor::style() const
920 return xarray().style();
924 void MathCursor::normalize() const
927 #warning This is evil!
929 MathCursor * it = const_cast<MathCursor *>(this);
931 if (idx() >= par()->nargs()) {
932 lyxerr << "this should not really happen - 1: "
933 << idx() << " " << par()->nargs() << "\n";
936 it->idx() = min(idx(), par()->nargs() - 1);
938 if (pos() > size()) {
939 lyxerr << "this should not really happen - 2: "
940 << pos() << " " << size() << "\n";
943 it->pos() = min(pos(), size());
947 MathCursor::size_type MathCursor::size() const
949 return array().size();
953 MathCursor::col_type MathCursor::col() const
955 return par()->col(idx());
959 MathCursor::row_type MathCursor::row() const
961 return par()->row(idx());
965 bool MathCursor::hasPrevAtom() const
971 bool MathCursor::hasNextAtom() const
973 return pos() < size();
977 MathAtom const & MathCursor::prevAtom() const
979 lyx::Assert(pos() > 0);
980 return array().at(pos() - 1);
984 MathAtom & MathCursor::prevAtom()
986 lyx::Assert(pos() > 0);
987 return array().at(pos() - 1);
991 MathAtom const & MathCursor::nextAtom() const
993 lyx::Assert(pos() < size());
994 return array().at(pos());
998 MathAtom & MathCursor::nextAtom()
1000 lyx::Assert(pos() < size());
1001 return array().at(pos());
1005 MathArray & MathCursor::array() const
1007 static MathArray dummy;
1009 if (idx() >= par()->nargs()) {
1010 lyxerr << "############ idx_ " << idx() << " not valid\n";
1014 return cursor().cell();
1018 MathXArray & MathCursor::xarray() const
1020 return cursor().xcell();
1024 void MathCursor::idxNext()
1026 par()->idxNext(idx(), pos());
1030 void MathCursor::idxPrev()
1032 par()->idxPrev(idx(), pos());
1036 void MathCursor::splitCell()
1038 if (idx() == par()->nargs() - 1)
1040 MathArray ar = array();
1042 array().erase(pos(), size());
1045 array().insert(0, ar);
1049 void MathCursor::breakLine()
1051 // leave inner cells
1055 MathMatrixInset * p = formula()->par()->asMatrixInset();
1059 if (p->getType() == LM_OT_SIMPLE || p->getType() == LM_OT_EQUATION) {
1060 p->mutate(LM_OT_EQNARRAY);
1067 const row_type r = row();
1068 for (col_type c = col() + 1; c < p->ncols(); ++c) {
1069 const MathMatrixInset::idx_type i1 = p->index(r, c);
1070 const MathMatrixInset::idx_type i2 = p->index(r + 1, c);
1071 lyxerr << "swapping cells " << i1 << " and " << i2 << "\n";
1072 p->cell(i1).swap(p->cell(i2));
1077 p->cell(idx()).swap(p->cell(idx() + p->ncols() - 1));
1082 char MathCursor::valign() const
1085 MathArrayInset * p = enclosingArray(idx);
1086 return p ? p->valign() : '\0';
1090 char MathCursor::halign() const
1093 MathArrayInset * p = enclosingArray(idx);
1094 return p ? p->halign(idx % p->ncols()) : '\0';
1098 void MathCursor::getSelection(MathCursorPos & i1, MathCursorPos & i2) const
1100 MathCursorPos anc = normalAnchor();
1101 if (anc < cursor()) {
1111 MathCursorPos & MathCursor::cursor()
1113 return Cursor_.back();
1117 MathCursorPos const & MathCursor::cursor() const
1119 return Cursor_.back();
1123 int MathCursor::cellXOffset() const
1125 return par()->cellXOffset(idx());
1129 int MathCursor::cellYOffset() const
1131 return par()->cellYOffset(idx());
1135 int MathCursor::xpos() const
1137 return cellXOffset() + xarray().pos2x(pos());
1141 int MathCursor::ypos() const
1143 return cellYOffset();
1148 void MathCursor::gotoX(int x)
1150 pos() = xarray().x2pos(x - cellXOffset());
1154 bool MathCursor::goUp()
1156 // first ask the inset if it knows better then we
1157 if (par()->idxUp(idx(), pos()))
1160 // leave subscript to the nearest side
1161 MathScriptInset * p = par()->asScriptInset();
1162 if (p && p->hasDown()) {
1163 if (pos() <= size() / 2)
1170 // if not, apply brute force.
1174 std::vector<MathCursorPos> save = Cursor_;
1175 MathAtom const & out = formula()->par();
1176 y0 -= xarray().ascent();
1177 for (int y = y0 - 4; y > out->yo() - out->ascent(); y -= 4) {
1179 if (save != Cursor_ && xarray().yo() < y0)
1187 bool MathCursor::goDown()
1189 // first ask the inset if it knows better then we
1190 if (par()->idxDown(idx(), pos()))
1193 // leave superscript to the nearest side
1194 MathScriptInset * p = par()->asScriptInset();
1195 if (p && p->hasUp()) {
1196 if (pos() <= size() / 2)
1203 // if not, apply brute force.
1207 std::vector<MathCursorPos> save = Cursor_;
1208 MathAtom const & out = formula()->par();
1209 y0 += xarray().descent();
1210 for (int y = y0 + 4; y < out->yo() + out->descent(); y += 4) {
1212 if (save != Cursor_ && xarray().yo() > y0)
1220 bool MathCursor::idxLeft()
1222 return par()->idxLeft(idx(), pos());
1226 bool MathCursor::idxRight()
1228 return par()->idxRight(idx(), pos());
1232 void MathCursor::interpret(string const & s)
1234 //lyxerr << "interpret 1: '" << s << "'\n";
1235 //lyxerr << "in: " << in_word_set(s) << " \n";
1240 if (s.size() == 1) {
1245 //lyxerr << "char: '" << s[0] << "' int: " << int(s[0]) << endl;
1246 //owner_->getIntl()->getTrans().TranslateAndInsert(s[0], lt);
1247 //lyxerr << "trans: '" << s[0] << "' int: " << int(s[0]) << endl;
1249 if (s.size() > 7 && s.substr(0, 7) == "matrix ") {
1254 istringstream is(s.substr(7).c_str());
1255 is >> m >> n >> v_align >> h_align;
1256 m = std::max(1u, m);
1257 n = std::max(1u, n);
1259 niceInsert(MathAtom(new MathArrayInset(m, n, v_align[0], h_align)));
1263 if (s == "\\over" || s == "\\choose" || s == "\\atop") {
1264 MathArray ar = array();
1265 MathAtom t = createMathInset(s.substr(1));
1266 t->asNestInset()->cell(0).swap(array());
1274 niceInsert(createMathInset(s.substr(1)));
1278 void MathCursor::interpret(char c)
1280 //lyxerr << "interpret 2: '" << c << "'\n";
1282 if (inMacroMode()) {
1283 string name = macroName();
1285 if (name == "\\" && c == '#') {
1286 insert(c, LM_TC_TEX);
1290 if (name == "\\" && c == '\\') {
1292 interpret("\\backslash");
1296 if (name == "\\#" && '1' <= c && c <= '9') {
1297 insert(c, LM_TC_TEX);
1303 insert(c, LM_TC_TEX);
1308 insert(c, LM_TC_TEX);
1318 if (c == '^' || c == '_') {
1319 const bool up = (c == '^');
1321 if (hasPrevAtom() && prevAtom()->asScriptInset()) {
1322 prevAtom()->asScriptInset()->ensure(up);
1323 pushRight(prevAtom());
1325 } else if (hasNextAtom() && nextAtom()->asScriptInset()) {
1326 nextAtom()->asScriptInset()->ensure(up);
1327 pushLeft(nextAtom());
1330 plainInsert(MathAtom(new MathScriptInset(up)));
1331 pushRight(prevAtom());
1341 if (lastcode_ == LM_TC_TEXTRM) {
1342 insert(c, LM_TC_TEXTRM);
1347 if (hasPrevAtom() && prevAtom()->asSpaceInset()) {
1348 prevAtom()->asSpaceInset()->incSpace();
1352 if (mathcursor->popRight())
1356 // this would not work if the inset is in an table!
1357 //bv->text->cursorRight(bv, true);
1358 //result = FINISHED;
1362 if (strchr("{}", c)) {
1363 insert(c, LM_TC_TEX);
1367 if (strchr("#$%", c)) {
1368 insert(MathAtom(new MathSpecialCharInset(c)));
1369 lastcode_ = LM_TC_VAR;
1373 if (isalpha(c) && (lastcode_ == LM_TC_GREEK || lastcode_ == LM_TC_GREEK1)) {
1374 static char const greekl[][26] =
1375 {"alpha", "beta", "chi", "delta", "epsilon", "phi",
1376 "gamma", "eta", "iota", "epsilon", "kappa", "lambda", "mu",
1377 "nu", "omikron", "pi", "vartheta", "rho", "sigma",
1378 "tau", "upsilon", "theta", "omega", "xi", "varphi", "zeta"};
1379 static char const greeku[][26] =
1380 {"Alpha", "Beta", "chi", "Delta", "varepsilon", "Phi",
1381 "Gamma", "Eta", "Iota", "Epsilon", "Kappa", "Lambda", "Mu",
1382 "Nu", "Omikron", "Pi", "vartheta", "varrho", "Sigma", "varsigma",
1383 "Upsilon", "Theta", "Omega", "Xi", "Varphi", "Zeta"};
1385 latexkeys const * l = 0;
1386 if ('a' <= c && c <= 'z')
1387 l = in_word_set(greekl[c - 'a']);
1388 if ('A' <= c && c <= 'Z')
1389 l = in_word_set(greeku[c - 'A']);
1392 insert(createMathInset(l));
1394 insert(c, LM_TC_VAR);
1396 #warning greek insert problem? look here!
1397 if (lastcode_ == LM_TC_GREEK1)
1398 lastcode_ = LM_TC_VAR;
1403 insert(c, LM_TC_TEX);
1404 //bv->owner()->message(_("TeX mode"));
1408 // no special circumstances, so insert the character without any fuss
1409 insert(c, LM_TC_MIN);
1414 ////////////////////////////////////////////////////////////////////////
1417 bool operator==(MathCursorPos const & ti, MathCursorPos const & it)
1419 return ti.par_ == it.par_ && ti.idx_ == it.idx_ && ti.pos_ == it.pos_;
1423 bool operator<(MathCursorPos const & ti, MathCursorPos const & it)
1425 if (ti.par_ != it.par_) {
1426 lyxerr << "can't compare cursor and anchor in different insets\n";
1429 if (ti.idx_ != it.idx_)
1430 return ti.idx_ < it.idx_;
1431 return ti.pos_ < it.pos_;
1435 MathArray & MathCursorPos::cell(MathCursor::idx_type idx) const
1437 return (*par_)->cell(idx);
1441 MathArray & MathCursorPos::cell() const
1443 return (*par_)->cell(idx_);
1447 MathXArray & MathCursorPos::xcell(MathCursor::idx_type idx) const
1449 return (*par_)->xcell(idx);
1453 MathXArray & MathCursorPos::xcell() const
1455 return (*par_)->xcell(idx_);
1459 MathCursorPos MathCursor::normalAnchor() const
1461 // use Anchor on the same level as Cursor
1462 MathCursorPos normal = Anchor_[Cursor_.size() - 1];
1463 if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) {
1464 // anchor is behind cursor -> move anchor behind the inset