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 // check whether we could move into a superscript
596 MathAtom & p = prevAtom();
597 if (p->asScriptInset() && p->asScriptInset()->hasUp()) {
606 MathAtom & n = nextAtom();
607 if (n->asScriptInset() && n->asScriptInset()->hasUp()) {
616 return goUp() || selection_;
620 bool MathCursor::down(bool sel)
627 // check whether we could move into a subscript
629 MathAtom & p = prevAtom();
630 if (p->asScriptInset() && p->asScriptInset()->hasDown()) {
639 MathAtom & n = nextAtom();
640 if (n->asScriptInset() && n->asScriptInset()->hasDown()) {
649 return goDown() || selection_;
653 bool MathCursor::toggleLimits()
657 MathScriptInset * t = prevAtom()->asScriptInset();
660 int old = t->limits();
661 t->limits(old < 0 ? 1 : -1);
662 return old != t->limits();
666 void MathCursor::macroModeClose()
668 string s = macroName();
670 size_type old = pos();
672 array().erase(pos(), old);
678 int MathCursor::macroNamePos() const
680 for (int i = pos() - 1; i >= 0; --i) {
681 MathAtom & p = array().at(i);
682 if (p->code() == LM_TC_TEX && p->getChar() == '\\')
689 string MathCursor::macroName() const
692 for (int i = macroNamePos(); i >= 0 && i < int(pos()); ++i)
693 s += array().at(i)->getChar();
698 void MathCursor::selCopy()
702 theSelection.grab(*this);
708 void MathCursor::selCut()
712 theSelection.grab(*this);
713 theSelection.erase(*this);
716 theSelection.clear();
721 void MathCursor::selDel()
725 theSelection.erase(*this);
733 void MathCursor::selPaste()
736 theSelection.paste(*this);
737 theSelection.grab(*this);
742 void MathCursor::selHandle(bool sel)
744 if (sel == selection_)
747 theSelection.clear();
753 void MathCursor::selStart()
759 theSelection.clear();
765 void MathCursor::selClear()
772 void MathCursor::selGet(MathArray & ar)
778 theSelection.grab(*this);
779 ar = theSelection.glue();
784 void MathCursor::drawSelection(Painter & pain) const
791 getSelection(i1, i2);
792 //lyxerr << "selection from: " << i1 << " to " << i2 << "\n";
794 if (i1.idx_ == i2.idx_) {
795 MathXArray & c = i1.xcell();
796 int x1 = c.xo() + c.pos2x(i1.pos_);
797 int y1 = c.yo() - c.ascent();
798 int x2 = c.xo() + c.pos2x(i2.pos_);
799 int y2 = c.yo() + c.descent();
800 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
802 std::vector<MathInset::idx_type> indices
803 = (*i1.par_)->idxBetween(i1.idx_, i2.idx_);
804 for (unsigned i = 0; i < indices.size(); ++i) {
805 MathXArray & c = i1.xcell(indices[i]);
807 int y1 = c.yo() - c.ascent();
808 int x2 = c.xo() + c.width();
809 int y2 = c.yo() + c.descent();
810 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
815 // draw anchor if different from selection boundary
816 MathCursorPos anc = Anchor_.back();
817 if (anc != i1 && anc != i2) {
818 MathXArray & c = anc.xcell();
819 int x = c.xo() + c.pos2x(anc.pos_);
820 int y1 = c.yo() - c.ascent();
821 int y2 = c.yo() + c.descent();
822 pain.line(x, y1, x, y2, LColor::mathline);
828 void MathCursor::handleFont(MathTextCodes t)
834 getSelection(i1, i2);
835 if (i1.idx_ == i2.idx_) {
836 MathArray & ar = i1.cell();
837 for (MathInset::pos_type pos = i1.pos_; pos != i2.pos_; ++pos)
838 ar.at(pos)->handleFont(t);
841 lastcode_ = (lastcode_ == t) ? LM_TC_VAR : t;
845 void MathCursor::handleDelim(string const & l, string const & r)
847 handleNest(new MathDelimInset(l, r));
851 void MathCursor::handleNest(MathInset * p)
855 p->cell(0) = theSelection.glue();
857 insert(MathAtom(p)); // this invalidates p!
858 pushRight(prevAtom());
862 void MathCursor::getPos(int & x, int & y)
865 #warning This should probably take cellXOffset and cellYOffset into account
867 x = xarray().xo() + xarray().pos2x(pos());
872 MathAtom & MathCursor::par() const
874 return *cursor().par_;
878 InsetFormulaBase const * MathCursor::formula()
884 MathCursor::idx_type MathCursor::idx() const
886 return cursor().idx_;
890 MathCursor::idx_type & MathCursor::idx()
892 return cursor().idx_;
896 MathCursor::pos_type MathCursor::pos() const
898 return cursor().pos_;
902 MathCursor::pos_type & MathCursor::pos()
904 return cursor().pos_;
908 bool MathCursor::inMacroMode() const
910 return macroNamePos() != -1;
914 bool MathCursor::selection() const
920 MathGridInset * MathCursor::enclosingGrid(MathCursor::idx_type & idx) const
922 for (int i = Cursor_.size() - 1; i >= 0; --i) {
923 MathGridInset * p = (*Cursor_[i].par_)->asGridInset();
925 idx = Cursor_[i].idx_;
933 void MathCursor::pullArg(bool goright)
936 MathArray a = array();
938 MathScriptInset const * p = par()->asScriptInset();
940 // special handling for scripts
941 const bool up = p->hasUp();
943 MathScriptInset * q = nextAtom()->asScriptInset();
947 array().insert(pos(), a);
953 array().insert(pos(), a);
960 void MathCursor::normalize() const
963 #warning This is evil!
965 MathCursor * it = const_cast<MathCursor *>(this);
967 if (idx() >= par()->nargs()) {
968 lyxerr << "this should not really happen - 1: "
969 << idx() << " " << par()->nargs() << "\n";
972 it->idx() = min(idx(), par()->nargs() - 1);
974 if (pos() > size()) {
975 lyxerr << "this should not really happen - 2: "
976 << pos() << " " << size() << " in idx: " << it->idx()
978 WriteStream wi(0, lyxerr, false);
979 it->par()->write(wi);
983 it->pos() = min(pos(), size());
987 MathCursor::size_type MathCursor::size() const
989 return array().size();
993 MathCursor::col_type MathCursor::col() const
995 return par()->col(idx());
999 MathCursor::row_type MathCursor::row() const
1001 return par()->row(idx());
1005 bool MathCursor::hasPrevAtom() const
1011 bool MathCursor::hasNextAtom() const
1013 return pos() < size();
1017 MathAtom const & MathCursor::prevAtom() const
1019 lyx::Assert(pos() > 0);
1020 return array().at(pos() - 1);
1024 MathAtom & MathCursor::prevAtom()
1026 lyx::Assert(pos() > 0);
1027 return array().at(pos() - 1);
1031 MathAtom const & MathCursor::nextAtom() const
1033 lyx::Assert(pos() < size());
1034 return array().at(pos());
1038 MathAtom & MathCursor::nextAtom()
1040 lyx::Assert(pos() < size());
1041 return array().at(pos());
1045 MathArray & MathCursor::array() const
1047 static MathArray dummy;
1049 if (idx() >= par()->nargs()) {
1050 lyxerr << "############ idx_ " << idx() << " not valid\n";
1054 return cursor().cell();
1058 MathXArray & MathCursor::xarray() const
1060 return cursor().xcell();
1064 void MathCursor::idxNext()
1066 par()->idxNext(idx(), pos());
1070 void MathCursor::idxPrev()
1072 par()->idxPrev(idx(), pos());
1076 void MathCursor::splitCell()
1078 if (idx() == par()->nargs() - 1)
1080 MathArray ar = array();
1082 array().erase(pos(), size());
1085 array().insert(0, ar);
1089 void MathCursor::breakLine()
1091 // leave inner cells
1095 MathHullInset * p = formula()->par()->asHullInset();
1099 if (p->getType() == LM_OT_SIMPLE || p->getType() == LM_OT_EQUATION) {
1100 p->mutate(LM_OT_EQNARRAY);
1107 const row_type r = row();
1108 for (col_type c = col() + 1; c < p->ncols(); ++c)
1109 p->cell(p->index(r, c)).swap(p->cell(p->index(r + 1, c)));
1113 p->cell(idx()).swap(p->cell(idx() + p->ncols() - 1));
1118 void MathCursor::readLine(MathArray & ar) const
1120 idx_type base = row() * par()->ncols();
1121 for (idx_type off = 0; off < par()->ncols(); ++off)
1122 ar.push_back(par()->cell(base + off));
1126 char MathCursor::valign() const
1129 MathGridInset * p = enclosingGrid(idx);
1130 return p ? p->valign() : '\0';
1134 char MathCursor::halign() const
1137 MathGridInset * p = enclosingGrid(idx);
1138 return p ? p->halign(idx % p->ncols()) : '\0';
1142 void MathCursor::getSelection(MathCursorPos & i1, MathCursorPos & i2) const
1144 MathCursorPos anc = normalAnchor();
1145 if (anc < cursor()) {
1155 MathCursorPos & MathCursor::cursor()
1157 return Cursor_.back();
1161 MathCursorPos const & MathCursor::cursor() const
1163 return Cursor_.back();
1167 int MathCursor::cellXOffset() const
1169 return par()->cellXOffset(idx());
1173 int MathCursor::cellYOffset() const
1175 return par()->cellYOffset(idx());
1179 int MathCursor::xpos() const
1181 return cellXOffset() + xarray().pos2x(pos());
1185 int MathCursor::ypos() const
1187 return cellYOffset();
1192 void MathCursor::gotoX(int x)
1194 pos() = xarray().x2pos(x - cellXOffset());
1198 bool MathCursor::goUp()
1200 // first ask the inset if it knows better then we
1201 if (par()->idxUp(idx(), pos()))
1204 // leave subscript to the nearest side
1205 MathScriptInset * p = par()->asScriptInset();
1206 if (p && idx() == 0) {
1207 if (pos() <= size() / 2)
1214 // if not, apply brute force.
1218 std::vector<MathCursorPos> save = Cursor_;
1219 y0 -= xarray().ascent();
1220 for (int y = y0 - 4; y > formula()->upperY(); y -= 4) {
1222 if (save != Cursor_ && xarray().yo() < y0)
1230 bool MathCursor::goDown()
1232 // first ask the inset if it knows better then we
1233 if (par()->idxDown(idx(), pos()))
1236 // leave superscript to the nearest side
1237 MathScriptInset * p = par()->asScriptInset();
1238 if (p && idx() == 1) {
1239 if (pos() <= size() / 2)
1246 // if not, apply brute force.
1250 std::vector<MathCursorPos> save = Cursor_;
1251 y0 += xarray().descent();
1252 for (int y = y0 + 4; y < formula()->lowerY(); y += 4) {
1254 if (save != Cursor_ && xarray().yo() > y0)
1262 bool MathCursor::idxLeft()
1264 return par()->idxLeft(idx(), pos());
1268 bool MathCursor::idxRight()
1270 return par()->idxRight(idx(), pos());
1274 bool MathCursor::interpret(string const & s)
1276 //lyxerr << "interpret 1: '" << s << "'\n";
1281 return interpret(s[0]);
1283 //lyxerr << "char: '" << s[0] << "' int: " << int(s[0]) << endl;
1284 //owner_->getIntl()->getTrans().TranslateAndInsert(s[0], lt);
1285 //lyxerr << "trans: '" << s[0] << "' int: " << int(s[0]) << endl;
1287 if (s.size() >= 5 && s.substr(0, 5) == "cases") {
1289 istringstream is(s.substr(6).c_str());
1291 n = std::max(1u, n);
1292 niceInsert(MathAtom(new MathCasesInset(n)));
1296 if (s.size() >= 6 && s.substr(0, 6) == "matrix") {
1301 istringstream is(s.substr(7).c_str());
1302 is >> m >> n >> v_align >> h_align;
1303 m = std::max(1u, m);
1304 n = std::max(1u, n);
1306 niceInsert(MathAtom(new MathArrayInset(m, n, v_align[0], h_align)));
1310 if (s == "\\over" || s == "\\choose" || s == "\\atop") {
1311 MathArray ar = array();
1312 MathAtom t = createMathInset(s.substr(1));
1313 t->asNestInset()->cell(0).swap(array());
1321 niceInsert(createMathInset(s.substr(1)));
1326 bool MathCursor::interpret(char c)
1328 //lyxerr << "interpret 2: '" << c << "'\n";
1329 if (c == '^' || c == '_') {
1331 const bool up = (c == '^');
1333 if (hasPrevAtom() && prevAtom()->asScriptInset()) {
1334 prevAtom()->asScriptInset()->ensure(up);
1335 pushRight(prevAtom());
1338 } else if (hasNextAtom() && nextAtom()->asScriptInset()) {
1339 nextAtom()->asScriptInset()->ensure(up);
1340 pushLeft(nextAtom());
1344 plainInsert(MathAtom(new MathScriptInset(up)));
1345 prevAtom()->asScriptInset()->ensure(up);
1346 pushRight(prevAtom());
1357 if (inMacroMode()) {
1358 string name = macroName();
1360 if (name == "\\" && c == '#') {
1361 insert(c, LM_TC_TEX);
1365 if (name == "\\" && c == '\\') {
1367 interpret("\\backslash");
1371 if (name == "\\#" && '1' <= c && c <= '9') {
1372 insert(c, LM_TC_TEX);
1378 insert(c, LM_TC_TEX);
1383 insert(c, LM_TC_TEX);
1395 if (lastcode_ == LM_TC_TEXTRM) {
1396 // suppress direct insertion of to spaces in a row
1397 // the still allows typing '<space>a<space>' and deleting the 'a', but
1398 // it is better than nothing
1399 if (c == ' ' && hasPrevAtom() && prevAtom()->getChar() == ' ')
1401 insert(c, LM_TC_TEXTRM);
1406 if (hasPrevAtom() && prevAtom()->asSpaceInset()) {
1407 prevAtom()->asSpaceInset()->incSpace();
1411 if (mathcursor->popRight())
1414 // if are at the very end, leave the formula
1415 return pos() != size();
1419 if (strchr("{}", c)) {
1420 insert(c, LM_TC_TEX);
1426 niceInsert(MathAtom(new MathBraceInset));
1434 if (strchr("#$%", c)) {
1435 insert(MathAtom(new MathSpecialCharInset(c)));
1436 lastcode_ = LM_TC_VAR;
1440 if (isalpha(c) && lastcode_ == LM_TC_GREEK) {
1441 insert(c, LM_TC_VAR);
1445 if (isalpha(c) && lastcode_ == LM_TC_GREEK1) {
1446 insert(c, LM_TC_VAR);
1447 lastcode_ = LM_TC_VAR;
1452 insert(c, LM_TC_TEX);
1453 //bv->owner()->message(_("TeX mode"));
1457 // no special circumstances, so insert the character without any fuss
1458 insert(c, LM_TC_MIN);
1464 ////////////////////////////////////////////////////////////////////////
1467 bool operator==(MathCursorPos const & ti, MathCursorPos const & it)
1469 return ti.par_ == it.par_ && ti.idx_ == it.idx_ && ti.pos_ == it.pos_;
1473 bool operator<(MathCursorPos const & ti, MathCursorPos const & it)
1475 if (ti.par_ != it.par_) {
1476 lyxerr << "can't compare cursor and anchor in different insets\n";
1479 if (ti.idx_ != it.idx_)
1480 return ti.idx_ < it.idx_;
1481 return ti.pos_ < it.pos_;
1485 MathArray & MathCursorPos::cell(MathCursor::idx_type idx) const
1487 return (*par_)->cell(idx);
1491 MathArray & MathCursorPos::cell() const
1493 return (*par_)->cell(idx_);
1497 MathXArray & MathCursorPos::xcell(MathCursor::idx_type idx) const
1499 return (*par_)->xcell(idx);
1503 MathXArray & MathCursorPos::xcell() const
1505 return (*par_)->xcell(idx_);
1509 MathCursorPos MathCursor::normalAnchor() const
1511 // use Anchor on the same level as Cursor
1512 MathCursorPos normal = Anchor_[Cursor_.size() - 1];
1513 if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) {
1514 // anchor is behind cursor -> move anchor behind the inset
1521 void MathCursor::stripFromLastEqualSign()
1523 // find position of last '=' in the array
1524 MathArray & ar = cursor().cell();
1525 MathArray::const_iterator et = ar.end();
1526 for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it)
1527 if ((*it)->getChar() == '=')
1530 // delete everything behind this position
1531 ar.erase(et - ar.begin(), ar.size());