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 "formulabase.h"
32 #include "math_arrayinset.h"
33 #include "math_braceinset.h"
34 #include "math_casesinset.h"
35 #include "math_charinset.h"
36 #include "math_cursor.h"
37 #include "math_deliminset.h"
38 #include "math_factory.h"
39 #include "math_hullinset.h"
40 #include "math_iterator.h"
41 #include "math_mathmlstream.h"
42 #include "math_parser.h"
43 #include "math_replace.h"
44 #include "math_scriptinset.h"
45 #include "math_spaceinset.h"
46 #include "math_specialcharinset.h"
47 #include "math_support.h"
61 typedef MathInset::col_type col_type;
62 typedef MathInset::row_type row_type;
63 typedef MathInset::idx_type idx_type;
69 void region(MathCursorPos const & i1, MathCursorPos const & i2,
70 row_type & r1, row_type & r2, col_type & c1, col_type & c2)
72 MathInset * p = i1.par_;
83 void grab(MathCursor const & cursor)
87 cursor.getSelection(i1, i2);
88 // shouldn'tt we assert on i1.par_ == i2.par_?
89 if (i1.idx_ == i2.idx_) {
90 data_ = MathGridInset(1, 1);
91 data_.cell(0) = MathArray(i1.cell(), i1.pos_, i2.pos_);
95 region(i1, i2, r1, r2, c1, c2);
96 data_ = MathGridInset(c2 - c1 + 1, r2 - r1 + 1);
97 for (row_type row = 0; row < data_.nrows(); ++row)
98 for (col_type col = 0; col < data_.ncols(); ++col) {
99 idx_type i = i1.par_->index(row + r1, col + c1);
100 data_.cell(data_.index(row, col)) = i1.par_->cell(i);
105 void erase(MathCursor & cursor)
109 cursor.getSelection(i1, i2);
110 if (i1.idx_ == i2.idx_)
111 i1.cell().erase(i1.pos_, i2.pos_);
113 MathInset * p = i1.par_;
116 region(i1, i2, r1, r2, c1, c2);
117 for (row_type row = r1; row <= r2; ++row)
118 for (col_type col = c1; col <= c2; ++col)
119 p->cell(p->index(row, col)).erase();
121 cursor.cursor() = i1;
124 void paste(MathCursor & cursor) const
127 MathGridInset * p = cursor.enclosingGrid(idx);
128 col_type const numcols = min(data_.ncols(), p->ncols() - p->col(idx));
129 row_type const numrows = min(data_.nrows(), p->nrows() - p->row(idx));
130 for (row_type row = 0; row < numrows; ++row)
131 for (col_type col = 0; col < numcols; ++col) {
132 idx_type i = p->index(row + p->row(idx), col + p->col(idx));
133 p->cell(i).push_back(data_.cell(data_.index(row, col)));
137 // glues selection to one cell
138 MathArray glue() const
141 for (unsigned i = 0; i < data_.nargs(); ++i)
142 ar.push_back(data_.cell(i));
148 data_ = MathGridInset(1, 1);
155 Selection theSelection;
162 MathCursor::MathCursor(InsetFormulaBase * formula, bool left)
163 : formula_(formula), lastcode_(LM_TC_VAR), selection_(false)
165 left ? first() : last();
169 void MathCursor::push(MathAtom & t)
171 Cursor_.push_back(MathCursorPos(t.nucleus()));
175 void MathCursor::pushLeft(MathAtom & t)
177 //cerr << "Entering atom "; t->write(cerr, false); cerr << " left\n";
179 t->idxFirst(idx(), pos());
183 void MathCursor::pushRight(MathAtom & t)
185 //cerr << "Entering atom "; t->write(cerr, false); cerr << " right\n";
188 t->idxLast(idx(), pos());
192 bool MathCursor::popLeft()
194 //cerr << "Leaving atom "; par()->write(cerr, false); cerr << " left\n";
195 if (Cursor_.size() <= 1)
197 if (par()->asScriptInset())
198 par()->asScriptInset()->removeEmptyScripts();
204 bool MathCursor::popRight()
206 //cerr << "Leaving atom "; par()->write(cerr, false); cerr << " right\n";
207 if (Cursor_.size() <= 1)
209 if (par()->asScriptInset())
210 par()->asScriptInset()->removeEmptyScripts();
219 void MathCursor::dump(char const * what) const
221 lyxerr << "MC: " << what << "\n";
222 lyxerr << " Cursor: " << Cursor_.size() << "\n";
223 for (unsigned i = 0; i < Cursor_.size(); ++i)
224 lyxerr << " i: " << i << " " << Cursor_[i] << "\n";
225 lyxerr << " Anchor: " << Anchor_.size() << "\n";
226 for (unsigned i = 0; i < Anchor_.size(); ++i)
227 lyxerr << " i: " << i << " " << Anchor_[i] << "\n";
228 lyxerr << " sel: " << selection_ << "\n";
231 void MathCursor::dump(char const *) const {}
235 UpdatableInset * MathCursor::asHyperActiveInset() const
237 return par()->asHyperActiveInset();
241 bool MathCursor::isInside(MathInset const * p) const
243 for (unsigned i = 0; i < Cursor_.size(); ++i)
244 if (Cursor_[i].par_ == p)
250 bool MathCursor::openable(MathAtom const & t, bool sel) const
252 if (t->isHyperActive())
258 if (t->asScriptInset())
262 // we can't move into anything new during selection
263 if (Cursor_.size() == Anchor_.size())
265 if (t.nucleus() != Anchor_[Cursor_.size()].par_)
272 bool MathCursor::posLeft()
281 bool MathCursor::posRight()
290 bool MathCursor::left(bool sel)
295 lastcode_ = LM_TC_VAR;
299 lastcode_ = LM_TC_VAR;
301 if (hasPrevAtom() && openable(prevAtom(), sel)) {
302 if (prevAtom()->isHyperActive()) {
303 lyxerr << "entering hyperactive inset\n";
305 pushRight(prevAtom());
309 return posLeft() || idxLeft() || popLeft() || selection_;
313 bool MathCursor::right(bool sel)
318 lastcode_ = LM_TC_VAR;
322 lastcode_ = LM_TC_VAR;
324 if (hasNextAtom() && openable(nextAtom(), sel)) {
325 if (nextAtom()->isHyperActive()) {
326 lyxerr << "entering hyperactive inset\n";
329 nextAtom()->edit(formula()->view(), x, y, 0);
331 pushLeft(nextAtom());
335 return posRight() || idxRight() || popRight() || selection_;
339 void MathCursor::first()
342 pushLeft(formula_->par());
346 void MathCursor::last()
353 bool positionable(MathCursor::cursor_type const & cursor,
354 MathCursor::cursor_type const & anchor)
356 // avoid deeper nested insets when selecting
357 if (cursor.size() > anchor.size())
360 // anchor might be deeper, should have same path then
361 for (MathCursor::cursor_type::size_type i = 0; i < cursor.size(); ++i)
362 if (cursor[i].par_ != anchor[i].par_)
365 // position should be ok.
370 void MathCursor::setPos(int x, int y)
373 bool res = bruteFind(x, y,
374 formula()->xlow(), formula()->xhigh(),
375 formula()->ylow(), formula()->yhigh());
382 void MathCursor::home(bool sel)
387 lastcode_ = LM_TC_VAR;
388 if (!par()->idxHome(idx(), pos()))
394 void MathCursor::end(bool sel)
399 lastcode_ = LM_TC_VAR;
400 if (!par()->idxEnd(idx(), pos()))
406 void MathCursor::plainErase()
408 array().erase(pos());
412 void MathCursor::plainInsert(MathAtom const & t)
414 array().insert(pos(), t);
419 void MathCursor::insert(char c, MathTextCodes t)
421 //lyxerr << "inserting '" << c << "'\n";
422 plainInsert(MathAtom(new MathCharInset(c, t)));
426 void MathCursor::insert(MathAtom const & t)
441 void MathCursor::niceInsert(MathAtom const & t)
444 insert(t); // inserting invalidates the pointer!
445 MathAtom const & p = prevAtom();
448 right(); // do not push for e.g. MathSymbolInset
454 void MathCursor::insert(MathArray const & ar)
460 array().insert(pos(), ar);
465 void MathCursor::paste(MathArray const & ar)
469 array().insert(pos(), ar);
474 void MathCursor::backspace()
486 MathScriptInset * p = prevAtom()->asScriptInset();
488 p->removeScript(p->hasUp());
489 // Don't delete if there is anything left
490 if (p->hasUp() || p->hasDown())
499 void MathCursor::erase()
509 // delete empty cells if necessary
510 if (array().empty()) {
513 par()->idxDelete(idx(), popit, removeit);
514 if (popit && popLeft() && removeit)
522 MathScriptInset * p = nextAtom()->asScriptInset();
524 p->removeScript(p->hasUp());
525 // Don't delete if there is anything left
526 if (p->hasUp() || p->hasDown())
534 void MathCursor::delLine()
543 if (par()->nrows() > 1) {
544 // grid are the only things with more than one row...
545 lyx::Assert(par()->asGridInset());
546 par()->asGridInset()->delRow(hullRow());
549 if (idx() > par()->nargs())
550 idx() = par()->nargs();
557 bool MathCursor::up(bool sel)
562 cursor_type save = Cursor_;
570 bool MathCursor::down(bool sel)
575 cursor_type save = Cursor_;
583 bool MathCursor::toggleLimits()
587 MathScriptInset * t = nextAtom()->asScriptInset();
590 int old = t->limits();
591 t->limits(old < 0 ? 1 : -1);
592 return old != t->limits();
596 void MathCursor::macroModeClose()
598 string s = macroName();
600 size_type old = pos();
602 array().erase(pos(), old);
608 int MathCursor::macroNamePos() const
610 for (int i = pos() - 1; i >= 0; --i) {
611 MathAtom & p = array().at(i);
612 if (p->code() == LM_TC_TEX && p->getChar() == '\\')
619 string MathCursor::macroName() const
622 for (int i = macroNamePos(); i >= 0 && i < int(pos()); ++i)
623 s += array().at(i)->getChar();
628 void MathCursor::selCopy()
632 theSelection.grab(*this);
638 void MathCursor::selCut()
642 theSelection.grab(*this);
643 theSelection.erase(*this);
646 theSelection.clear();
651 void MathCursor::selDel()
655 theSelection.erase(*this);
663 void MathCursor::selPaste()
666 theSelection.paste(*this);
667 //theSelection.grab(*this);
672 void MathCursor::selHandle(bool sel)
674 if (sel == selection_)
676 //theSelection.clear();
682 void MathCursor::selStart()
685 //theSelection.clear();
692 void MathCursor::selClear()
700 void MathCursor::selGet(MathArray & ar)
706 theSelection.grab(*this);
707 ar = theSelection.glue();
712 void MathCursor::drawSelection(Painter & pain) const
719 getSelection(i1, i2);
721 if (i1.idx_ == i2.idx_) {
722 MathXArray & c = i1.xcell();
723 int x1 = c.xo() + c.pos2x(i1.pos_);
724 int y1 = c.yo() - c.ascent();
725 int x2 = c.xo() + c.pos2x(i2.pos_);
726 int y2 = c.yo() + c.descent();
727 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
729 std::vector<MathInset::idx_type> indices
730 = i1.par_->idxBetween(i1.idx_, i2.idx_);
731 for (unsigned i = 0; i < indices.size(); ++i) {
732 MathXArray & c = i1.xcell(indices[i]);
734 int y1 = c.yo() - c.ascent();
735 int x2 = c.xo() + c.width();
736 int y2 = c.yo() + c.descent();
737 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
742 // draw anchor if different from selection boundary
743 MathCursorPos anc = Anchor_.back();
744 if (anc != i1 && anc != i2) {
745 MathXArray & c = anc.xcell();
746 int x = c.xo() + c.pos2x(anc.pos_);
747 int y1 = c.yo() - c.ascent();
748 int y2 = c.yo() + c.descent();
749 pain.line(x, y1, x, y2, LColor::math);
755 void MathCursor::handleFont(MathTextCodes t)
761 getSelection(i1, i2);
762 if (i1.idx_ == i2.idx_) {
763 MathArray & ar = i1.cell();
764 for (MathInset::pos_type pos = i1.pos_; pos != i2.pos_; ++pos)
765 ar.at(pos)->handleFont(t);
768 lastcode_ = (lastcode_ == t) ? LM_TC_VAR : t;
772 void MathCursor::handleDelim(string const & l, string const & r)
774 handleNest(new MathDelimInset(l, r));
778 void MathCursor::handleNest(MathInset * p)
782 p->cell(0) = theSelection.glue();
784 insert(MathAtom(p)); // this invalidates p!
785 pushRight(prevAtom());
789 void MathCursor::getPos(int & x, int & y)
792 #warning This should probably take cellXOffset and cellYOffset into account
794 x = xarray().xo() + xarray().pos2x(pos());
799 MathInset * MathCursor::par() const
801 return cursor().par_;
805 InsetFormulaBase * MathCursor::formula()
811 MathCursor::idx_type MathCursor::idx() const
813 return cursor().idx_;
817 MathCursor::idx_type & MathCursor::idx()
819 return cursor().idx_;
823 MathCursor::pos_type MathCursor::pos() const
825 return cursor().pos_;
829 MathCursor::pos_type & MathCursor::pos()
831 return cursor().pos_;
835 bool MathCursor::inMacroMode() const
837 return macroNamePos() != -1;
841 bool MathCursor::selection() const
847 MathGridInset * MathCursor::enclosingGrid(MathCursor::idx_type & idx) const
849 for (int i = Cursor_.size() - 1; i >= 0; --i) {
850 MathGridInset * p = Cursor_[i].par_->asGridInset();
852 idx = Cursor_[i].idx_;
860 void MathCursor::pullArg(bool goright)
863 MathArray a = array();
865 MathScriptInset const * p = par()->asScriptInset();
867 // special handling for scripts
868 const bool up = p->hasUp();
870 MathScriptInset * q = nextAtom()->asScriptInset();
874 array().insert(pos(), a);
880 array().insert(pos(), a);
887 void MathCursor::normalize() const
890 #warning This is evil!
892 MathCursor * it = const_cast<MathCursor *>(this);
894 if (idx() >= par()->nargs()) {
895 lyxerr << "this should not really happen - 1: "
896 << idx() << " " << par()->nargs() << "\n";
899 it->idx() = min(idx(), par()->nargs() - 1);
901 if (pos() > size()) {
902 lyxerr << "this should not really happen - 2: "
903 << pos() << " " << size() << " in idx: " << it->idx()
905 WriteStream wi(lyxerr, false);
906 it->par()->write(wi);
910 it->pos() = min(pos(), size());
914 MathCursor::size_type MathCursor::size() const
916 return array().size();
920 MathCursor::col_type MathCursor::hullCol() const
922 return Cursor_[0].par_->asGridInset()->col(Cursor_[0].idx_);
926 MathCursor::row_type MathCursor::hullRow() const
928 return Cursor_[0].par_->asGridInset()->row(Cursor_[0].idx_);
932 bool MathCursor::hasPrevAtom() const
938 bool MathCursor::hasNextAtom() const
940 return pos() < size();
944 MathAtom const & MathCursor::prevAtom() const
946 lyx::Assert(pos() > 0);
947 return array().at(pos() - 1);
951 MathAtom & MathCursor::prevAtom()
953 lyx::Assert(pos() > 0);
954 return array().at(pos() - 1);
958 MathAtom const & MathCursor::nextAtom() const
960 lyx::Assert(pos() < size());
961 return array().at(pos());
965 MathAtom & MathCursor::nextAtom()
967 lyx::Assert(pos() < size());
968 return array().at(pos());
972 MathArray & MathCursor::array() const
974 static MathArray dummy;
976 if (idx() >= par()->nargs()) {
977 lyxerr << "############ idx_ " << idx() << " not valid\n";
981 if (Cursor_.size() == 0) {
982 lyxerr << "############ Cursor_.size() == 0 not valid\n";
986 return cursor().cell();
990 MathXArray & MathCursor::xarray() const
992 static MathXArray dummy;
994 if (Cursor_.size() == 0) {
995 lyxerr << "############ Cursor_.size() == 0 not valid\n";
999 return cursor().xcell();
1003 void MathCursor::idxNext()
1005 par()->idxNext(idx(), pos());
1009 void MathCursor::idxPrev()
1011 par()->idxPrev(idx(), pos());
1015 void MathCursor::splitCell()
1017 if (idx() + 1 == par()->nargs())
1019 MathArray ar = array();
1021 array().erase(pos(), size());
1024 array().insert(0, ar);
1028 void MathCursor::breakLine()
1030 // leave inner cells
1034 MathHullInset * p = formula()->par()->asHullInset();
1038 if (p->getType() == LM_OT_SIMPLE || p->getType() == LM_OT_EQUATION) {
1039 p->mutate(LM_OT_EQNARRAY);
1043 p->addRow(hullRow());
1046 const row_type r = hullRow();
1047 for (col_type c = hullCol() + 1; c < p->ncols(); ++c)
1048 p->cell(p->index(r, c)).swap(p->cell(p->index(r + 1, c)));
1052 p->cell(idx()).swap(p->cell(idx() + p->ncols() - 1));
1057 //void MathCursor::readLine(MathArray & ar) const
1059 // idx_type base = row() * par()->ncols();
1060 // for (idx_type off = 0; off < par()->ncols(); ++off)
1061 // ar.push_back(par()->cell(base + off));
1065 char MathCursor::valign() const
1068 MathGridInset * p = enclosingGrid(idx);
1069 return p ? p->valign() : '\0';
1073 char MathCursor::halign() const
1076 MathGridInset * p = enclosingGrid(idx);
1077 return p ? p->halign(idx % p->ncols()) : '\0';
1081 void MathCursor::getSelection(MathCursorPos & i1, MathCursorPos & i2) const
1083 MathCursorPos anc = normalAnchor();
1084 if (anc < cursor()) {
1094 MathCursorPos & MathCursor::cursor()
1096 lyx::Assert(Cursor_.size());
1097 return Cursor_.back();
1101 MathCursorPos const & MathCursor::cursor() const
1103 lyx::Assert(Cursor_.size());
1104 return Cursor_.back();
1108 bool MathCursor::goUpDown(bool up)
1110 int xlow, xhigh, ylow, yhigh;
1115 // try current cell first
1116 xarray().boundingBox(xlow, xhigh, ylow, yhigh);
1121 if (bruteFind(xo, yo, xlow, xhigh, ylow, yhigh))
1124 // try to find an inset that knows better then we
1126 // we found a cell that think something "below" us.
1128 if (par()->idxUp(idx()))
1131 if (par()->idxDown(idx()))
1136 // no such inset found, just take something "above"
1141 up ? formula()->ylow() : yo + 4,
1142 up ? yo - 4 : formula()->yhigh()
1146 xarray().boundingBox(xlow, xhigh, ylow, yhigh);
1147 bruteFind(xo, yo, xlow, xhigh, ylow, yhigh);
1152 bool MathCursor::bruteFind(int x, int y, int xlow, int xhigh, int ylow, int yhigh)
1154 cursor_type best_cursor;
1155 double best_dist = 1e10;
1157 MathIterator it = ibegin(formula()->par().nucleus());
1158 MathIterator et = iend(formula()->par().nucleus());
1159 for ( ; it != et; ++it) {
1160 // avoid invalid nesting hen selecting
1161 if (selection_ && !positionable(it.cursor(), Anchor_))
1163 int xo = it.position().xpos();
1164 int yo = it.position().ypos();
1165 if (xlow - 2 <= xo && xo <= xhigh + 2 &&
1166 ylow - 2 <= yo && yo <= yhigh + 2)
1168 double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
1169 if (d < best_dist) {
1171 best_cursor = it.cursor();
1175 if (best_dist < 1e10)
1176 Cursor_ = best_cursor;
1177 return best_dist < 1e10;
1181 bool MathCursor::idxLeft()
1183 return par()->idxLeft(idx(), pos());
1187 bool MathCursor::idxRight()
1189 return par()->idxRight(idx(), pos());
1193 bool MathCursor::interpret(string const & s)
1195 //lyxerr << "interpret 1: '" << s << "'\n";
1200 return interpret(s[0]);
1202 //lyxerr << "char: '" << s[0] << "' int: " << int(s[0]) << endl;
1203 //owner_->getIntl()->getTrans().TranslateAndInsert(s[0], lt);
1204 //lyxerr << "trans: '" << s[0] << "' int: " << int(s[0]) << endl;
1206 if (s.size() >= 5 && s.substr(0, 5) == "cases") {
1208 istringstream is(s.substr(5).c_str());
1210 n = std::max(1u, n);
1211 niceInsert(MathAtom(new MathCasesInset(n)));
1215 if (s.size() >= 6 && s.substr(0, 6) == "matrix") {
1220 istringstream is(s.substr(6).c_str());
1221 is >> m >> n >> v_align >> h_align;
1222 m = std::max(1u, m);
1223 n = std::max(1u, n);
1225 niceInsert(MathAtom(new MathArrayInset(m, n, v_align[0], h_align)));
1229 if (s.size() >= 7 && s.substr(0, 7) == "replace") {
1231 istringstream is(s.substr(7).c_str());
1234 mathed_parse_cell(rep.from, from);
1235 mathed_parse_cell(rep.to, to);
1236 lyxerr << "replacing '" << from << "' with '" << to << "'\n";
1237 par()->replace(rep);
1241 if (s == "\\over" || s == "\\choose" || s == "\\atop") {
1242 MathArray ar = array();
1243 MathAtom t = createMathInset(s.substr(1));
1244 t->asNestInset()->cell(0).swap(array());
1252 latexkeys const * l = in_word_set(s.substr(1));
1253 if (l && (l->token == LM_TK_FONT || l->token == LM_TK_OLDFONT)) {
1254 lastcode_ = static_cast<MathTextCodes>(l->id);
1258 niceInsert(createMathInset(s.substr(1)));
1262 bool MathCursor::script(bool up)
1266 if (hasPrevAtom() && prevAtom()->asScriptInset()) {
1267 prevAtom()->asScriptInset()->ensure(up);
1268 pushRight(prevAtom());
1271 } else if (hasNextAtom() && nextAtom()->asScriptInset()) {
1272 nextAtom()->asScriptInset()->ensure(up);
1273 pushLeft(nextAtom());
1277 plainInsert(MathAtom(new MathScriptInset(up)));
1278 prevAtom()->asScriptInset()->ensure(up);
1279 pushRight(prevAtom());
1289 bool MathCursor::interpret(char c)
1291 //lyxerr << "interpret 2: '" << c << "'\n";
1293 if (inMacroMode()) {
1294 string name = macroName();
1296 if (name == "\\" && c == '#') {
1297 insert(c, LM_TC_TEX);
1301 if (name == "\\" && c == '\\') {
1303 interpret("\\backslash");
1307 if (name == "\\#" && '1' <= c && c <= '9') {
1308 insert(c, LM_TC_TEX);
1314 insert(c, LM_TC_TEX);
1319 insert(c, LM_TC_TEX);
1332 // fall through in the other cases
1335 if (lastcode_ == LM_TC_TEXTRM) {
1336 // suppress direct insertion of two spaces in a row
1337 // the still allows typing '<space>a<space>' and deleting the 'a', but
1338 // it is better than nothing...
1339 if (c == ' ' && hasPrevAtom() && prevAtom()->getChar() == ' ')
1341 insert(c, LM_TC_TEXTRM);
1346 if (hasPrevAtom() && prevAtom()->asSpaceInset()) {
1347 prevAtom()->asSpaceInset()->incSpace();
1350 if (mathcursor->popRight())
1352 // if are at the very end, leave the formula
1353 return pos() != size();
1357 if (strchr("{}", c)) {
1358 insert(c, LM_TC_TEX);
1364 niceInsert(MathAtom(new MathBraceInset));
1372 if (strchr("#$%", c)) {
1373 insert(MathAtom(new MathSpecialCharInset(c)));
1374 lastcode_ = LM_TC_VAR;
1378 if (isalpha(c) && lastcode_ == LM_TC_GREEK) {
1379 insert(c, LM_TC_VAR);
1383 if (isalpha(c) && lastcode_ == LM_TC_GREEK1) {
1384 insert(c, LM_TC_VAR);
1385 lastcode_ = LM_TC_VAR;
1390 insert(c, LM_TC_TEX);
1391 //bv->owner()->message(_("TeX mode"));
1395 // no special circumstances, so insert the character without any fuss
1396 insert(c, lastcode_);
1397 lastcode_ = LM_TC_MIN;
1403 MathCursorPos MathCursor::normalAnchor() const
1405 if (Anchor_.size() < Cursor_.size()) {
1407 lyxerr << "unusual Anchor size\n";
1410 //lyx::Assert(Anchor_.size() >= Cursor_.size());
1411 // use Anchor on the same level as Cursor
1412 MathCursorPos normal = Anchor_[Cursor_.size() - 1];
1413 if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) {
1414 // anchor is behind cursor -> move anchor behind the inset
1421 void MathCursor::stripFromLastEqualSign()
1423 // find position of last '=' in the array
1424 MathArray & ar = cursor().cell();
1425 MathArray::const_iterator et = ar.end();
1426 for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it)
1427 if ((*it)->getChar() == '=')
1430 // delete everything behind this position
1431 ar.erase(et - ar.begin(), ar.size());