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 "support/lstrings.h"
25 #include "support/LAssert.h"
29 #include "math_cursor.h"
30 #include "formulabase.h"
31 #include "math_arrayinset.h"
32 #include "math_braceinset.h"
33 #include "math_boxinset.h"
34 #include "math_casesinset.h"
35 #include "math_charinset.h"
36 #include "math_deliminset.h"
37 #include "math_factory.h"
38 #include "math_hullinset.h"
39 #include "math_iterator.h"
40 #include "math_mathmlstream.h"
41 #include "math_parser.h"
42 #include "math_replace.h"
43 #include "math_scriptinset.h"
44 #include "math_spaceinset.h"
45 #include "math_specialcharinset.h"
46 #include "math_support.h"
63 typedef MathInset::col_type col_type;
64 typedef MathInset::row_type row_type;
65 typedef MathInset::idx_type idx_type;
71 void region(MathCursorPos const & i1, MathCursorPos const & i2,
72 row_type & r1, row_type & r2, col_type & c1, col_type & c2)
74 MathInset * p = i1.par_;
85 void grab(MathCursor const & cursor)
89 cursor.getSelection(i1, i2);
90 // shouldn'tt we assert on i1.par_ == i2.par_?
91 if (i1.idx_ == i2.idx_) {
92 data_ = MathGridInset(1, 1);
93 data_.cell(0) = MathArray(i1.cell(), i1.pos_, i2.pos_);
97 region(i1, i2, r1, r2, c1, c2);
98 data_ = MathGridInset(c2 - c1 + 1, r2 - r1 + 1);
99 for (row_type row = 0; row < data_.nrows(); ++row)
100 for (col_type col = 0; col < data_.ncols(); ++col) {
101 idx_type i = i1.par_->index(row + r1, col + c1);
102 data_.cell(data_.index(row, col)) = i1.par_->cell(i);
107 void erase(MathCursor & cursor)
111 cursor.getSelection(i1, i2);
112 if (i1.idx_ == i2.idx_)
113 i1.cell().erase(i1.pos_, i2.pos_);
115 MathInset * p = i1.par_;
118 region(i1, i2, r1, r2, c1, c2);
119 for (row_type row = r1; row <= r2; ++row)
120 for (col_type col = c1; col <= c2; ++col)
121 p->cell(p->index(row, col)).erase();
123 cursor.cursor() = i1;
126 void paste(MathCursor & cursor) const
129 MathGridInset * p = cursor.enclosingGrid(idx);
130 col_type const numcols = min(data_.ncols(), p->ncols() - p->col(idx));
131 row_type const numrows = min(data_.nrows(), p->nrows() - p->row(idx));
132 for (row_type row = 0; row < numrows; ++row)
133 for (col_type col = 0; col < numcols; ++col) {
134 idx_type i = p->index(row + p->row(idx), col + p->col(idx));
135 p->cell(i).push_back(data_.cell(data_.index(row, col)));
139 // glues selection to one cell
140 MathArray glue() const
143 for (unsigned i = 0; i < data_.nargs(); ++i)
144 ar.push_back(data_.cell(i));
150 data_ = MathGridInset(1, 1);
157 Selection theSelection;
164 MathCursor::MathCursor(InsetFormulaBase * formula, bool left)
165 : formula_(formula), lastcode_(LM_TC_VAR), selection_(false)
167 left ? first() : last();
171 void MathCursor::push(MathAtom & t)
173 Cursor_.push_back(MathCursorPos(t.nucleus()));
177 void MathCursor::pushLeft(MathAtom & t)
179 //cerr << "Entering atom "; t->write(cerr, false); cerr << " left\n";
181 t->idxFirst(idx(), pos());
185 void MathCursor::pushRight(MathAtom & t)
187 //cerr << "Entering atom "; t->write(cerr, false); cerr << " right\n";
190 t->idxLast(idx(), pos());
194 bool MathCursor::popLeft()
196 //cerr << "Leaving atom "; par()->write(cerr, false); cerr << " left\n";
197 if (Cursor_.size() <= 1)
199 if (par()->asScriptInset())
200 par()->asScriptInset()->removeEmptyScripts();
206 bool MathCursor::popRight()
208 //cerr << "Leaving atom "; par()->write(cerr, false); cerr << " right\n";
209 if (Cursor_.size() <= 1)
211 if (par()->asScriptInset())
212 par()->asScriptInset()->removeEmptyScripts();
221 void MathCursor::dump(char const * what) const
223 lyxerr << "MC: " << what << "\n";
224 lyxerr << " Cursor: " << Cursor_.size() << "\n";
225 for (unsigned i = 0; i < Cursor_.size(); ++i)
226 lyxerr << " i: " << i << " " << Cursor_[i] << "\n";
227 lyxerr << " Anchor: " << Anchor_.size() << "\n";
228 for (unsigned i = 0; i < Anchor_.size(); ++i)
229 lyxerr << " i: " << i << " " << Anchor_[i] << "\n";
230 lyxerr << " sel: " << selection_ << "\n";
233 void MathCursor::dump(char const *) const {}
237 UpdatableInset * MathCursor::asHyperActiveInset() const
239 return par()->asHyperActiveInset();
243 bool MathCursor::isInside(MathInset const * p) const
245 for (unsigned i = 0; i < Cursor_.size(); ++i)
246 if (Cursor_[i].par_ == p)
252 bool MathCursor::openable(MathAtom const & t, bool sel) const
254 if (t->isHyperActive())
260 if (t->asScriptInset())
264 // we can't move into anything new during selection
265 if (Cursor_.size() == Anchor_.size())
267 if (t.nucleus() != Anchor_[Cursor_.size()].par_)
274 bool MathCursor::posLeft()
283 bool MathCursor::posRight()
292 bool MathCursor::left(bool sel)
297 lastcode_ = LM_TC_VAR;
301 lastcode_ = LM_TC_VAR;
303 if (hasPrevAtom() && openable(prevAtom(), sel)) {
304 if (prevAtom()->isHyperActive()) {
305 lyxerr << "entering hyperactive inset\n";
307 pushRight(prevAtom());
311 return posLeft() || idxLeft() || popLeft() || selection_;
315 bool MathCursor::right(bool sel)
320 lastcode_ = LM_TC_VAR;
324 lastcode_ = LM_TC_VAR;
326 if (hasNextAtom() && openable(nextAtom(), sel)) {
327 if (nextAtom()->isHyperActive()) {
328 lyxerr << "entering hyperactive inset\n";
331 nextAtom()->edit(formula()->view(), x, y, 0);
333 pushLeft(nextAtom());
337 return posRight() || idxRight() || popRight() || selection_;
341 void MathCursor::first()
344 pushLeft(formula_->par());
348 void MathCursor::last()
355 bool positionable(MathCursor::cursor_type const & cursor,
356 MathCursor::cursor_type const & anchor)
358 // avoid deeper nested insets when selecting
359 if (cursor.size() > anchor.size())
362 // anchor might be deeper, should have same path then
363 for (MathCursor::cursor_type::size_type i = 0; i < cursor.size(); ++i)
364 if (cursor[i].par_ != anchor[i].par_)
367 // position should be ok.
372 void MathCursor::setPos(int x, int y)
375 bool res = bruteFind(x, y,
376 formula()->xlow(), formula()->xhigh(),
377 formula()->ylow(), formula()->yhigh());
379 // this ccan happen on creation of "math-display"
388 void MathCursor::home(bool sel)
393 lastcode_ = LM_TC_VAR;
394 if (!par()->idxHome(idx(), pos()))
400 void MathCursor::end(bool sel)
405 lastcode_ = LM_TC_VAR;
406 if (!par()->idxEnd(idx(), pos()))
412 void MathCursor::plainErase()
414 array().erase(pos());
418 void MathCursor::plainInsert(MathAtom const & t)
420 array().insert(pos(), t);
425 void MathCursor::insert(char c, MathTextCodes t)
427 //lyxerr << "inserting '" << c << "'\n";
428 plainInsert(MathAtom(new MathCharInset(c, t)));
432 void MathCursor::insert(MathAtom const & t)
447 void MathCursor::niceInsert(MathAtom const & t)
450 insert(t); // inserting invalidates the pointer!
451 MathAtom const & p = prevAtom();
454 right(); // do not push for e.g. MathSymbolInset
460 void MathCursor::insert(MathArray const & ar)
466 array().insert(pos(), ar);
471 void MathCursor::paste(MathArray const & ar)
475 array().insert(pos(), ar);
480 void MathCursor::backspace()
492 MathScriptInset * p = prevAtom()->asScriptInset();
494 p->removeScript(p->hasUp());
495 // Don't delete if there is anything left
496 if (p->hasUp() || p->hasDown())
505 void MathCursor::erase()
515 // delete empty cells if necessary
516 if (array().empty()) {
519 par()->idxDelete(idx(), popit, removeit);
520 if (popit && popLeft() && removeit)
528 MathScriptInset * p = nextAtom()->asScriptInset();
530 p->removeScript(p->hasUp());
531 // Don't delete if there is anything left
532 if (p->hasUp() || p->hasDown())
540 void MathCursor::delLine()
549 if (par()->nrows() > 1) {
550 // grid are the only things with more than one row...
551 lyx::Assert(par()->asGridInset());
552 par()->asGridInset()->delRow(hullRow());
555 if (idx() > par()->nargs())
556 idx() = par()->nargs();
563 bool MathCursor::up(bool sel)
568 cursor_type save = Cursor_;
576 bool MathCursor::down(bool sel)
581 cursor_type save = Cursor_;
589 bool MathCursor::toggleLimits()
593 MathScriptInset * t = nextAtom()->asScriptInset();
596 int old = t->limits();
597 t->limits(old < 0 ? 1 : -1);
598 return old != t->limits();
602 void MathCursor::macroModeClose()
604 string s = macroName();
606 size_type old = pos();
608 array().erase(pos(), old);
614 int MathCursor::macroNamePos() const
616 for (int i = pos() - 1; i >= 0; --i) {
617 MathAtom & p = array().at(i);
618 if (p->code() == LM_TC_TEX && p->getChar() == '\\')
625 string MathCursor::macroName() const
628 for (int i = macroNamePos(); i >= 0 && i < int(pos()); ++i)
629 s += array().at(i)->getChar();
634 void MathCursor::selCopy()
638 theSelection.grab(*this);
644 void MathCursor::selCut()
648 theSelection.grab(*this);
649 theSelection.erase(*this);
652 theSelection.clear();
657 void MathCursor::selDel()
661 theSelection.erase(*this);
669 void MathCursor::selPaste()
672 theSelection.paste(*this);
673 //theSelection.grab(*this);
678 void MathCursor::selHandle(bool sel)
680 if (sel == selection_)
682 //theSelection.clear();
688 void MathCursor::selStart()
691 //theSelection.clear();
698 void MathCursor::selClear()
706 void MathCursor::selGet(MathArray & ar)
712 theSelection.grab(*this);
713 ar = theSelection.glue();
718 void MathCursor::drawSelection(Painter & pain) const
725 getSelection(i1, i2);
727 if (i1.idx_ == i2.idx_) {
728 MathXArray & c = i1.xcell();
729 int x1 = c.xo() + c.pos2x(i1.pos_);
730 int y1 = c.yo() - c.ascent();
731 int x2 = c.xo() + c.pos2x(i2.pos_);
732 int y2 = c.yo() + c.descent();
733 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
735 std::vector<MathInset::idx_type> indices
736 = i1.par_->idxBetween(i1.idx_, i2.idx_);
737 for (unsigned i = 0; i < indices.size(); ++i) {
738 MathXArray & c = i1.xcell(indices[i]);
740 int y1 = c.yo() - c.ascent();
741 int x2 = c.xo() + c.width();
742 int y2 = c.yo() + c.descent();
743 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
748 // draw anchor if different from selection boundary
749 MathCursorPos anc = Anchor_.back();
750 if (anc != i1 && anc != i2) {
751 MathXArray & c = anc.xcell();
752 int x = c.xo() + c.pos2x(anc.pos_);
753 int y1 = c.yo() - c.ascent();
754 int y2 = c.yo() + c.descent();
755 pain.line(x, y1, x, y2, LColor::math);
761 void MathCursor::handleFont(MathTextCodes t)
767 getSelection(i1, i2);
768 if (i1.idx_ == i2.idx_) {
769 MathArray & ar = i1.cell();
770 for (MathInset::pos_type pos = i1.pos_; pos != i2.pos_; ++pos)
771 ar.at(pos)->handleFont(t);
774 lastcode_ = (lastcode_ == t) ? LM_TC_VAR : t;
778 void MathCursor::handleDelim(string const & l, string const & r)
780 handleNest(new MathDelimInset(l, r));
784 void MathCursor::handleNest(MathInset * p)
788 p->cell(0) = theSelection.glue();
790 insert(MathAtom(p)); // this invalidates p!
791 pushRight(prevAtom());
795 void MathCursor::getPos(int & x, int & y)
798 #warning This should probably take cellXOffset and cellYOffset into account
800 x = xarray().xo() + xarray().pos2x(pos());
805 MathInset * MathCursor::par() const
807 return cursor().par_;
811 InsetFormulaBase * MathCursor::formula()
817 MathCursor::idx_type MathCursor::idx() const
819 return cursor().idx_;
823 MathCursor::idx_type & MathCursor::idx()
825 return cursor().idx_;
829 MathCursor::pos_type MathCursor::pos() const
831 return cursor().pos_;
835 MathCursor::pos_type & MathCursor::pos()
837 return cursor().pos_;
841 bool MathCursor::inMacroMode() const
843 return macroNamePos() != -1;
847 bool MathCursor::selection() const
853 MathGridInset * MathCursor::enclosingGrid(MathCursor::idx_type & idx) const
855 for (int i = Cursor_.size() - 1; i >= 0; --i) {
856 MathGridInset * p = Cursor_[i].par_->asGridInset();
858 idx = Cursor_[i].idx_;
866 void MathCursor::pullArg(bool goright)
869 MathArray a = array();
871 MathScriptInset const * p = par()->asScriptInset();
873 // special handling for scripts
874 const bool up = p->hasUp();
876 MathScriptInset * q = nextAtom()->asScriptInset();
880 array().insert(pos(), a);
886 array().insert(pos(), a);
893 void MathCursor::normalize()
897 MathIterator it = ibegin(formula()->par().nucleus());
898 MathIterator et = iend(formula()->par().nucleus());
899 for ( ; it != et; ++it)
900 if (it.par()->asBoxInset())
901 it.par()->asBoxInset()->rebreak();
904 if (idx() >= par()->nargs()) {
905 lyxerr << "this should not really happen - 1: "
906 << idx() << " " << par()->nargs() << "\n";
909 idx() = min(idx(), par()->nargs() - 1);
911 if (pos() > size()) {
912 lyxerr << "this should not really happen - 2: "
913 << pos() << " " << size() << " in idx: " << idx()
915 WriteStream wi(lyxerr, false);
920 pos() = min(pos(), size());
924 MathCursor::size_type MathCursor::size() const
926 return array().size();
930 MathCursor::col_type MathCursor::hullCol() const
932 return Cursor_[0].par_->asGridInset()->col(Cursor_[0].idx_);
936 MathCursor::row_type MathCursor::hullRow() const
938 return Cursor_[0].par_->asGridInset()->row(Cursor_[0].idx_);
942 bool MathCursor::hasPrevAtom() const
948 bool MathCursor::hasNextAtom() const
950 return pos() < size();
954 MathAtom const & MathCursor::prevAtom() const
956 lyx::Assert(pos() > 0);
957 return array().at(pos() - 1);
961 MathAtom & MathCursor::prevAtom()
963 lyx::Assert(pos() > 0);
964 return array().at(pos() - 1);
968 MathAtom const & MathCursor::nextAtom() const
970 lyx::Assert(pos() < size());
971 return array().at(pos());
975 MathAtom & MathCursor::nextAtom()
977 lyx::Assert(pos() < size());
978 return array().at(pos());
982 MathArray & MathCursor::array() const
984 static MathArray dummy;
986 if (idx() >= par()->nargs()) {
987 lyxerr << "############ idx_ " << idx() << " not valid\n";
991 if (Cursor_.size() == 0) {
992 lyxerr << "############ Cursor_.size() == 0 not valid\n";
996 return cursor().cell();
1000 MathXArray & MathCursor::xarray() const
1002 static MathXArray dummy;
1004 if (Cursor_.size() == 0) {
1005 lyxerr << "############ Cursor_.size() == 0 not valid\n";
1009 return cursor().xcell();
1013 void MathCursor::idxNext()
1015 par()->idxNext(idx(), pos());
1019 void MathCursor::idxPrev()
1021 par()->idxPrev(idx(), pos());
1025 void MathCursor::splitCell()
1027 if (idx() + 1 == par()->nargs())
1029 MathArray ar = array();
1031 array().erase(pos(), size());
1034 array().insert(0, ar);
1038 void MathCursor::breakLine()
1040 // leave inner cells
1044 MathHullInset * p = formula()->par()->asHullInset();
1048 if (p->getType() == LM_OT_SIMPLE || p->getType() == LM_OT_EQUATION) {
1049 p->mutate(LM_OT_EQNARRAY);
1053 p->addRow(hullRow());
1056 const row_type r = hullRow();
1057 for (col_type c = hullCol() + 1; c < p->ncols(); ++c)
1058 p->cell(p->index(r, c)).swap(p->cell(p->index(r + 1, c)));
1062 p->cell(idx()).swap(p->cell(idx() + p->ncols() - 1));
1067 //void MathCursor::readLine(MathArray & ar) const
1069 // idx_type base = row() * par()->ncols();
1070 // for (idx_type off = 0; off < par()->ncols(); ++off)
1071 // ar.push_back(par()->cell(base + off));
1075 char MathCursor::valign() const
1078 MathGridInset * p = enclosingGrid(idx);
1079 return p ? p->valign() : '\0';
1083 char MathCursor::halign() const
1086 MathGridInset * p = enclosingGrid(idx);
1087 return p ? p->halign(idx % p->ncols()) : '\0';
1091 void MathCursor::getSelection(MathCursorPos & i1, MathCursorPos & i2) const
1093 MathCursorPos anc = normalAnchor();
1094 if (anc < cursor()) {
1104 MathCursorPos & MathCursor::cursor()
1106 lyx::Assert(Cursor_.size());
1107 return Cursor_.back();
1111 MathCursorPos const & MathCursor::cursor() const
1113 lyx::Assert(Cursor_.size());
1114 return Cursor_.back();
1118 bool MathCursor::goUpDown(bool up)
1120 int xlow, xhigh, ylow, yhigh;
1125 // try current cell first
1126 xarray().boundingBox(xlow, xhigh, ylow, yhigh);
1131 if (bruteFind(xo, yo, xlow, xhigh, ylow, yhigh))
1134 // try to find an inset that knows better then we
1136 // we found a cell that think something "below" us.
1138 if (par()->idxUp(idx()))
1141 if (par()->idxDown(idx()))
1146 // no such inset found, just take something "above"
1151 up ? formula()->ylow() : yo + 4,
1152 up ? yo - 4 : formula()->yhigh()
1156 xarray().boundingBox(xlow, xhigh, ylow, yhigh);
1157 bruteFind(xo, yo, xlow, xhigh, ylow, yhigh);
1162 bool MathCursor::bruteFind(int x, int y, int xlow, int xhigh, int ylow, int yhigh)
1164 cursor_type best_cursor;
1165 double best_dist = 1e10;
1167 MathIterator it = ibegin(formula()->par().nucleus());
1168 MathIterator et = iend(formula()->par().nucleus());
1169 for ( ; it != et; ++it) {
1170 // avoid invalid nesting hen selecting
1171 if (selection_ && !positionable(it.cursor(), Anchor_))
1173 int xo = it.position().xpos();
1174 int yo = it.position().ypos();
1175 if (xlow - 2 <= xo && xo <= xhigh + 2 &&
1176 ylow - 2 <= yo && yo <= yhigh + 2)
1178 double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
1179 if (d < best_dist) {
1181 best_cursor = it.cursor();
1185 if (best_dist < 1e10)
1186 Cursor_ = best_cursor;
1187 return best_dist < 1e10;
1191 bool MathCursor::idxLeft()
1193 return par()->idxLeft(idx(), pos());
1197 bool MathCursor::idxRight()
1199 return par()->idxRight(idx(), pos());
1203 bool MathCursor::interpret(string const & s)
1205 //lyxerr << "interpret 1: '" << s << "'\n";
1210 return interpret(s[0]);
1212 //lyxerr << "char: '" << s[0] << "' int: " << int(s[0]) << endl;
1213 //owner_->getIntl()->getTrans().TranslateAndInsert(s[0], lt);
1214 //lyxerr << "trans: '" << s[0] << "' int: " << int(s[0]) << endl;
1216 if (s.size() >= 5 && s.substr(0, 5) == "cases") {
1218 istringstream is(s.substr(5).c_str());
1220 n = std::max(1u, n);
1221 niceInsert(MathAtom(new MathCasesInset(n)));
1225 if (s.size() >= 6 && s.substr(0, 6) == "matrix") {
1230 istringstream is(s.substr(6).c_str());
1231 is >> m >> n >> v_align >> h_align;
1232 m = std::max(1u, m);
1233 n = std::max(1u, n);
1235 niceInsert(MathAtom(new MathArrayInset(m, n, v_align[0], h_align)));
1239 if (s.size() >= 7 && s.substr(0, 7) == "replace") {
1241 istringstream is(s.substr(7).c_str());
1244 mathed_parse_cell(rep.from, from);
1245 mathed_parse_cell(rep.to, to);
1246 lyxerr << "replacing '" << from << "' with '" << to << "'\n";
1247 par()->replace(rep);
1251 if (s == "\\over" || s == "\\choose" || s == "\\atop") {
1252 MathArray ar = array();
1253 MathAtom t(createMathInset(s.substr(1)));
1254 t->asNestInset()->cell(0).swap(array());
1262 latexkeys const * l = in_word_set(s.substr(1));
1263 if (l && (l->token == LM_TK_FONT || l->token == LM_TK_OLDFONT)) {
1264 lastcode_ = static_cast<MathTextCodes>(l->id);
1268 niceInsert(createMathInset(s.substr(1)));
1272 bool MathCursor::script(bool up)
1276 if (hasPrevAtom() && prevAtom()->asScriptInset()) {
1277 prevAtom()->asScriptInset()->ensure(up);
1278 pushRight(prevAtom());
1281 } else if (hasNextAtom() && nextAtom()->asScriptInset()) {
1282 nextAtom()->asScriptInset()->ensure(up);
1283 pushLeft(nextAtom());
1287 plainInsert(MathAtom(new MathScriptInset(up)));
1288 prevAtom()->asScriptInset()->ensure(up);
1289 pushRight(prevAtom());
1299 bool MathCursor::interpret(char c)
1301 //lyxerr << "interpret 2: '" << c << "'\n";
1303 if (inMacroMode()) {
1304 string name = macroName();
1306 if (name == "\\" && c == '#') {
1307 insert(c, LM_TC_TEX);
1311 if (name == "\\" && c == '\\') {
1313 interpret("\\backslash");
1317 if (name == "\\#" && '1' <= c && c <= '9') {
1318 insert(c, LM_TC_TEX);
1324 insert(c, LM_TC_TEX);
1329 insert(c, LM_TC_TEX);
1342 // fall through in the other cases
1345 if (lastcode_ == LM_TC_TEXTRM || par()->asBoxInset()) {
1346 // suppress direct insertion of two spaces in a row
1347 // the still allows typing '<space>a<space>' and deleting the 'a', but
1348 // it is better than nothing...
1349 if (c == ' ' && hasPrevAtom() && prevAtom()->getChar() == ' ')
1351 insert(c, LM_TC_TEXTRM);
1356 if (hasPrevAtom() && prevAtom()->asSpaceInset()) {
1357 prevAtom()->asSpaceInset()->incSpace();
1362 // if are at the very end, leave the formula
1363 return pos() != size();
1367 if (strchr("{}", c)) {
1368 insert(c, LM_TC_TEX);
1374 niceInsert(MathAtom(new MathBraceInset));
1382 if (strchr("#$%", c)) {
1383 insert(MathAtom(new MathSpecialCharInset(c)));
1384 lastcode_ = LM_TC_VAR;
1388 if (isalpha(c) && lastcode_ == LM_TC_GREEK) {
1389 insert(c, LM_TC_VAR);
1393 if (isalpha(c) && lastcode_ == LM_TC_GREEK1) {
1394 insert(c, LM_TC_VAR);
1395 lastcode_ = LM_TC_VAR;
1400 insert(c, LM_TC_TEX);
1401 //bv->owner()->message(_("TeX mode"));
1405 // no special circumstances, so insert the character without any fuss
1406 insert(c, lastcode_);
1407 lastcode_ = LM_TC_MIN;
1413 MathCursorPos MathCursor::normalAnchor() const
1415 if (Anchor_.size() < Cursor_.size()) {
1417 lyxerr << "unusual Anchor size\n";
1420 //lyx::Assert(Anchor_.size() >= Cursor_.size());
1421 // use Anchor on the same level as Cursor
1422 MathCursorPos normal = Anchor_[Cursor_.size() - 1];
1423 if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) {
1424 // anchor is behind cursor -> move anchor behind the inset
1431 void MathCursor::stripFromLastEqualSign()
1433 // find position of last '=' in the array
1434 MathArray & ar = cursor().cell();
1435 MathArray::const_iterator et = ar.end();
1436 for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it)
1437 if ((*it)->getChar() == '=')
1440 // delete everything behind this position
1441 ar.erase(et - ar.begin(), ar.size());