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.
21 #pragma implementation
24 #include "math_cursor.h"
25 #include "formulabase.h"
26 #include "math_arrayinset.h"
27 #include "math_braceinset.h"
28 #include "math_casesinset.h"
29 #include "math_charinset.h"
30 #include "math_deliminset.h"
31 #include "math_factory.h"
32 #include "math_hullinset.h"
33 #include "math_iterator.h"
34 #include "math_mathmlstream.h"
35 #include "math_parser.h"
36 #include "math_replace.h"
37 #include "math_scriptinset.h"
38 #include "math_spaceinset.h"
39 #include "math_specialcharinset.h"
40 #include "math_support.h"
46 #include "support/lstrings.h"
47 #include "support/LAssert.h"
64 typedef MathInset::col_type col_type;
65 typedef MathInset::row_type row_type;
66 typedef MathInset::idx_type idx_type;
72 void region(MathCursorPos const & i1, MathCursorPos const & i2,
73 row_type & r1, row_type & r2, col_type & c1, col_type & c2)
75 MathInset * p = i1.par_;
86 void grab(MathCursor const & cursor)
90 cursor.getSelection(i1, i2);
91 // shouldn'tt we assert on i1.par_ == i2.par_?
92 if (i1.idx_ == i2.idx_) {
93 data_ = MathGridInset(1, 1);
94 data_.cell(0) = MathArray(i1.cell(), i1.pos_, i2.pos_);
98 region(i1, i2, r1, r2, c1, c2);
99 data_ = MathGridInset(c2 - c1 + 1, r2 - r1 + 1);
100 for (row_type row = 0; row < data_.nrows(); ++row)
101 for (col_type col = 0; col < data_.ncols(); ++col) {
102 idx_type i = i1.par_->index(row + r1, col + c1);
103 data_.cell(data_.index(row, col)) = i1.par_->cell(i);
108 void erase(MathCursor & cursor)
112 cursor.getSelection(i1, i2);
113 if (i1.idx_ == i2.idx_)
114 i1.cell().erase(i1.pos_, i2.pos_);
116 MathInset * p = i1.par_;
119 region(i1, i2, r1, r2, c1, c2);
120 for (row_type row = r1; row <= r2; ++row)
121 for (col_type col = c1; col <= c2; ++col)
122 p->cell(p->index(row, col)).erase();
124 cursor.cursor() = i1;
127 void paste(MathCursor & cursor) const
130 MathGridInset * p = cursor.enclosingGrid(idx);
131 col_type const numcols = min(data_.ncols(), p->ncols() - p->col(idx));
132 row_type const numrows = min(data_.nrows(), p->nrows() - p->row(idx));
133 for (row_type row = 0; row < numrows; ++row)
134 for (col_type col = 0; col < numcols; ++col) {
135 idx_type i = p->index(row + p->row(idx), col + p->col(idx));
136 p->cell(i).push_back(data_.cell(data_.index(row, col)));
140 // glues selection to one cell
141 MathArray glue() const
144 for (unsigned i = 0; i < data_.nargs(); ++i)
145 ar.push_back(data_.cell(i));
151 data_ = MathGridInset(1, 1);
158 Selection theSelection;
165 MathCursor::MathCursor(InsetFormulaBase * formula, bool left)
166 : formula_(formula), lastcode_(LM_TC_VAR), selection_(false)
168 left ? first() : last();
172 void MathCursor::push(MathAtom & t)
174 Cursor_.push_back(MathCursorPos(t.nucleus()));
178 void MathCursor::pushLeft(MathAtom & t)
180 //cerr << "Entering atom "; t->write(cerr, false); cerr << " left\n";
182 t->idxFirst(idx(), pos());
186 void MathCursor::pushRight(MathAtom & t)
188 //cerr << "Entering atom "; t->write(cerr, false); cerr << " right\n";
191 t->idxLast(idx(), pos());
195 bool MathCursor::popLeft()
197 //cerr << "Leaving atom "; par()->write(cerr, false); cerr << " left\n";
198 if (Cursor_.size() <= 1)
200 if (par()->asScriptInset())
201 par()->asScriptInset()->removeEmptyScripts();
207 bool MathCursor::popRight()
209 //cerr << "Leaving atom "; par()->write(cerr, false); cerr << " right\n";
210 if (Cursor_.size() <= 1)
212 if (par()->asScriptInset())
213 par()->asScriptInset()->removeEmptyScripts();
222 void MathCursor::dump(char const * what) const
224 lyxerr << "MC: " << what << "\n";
225 lyxerr << " Cursor: " << Cursor_.size() << "\n";
226 for (unsigned i = 0; i < Cursor_.size(); ++i)
227 lyxerr << " i: " << i << " " << Cursor_[i] << "\n";
228 lyxerr << " Anchor: " << Anchor_.size() << "\n";
229 for (unsigned i = 0; i < Anchor_.size(); ++i)
230 lyxerr << " i: " << i << " " << Anchor_[i] << "\n";
231 lyxerr << " sel: " << selection_ << "\n";
234 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_ == 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.nucleus() != Anchor_[Cursor_.size()].par_)
275 bool MathCursor::posLeft()
284 bool MathCursor::posRight()
293 bool MathCursor::left(bool sel)
298 lastcode_ = LM_TC_VAR;
302 lastcode_ = LM_TC_VAR;
304 if (hasPrevAtom() && openable(prevAtom(), sel)) {
305 if (prevAtom()->isHyperActive()) {
306 lyxerr << "entering hyperactive inset\n";
308 pushRight(prevAtom());
312 return posLeft() || idxLeft() || popLeft() || selection_;
316 bool MathCursor::right(bool sel)
321 lastcode_ = LM_TC_VAR;
325 lastcode_ = LM_TC_VAR;
327 if (hasNextAtom() && openable(nextAtom(), sel)) {
328 if (nextAtom()->isHyperActive()) {
329 lyxerr << "entering hyperactive inset\n";
332 nextAtom()->edit(formula()->view(), x, y, 0);
334 pushLeft(nextAtom());
338 return posRight() || idxRight() || popRight() || selection_;
342 void MathCursor::first()
345 pushLeft(formula_->par());
349 void MathCursor::last()
356 bool positionable(MathCursor::cursor_type const & cursor,
357 MathCursor::cursor_type const & anchor)
359 // avoid deeper nested insets when selecting
360 if (cursor.size() > anchor.size())
363 // anchor might be deeper, should have same path then
364 for (MathCursor::cursor_type::size_type i = 0; i < cursor.size(); ++i)
365 if (cursor[i].par_ != anchor[i].par_)
368 // position should be ok.
373 void MathCursor::setPos(int x, int y)
376 bool res = bruteFind(x, y,
377 formula()->xlow(), formula()->xhigh(),
378 formula()->ylow(), formula()->yhigh());
380 // this ccan happen on creation of "math-display"
389 void MathCursor::home(bool sel)
394 lastcode_ = LM_TC_VAR;
395 if (!par()->idxHome(idx(), pos()))
401 void MathCursor::end(bool sel)
406 lastcode_ = LM_TC_VAR;
407 if (!par()->idxEnd(idx(), pos()))
413 void MathCursor::plainErase()
415 array().erase(pos());
419 void MathCursor::plainInsert(MathAtom const & t)
421 array().insert(pos(), t);
426 void MathCursor::insert(char c, MathTextCodes t)
428 //lyxerr << "inserting '" << c << "'\n";
429 plainInsert(MathAtom(new MathCharInset(c, t)));
433 void MathCursor::insert(MathAtom const & t)
448 void MathCursor::niceInsert(MathAtom const & t)
451 insert(t); // inserting invalidates the pointer!
452 MathAtom const & p = prevAtom();
455 right(); // do not push for e.g. MathSymbolInset
461 void MathCursor::insert(MathArray const & ar)
467 array().insert(pos(), ar);
472 void MathCursor::paste(MathArray const & ar)
476 array().insert(pos(), ar);
481 void MathCursor::backspace()
493 MathScriptInset * p = prevAtom()->asScriptInset();
495 p->removeScript(p->hasUp());
496 // Don't delete if there is anything left
497 if (p->hasUp() || p->hasDown())
506 void MathCursor::erase()
516 // delete empty cells if necessary
517 if (array().empty()) {
520 par()->idxDelete(idx(), popit, removeit);
521 if (popit && popLeft() && removeit)
529 MathScriptInset * p = nextAtom()->asScriptInset();
531 p->removeScript(p->hasUp());
532 // Don't delete if there is anything left
533 if (p->hasUp() || p->hasDown())
541 void MathCursor::delLine()
550 if (par()->nrows() > 1) {
551 // grid are the only things with more than one row...
552 lyx::Assert(par()->asGridInset());
553 par()->asGridInset()->delRow(hullRow());
556 if (idx() > par()->nargs())
557 idx() = par()->nargs();
564 bool MathCursor::up(bool sel)
569 cursor_type save = Cursor_;
577 bool MathCursor::down(bool sel)
582 cursor_type save = Cursor_;
590 bool MathCursor::toggleLimits()
594 MathScriptInset * t = nextAtom()->asScriptInset();
597 int old = t->limits();
598 t->limits(old < 0 ? 1 : -1);
599 return old != t->limits();
603 void MathCursor::macroModeClose()
605 string s = macroName();
607 size_type old = pos();
609 array().erase(pos(), old);
615 int MathCursor::macroNamePos() const
617 for (int i = pos() - 1; i >= 0; --i) {
618 MathAtom & p = array().at(i);
619 if (p->code() == LM_TC_TEX && p->getChar() == '\\')
626 string MathCursor::macroName() const
629 for (int i = macroNamePos(); i >= 0 && i < int(pos()); ++i)
630 s += array().at(i)->getChar();
635 void MathCursor::selCopy()
639 theSelection.grab(*this);
645 void MathCursor::selCut()
649 theSelection.grab(*this);
650 theSelection.erase(*this);
653 theSelection.clear();
658 void MathCursor::selDel()
662 theSelection.erase(*this);
670 void MathCursor::selPaste()
673 theSelection.paste(*this);
674 //theSelection.grab(*this);
679 void MathCursor::selHandle(bool sel)
681 if (sel == selection_)
683 //theSelection.clear();
689 void MathCursor::selStart()
692 //theSelection.clear();
699 void MathCursor::selClear()
707 void MathCursor::selGet(MathArray & ar)
713 theSelection.grab(*this);
714 ar = theSelection.glue();
719 void MathCursor::drawSelection(Painter & pain) const
726 getSelection(i1, i2);
728 if (i1.idx_ == i2.idx_) {
729 MathXArray & c = i1.xcell();
730 int x1 = c.xo() + c.pos2x(i1.pos_);
731 int y1 = c.yo() - c.ascent();
732 int x2 = c.xo() + c.pos2x(i2.pos_);
733 int y2 = c.yo() + c.descent();
734 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
736 std::vector<MathInset::idx_type> indices
737 = i1.par_->idxBetween(i1.idx_, i2.idx_);
738 for (unsigned i = 0; i < indices.size(); ++i) {
739 MathXArray & c = i1.xcell(indices[i]);
741 int y1 = c.yo() - c.ascent();
742 int x2 = c.xo() + c.width();
743 int y2 = c.yo() + c.descent();
744 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
749 // draw anchor if different from selection boundary
750 MathCursorPos anc = Anchor_.back();
751 if (anc != i1 && anc != i2) {
752 MathXArray & c = anc.xcell();
753 int x = c.xo() + c.pos2x(anc.pos_);
754 int y1 = c.yo() - c.ascent();
755 int y2 = c.yo() + c.descent();
756 pain.line(x, y1, x, y2, LColor::math);
762 void MathCursor::handleFont(MathTextCodes t)
768 getSelection(i1, i2);
769 if (i1.idx_ == i2.idx_) {
770 MathArray & ar = i1.cell();
771 for (MathInset::pos_type pos = i1.pos_; pos != i2.pos_; ++pos)
772 ar.at(pos)->handleFont(t);
775 lastcode_ = (lastcode_ == t) ? LM_TC_VAR : t;
779 void MathCursor::handleDelim(string const & l, string const & r)
781 handleNest(new MathDelimInset(l, r));
785 void MathCursor::handleNest(MathInset * p)
789 p->cell(0) = theSelection.glue();
791 insert(MathAtom(p)); // this invalidates p!
792 pushRight(prevAtom());
796 void MathCursor::getPos(int & x, int & y)
799 #warning This should probably take cellXOffset and cellYOffset into account
801 x = xarray().xo() + xarray().pos2x(pos());
806 MathInset * MathCursor::par() const
808 return cursor().par_;
812 InsetFormulaBase * MathCursor::formula()
818 MathCursor::idx_type MathCursor::idx() const
820 return cursor().idx_;
824 MathCursor::idx_type & MathCursor::idx()
826 return cursor().idx_;
830 MathCursor::pos_type MathCursor::pos() const
832 return cursor().pos_;
836 MathCursor::pos_type & MathCursor::pos()
838 return cursor().pos_;
842 bool MathCursor::inMacroMode() const
844 return macroNamePos() != -1;
848 bool MathCursor::selection() const
854 MathGridInset * MathCursor::enclosingGrid(MathCursor::idx_type & idx) const
856 for (int i = Cursor_.size() - 1; i >= 0; --i) {
857 MathGridInset * p = Cursor_[i].par_->asGridInset();
859 idx = Cursor_[i].idx_;
867 void MathCursor::pullArg(bool goright)
870 MathArray a = array();
872 MathScriptInset const * p = par()->asScriptInset();
874 // special handling for scripts
875 const bool up = p->hasUp();
877 MathScriptInset * q = nextAtom()->asScriptInset();
881 array().insert(pos(), a);
887 array().insert(pos(), a);
894 void MathCursor::normalize() const
897 #warning This is evil!
899 MathCursor * it = const_cast<MathCursor *>(this);
901 if (idx() >= par()->nargs()) {
902 lyxerr << "this should not really happen - 1: "
903 << idx() << " " << par()->nargs() << "\n";
906 it->idx() = min(idx(), par()->nargs() - 1);
908 if (pos() > size()) {
909 lyxerr << "this should not really happen - 2: "
910 << pos() << " " << size() << " in idx: " << it->idx()
912 WriteStream wi(lyxerr, false);
913 it->par()->write(wi);
917 it->pos() = min(pos(), size());
921 MathCursor::size_type MathCursor::size() const
923 return array().size();
927 MathCursor::col_type MathCursor::hullCol() const
929 return Cursor_[0].par_->asGridInset()->col(Cursor_[0].idx_);
933 MathCursor::row_type MathCursor::hullRow() const
935 return Cursor_[0].par_->asGridInset()->row(Cursor_[0].idx_);
939 bool MathCursor::hasPrevAtom() const
945 bool MathCursor::hasNextAtom() const
947 return pos() < size();
951 MathAtom const & MathCursor::prevAtom() const
953 lyx::Assert(pos() > 0);
954 return array().at(pos() - 1);
958 MathAtom & MathCursor::prevAtom()
960 lyx::Assert(pos() > 0);
961 return array().at(pos() - 1);
965 MathAtom const & MathCursor::nextAtom() const
967 lyx::Assert(pos() < size());
968 return array().at(pos());
972 MathAtom & MathCursor::nextAtom()
974 lyx::Assert(pos() < size());
975 return array().at(pos());
979 MathArray & MathCursor::array() const
981 static MathArray dummy;
983 if (idx() >= par()->nargs()) {
984 lyxerr << "############ idx_ " << idx() << " not valid\n";
988 if (Cursor_.size() == 0) {
989 lyxerr << "############ Cursor_.size() == 0 not valid\n";
993 return cursor().cell();
997 MathXArray & MathCursor::xarray() const
999 static MathXArray dummy;
1001 if (Cursor_.size() == 0) {
1002 lyxerr << "############ Cursor_.size() == 0 not valid\n";
1006 return cursor().xcell();
1010 void MathCursor::idxNext()
1012 par()->idxNext(idx(), pos());
1016 void MathCursor::idxPrev()
1018 par()->idxPrev(idx(), pos());
1022 void MathCursor::splitCell()
1024 if (idx() + 1 == par()->nargs())
1026 MathArray ar = array();
1028 array().erase(pos(), size());
1031 array().insert(0, ar);
1035 void MathCursor::breakLine()
1037 // leave inner cells
1041 MathHullInset * p = formula()->par()->asHullInset();
1045 if (p->getType() == LM_OT_SIMPLE || p->getType() == LM_OT_EQUATION) {
1046 p->mutate(LM_OT_EQNARRAY);
1050 p->addRow(hullRow());
1053 const row_type r = hullRow();
1054 for (col_type c = hullCol() + 1; c < p->ncols(); ++c)
1055 p->cell(p->index(r, c)).swap(p->cell(p->index(r + 1, c)));
1059 p->cell(idx()).swap(p->cell(idx() + p->ncols() - 1));
1064 //void MathCursor::readLine(MathArray & ar) const
1066 // idx_type base = row() * par()->ncols();
1067 // for (idx_type off = 0; off < par()->ncols(); ++off)
1068 // ar.push_back(par()->cell(base + off));
1072 char MathCursor::valign() const
1075 MathGridInset * p = enclosingGrid(idx);
1076 return p ? p->valign() : '\0';
1080 char MathCursor::halign() const
1083 MathGridInset * p = enclosingGrid(idx);
1084 return p ? p->halign(idx % p->ncols()) : '\0';
1088 void MathCursor::getSelection(MathCursorPos & i1, MathCursorPos & i2) const
1090 MathCursorPos anc = normalAnchor();
1091 if (anc < cursor()) {
1101 MathCursorPos & MathCursor::cursor()
1103 lyx::Assert(Cursor_.size());
1104 return Cursor_.back();
1108 MathCursorPos const & MathCursor::cursor() const
1110 lyx::Assert(Cursor_.size());
1111 return Cursor_.back();
1115 bool MathCursor::goUpDown(bool up)
1117 int xlow, xhigh, ylow, yhigh;
1122 // try current cell first
1123 xarray().boundingBox(xlow, xhigh, ylow, yhigh);
1128 if (bruteFind(xo, yo, xlow, xhigh, ylow, yhigh))
1131 // try to find an inset that knows better then we
1133 // we found a cell that think something "below" us.
1135 if (par()->idxUp(idx()))
1138 if (par()->idxDown(idx()))
1143 // no such inset found, just take something "above"
1148 up ? formula()->ylow() : yo + 4,
1149 up ? yo - 4 : formula()->yhigh()
1153 xarray().boundingBox(xlow, xhigh, ylow, yhigh);
1154 bruteFind(xo, yo, xlow, xhigh, ylow, yhigh);
1159 bool MathCursor::bruteFind(int x, int y, int xlow, int xhigh, int ylow, int yhigh)
1161 cursor_type best_cursor;
1162 double best_dist = 1e10;
1164 MathIterator it = ibegin(formula()->par().nucleus());
1165 MathIterator et = iend(formula()->par().nucleus());
1166 for ( ; it != et; ++it) {
1167 // avoid invalid nesting hen selecting
1168 if (selection_ && !positionable(it.cursor(), Anchor_))
1170 int xo = it.position().xpos();
1171 int yo = it.position().ypos();
1172 if (xlow - 2 <= xo && xo <= xhigh + 2 &&
1173 ylow - 2 <= yo && yo <= yhigh + 2)
1175 double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
1176 if (d < best_dist) {
1178 best_cursor = it.cursor();
1182 if (best_dist < 1e10)
1183 Cursor_ = best_cursor;
1184 return best_dist < 1e10;
1188 bool MathCursor::idxLeft()
1190 return par()->idxLeft(idx(), pos());
1194 bool MathCursor::idxRight()
1196 return par()->idxRight(idx(), pos());
1200 bool MathCursor::interpret(string const & s)
1202 //lyxerr << "interpret 1: '" << s << "'\n";
1207 return interpret(s[0]);
1209 //lyxerr << "char: '" << s[0] << "' int: " << int(s[0]) << endl;
1210 //owner_->getIntl()->getTrans().TranslateAndInsert(s[0], lt);
1211 //lyxerr << "trans: '" << s[0] << "' int: " << int(s[0]) << endl;
1213 if (s.size() >= 5 && s.substr(0, 5) == "cases") {
1215 istringstream is(s.substr(5).c_str());
1217 n = std::max(1u, n);
1218 niceInsert(MathAtom(new MathCasesInset(n)));
1222 if (s.size() >= 6 && s.substr(0, 6) == "matrix") {
1227 istringstream is(s.substr(6).c_str());
1228 is >> m >> n >> v_align >> h_align;
1229 m = std::max(1u, m);
1230 n = std::max(1u, n);
1232 niceInsert(MathAtom(new MathArrayInset(m, n, v_align[0], h_align)));
1236 if (s.size() >= 7 && s.substr(0, 7) == "replace") {
1238 istringstream is(s.substr(7).c_str());
1241 mathed_parse_cell(rep.from, from);
1242 mathed_parse_cell(rep.to, to);
1243 lyxerr << "replacing '" << from << "' with '" << to << "'\n";
1244 par()->replace(rep);
1248 if (s == "\\over" || s == "\\choose" || s == "\\atop") {
1249 MathArray ar = array();
1250 MathAtom t(createMathInset(s.substr(1)));
1251 t->asNestInset()->cell(0).swap(array());
1259 latexkeys const * l = in_word_set(s.substr(1));
1260 if (l && (l->token == LM_TK_FONT || l->token == LM_TK_OLDFONT)) {
1261 lastcode_ = static_cast<MathTextCodes>(l->id);
1265 niceInsert(createMathInset(s.substr(1)));
1269 bool MathCursor::script(bool up)
1273 if (hasPrevAtom() && prevAtom()->asScriptInset()) {
1274 prevAtom()->asScriptInset()->ensure(up);
1275 pushRight(prevAtom());
1278 } else if (hasNextAtom() && nextAtom()->asScriptInset()) {
1279 nextAtom()->asScriptInset()->ensure(up);
1280 pushLeft(nextAtom());
1284 plainInsert(MathAtom(new MathScriptInset(up)));
1285 prevAtom()->asScriptInset()->ensure(up);
1286 pushRight(prevAtom());
1296 bool MathCursor::interpret(char c)
1298 //lyxerr << "interpret 2: '" << c << "'\n";
1300 if (inMacroMode()) {
1301 string name = macroName();
1303 if (name == "\\" && c == '#') {
1304 insert(c, LM_TC_TEX);
1308 if (name == "\\" && c == '\\') {
1310 interpret("\\backslash");
1314 if (name == "\\#" && '1' <= c && c <= '9') {
1315 insert(c, LM_TC_TEX);
1321 insert(c, LM_TC_TEX);
1326 insert(c, LM_TC_TEX);
1339 // fall through in the other cases
1342 if (lastcode_ == LM_TC_TEXTRM) {
1343 // suppress direct insertion of two spaces in a row
1344 // the still allows typing '<space>a<space>' and deleting the 'a', but
1345 // it is better than nothing...
1346 if (c == ' ' && hasPrevAtom() && prevAtom()->getChar() == ' ')
1348 insert(c, LM_TC_TEXTRM);
1353 if (hasPrevAtom() && prevAtom()->asSpaceInset()) {
1354 prevAtom()->asSpaceInset()->incSpace();
1357 if (mathcursor->popRight())
1359 // if are at the very end, leave the formula
1360 return pos() != size();
1364 if (strchr("{}", c)) {
1365 insert(c, LM_TC_TEX);
1371 niceInsert(MathAtom(new MathBraceInset));
1379 if (strchr("#$%", c)) {
1380 insert(MathAtom(new MathSpecialCharInset(c)));
1381 lastcode_ = LM_TC_VAR;
1385 if (isalpha(c) && lastcode_ == LM_TC_GREEK) {
1386 insert(c, LM_TC_VAR);
1390 if (isalpha(c) && lastcode_ == LM_TC_GREEK1) {
1391 insert(c, LM_TC_VAR);
1392 lastcode_ = LM_TC_VAR;
1397 insert(c, LM_TC_TEX);
1398 //bv->owner()->message(_("TeX mode"));
1402 // no special circumstances, so insert the character without any fuss
1403 insert(c, lastcode_);
1404 lastcode_ = LM_TC_MIN;
1410 MathCursorPos MathCursor::normalAnchor() const
1412 if (Anchor_.size() < Cursor_.size()) {
1414 lyxerr << "unusual Anchor size\n";
1417 //lyx::Assert(Anchor_.size() >= Cursor_.size());
1418 // use Anchor on the same level as Cursor
1419 MathCursorPos normal = Anchor_[Cursor_.size() - 1];
1420 if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) {
1421 // anchor is behind cursor -> move anchor behind the inset
1428 void MathCursor::stripFromLastEqualSign()
1430 // find position of last '=' in the array
1431 MathArray & ar = cursor().cell();
1432 MathArray::const_iterator et = ar.end();
1433 for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it)
1434 if ((*it)->getChar() == '=')
1437 // delete everything behind this position
1438 ar.erase(et - ar.begin(), ar.size());