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 void grab(MathCursor const & cursor)
66 cursor.getSelection(i1, i2);
67 if (i1.idx_ == i2.idx_)
68 data_.push_back(MathArray(i1.cell(), i1.pos_, i2.pos_));
70 std::vector<MathInset::idx_type> indices =
71 i1.par_->idxBetween(i1.idx_, i2.idx_);
72 for (MathInset::idx_type i = 0; i < indices.size(); ++i)
73 data_.push_back(i1.cell(indices[i]));
77 void erase(MathCursor & cursor)
81 cursor.getSelection(i1, i2);
82 if (i1.idx_ == i2.idx_)
83 i1.cell().erase(i1.pos_, i2.pos_);
85 std::vector<MathInset::idx_type> indices =
86 i1.par_->idxBetween(i1.idx_, i2.idx_);
87 for (unsigned i = 0; i < indices.size(); ++i)
88 i1.cell(indices[i]).erase();
93 void paste(MathCursor & cursor) const
95 MathArray ar = glue();
99 // glues selection to one cell
100 MathArray glue() const
103 for (unsigned i = 0; i < data_.size(); ++i)
104 ar.push_back(data_[i]);
113 std::vector<MathArray> data_;
117 Selection theSelection;
124 MathCursor::MathCursor(InsetFormulaBase * formula, bool left)
125 : formula_(formula), lastcode_(LM_TC_VAR), selection_(false)
127 left ? first() : last();
131 void MathCursor::push(MathAtom & t)
133 Cursor_.push_back(MathCursorPos(t.nucleus()));
137 void MathCursor::pushLeft(MathAtom & t)
139 //cerr << "Entering atom "; t->write(cerr, false); cerr << " left\n";
141 t->idxFirst(idx(), pos());
145 void MathCursor::pushRight(MathAtom & t)
147 //cerr << "Entering atom "; t->write(cerr, false); cerr << " right\n";
150 t->idxLast(idx(), pos());
154 bool MathCursor::popLeft()
156 //cerr << "Leaving atom "; par()->write(cerr, false); cerr << " left\n";
157 if (Cursor_.size() <= 1)
160 // nextInset()->removeEmptyScripts();
163 // nextAtom()->removeEmptyScripts();
168 bool MathCursor::popRight()
170 //cerr << "Leaving atom "; par()->write(cerr, false); cerr << " right\n";
171 if (Cursor_.size() <= 1)
174 // nextInset()->removeEmptyScripts();
177 // nextInset()->removeEmptyScripts();
185 void MathCursor::dump(char const * what) const
187 lyxerr << "MC: " << what << "\n";
188 lyxerr << " Cursor: " << Cursor_.size() << "\n";
189 for (unsigned i = 0; i < Cursor_.size(); ++i)
190 lyxerr << " i: " << i << " " << Cursor_[i] << "\n";
191 lyxerr << " Anchor: " << Anchor_.size() << "\n";
192 for (unsigned i = 0; i < Anchor_.size(); ++i)
193 lyxerr << " i: " << i << " " << Anchor_[i] << "\n";
194 lyxerr << " sel: " << selection_ << "\n";
197 void MathCursor::dump(char const *) const {}
201 UpdatableInset * MathCursor::asHyperActiveInset() const
203 return par()->asHyperActiveInset();
207 bool MathCursor::isInside(MathInset const * p) const
209 for (unsigned i = 0; i < Cursor_.size(); ++i)
210 if (Cursor_[i].par_ == p)
216 bool MathCursor::openable(MathAtom const & t, bool sel) const
218 if (t->isHyperActive())
224 if (t->asScriptInset())
228 // we can't move into anything new during selection
229 if (Cursor_.size() == Anchor_.size())
231 if (t.nucleus() != Anchor_[Cursor_.size()].par_)
238 bool MathCursor::posLeft()
247 bool MathCursor::posRight()
256 bool MathCursor::left(bool sel)
261 lastcode_ = LM_TC_VAR;
265 lastcode_ = LM_TC_VAR;
267 if (hasPrevAtom() && openable(prevAtom(), sel)) {
268 if (prevAtom()->isHyperActive()) {
269 lyxerr << "entering hyperactive inset\n";
271 pushRight(prevAtom());
275 return posLeft() || idxLeft() || popLeft() || selection_;
279 bool MathCursor::right(bool sel)
284 lastcode_ = LM_TC_VAR;
288 lastcode_ = LM_TC_VAR;
290 if (hasNextAtom() && openable(nextAtom(), sel)) {
291 if (nextAtom()->isHyperActive()) {
292 lyxerr << "entering hyperactive inset\n";
295 nextAtom()->edit(formula()->view(), x, y, 0);
297 pushLeft(nextAtom());
301 return posRight() || idxRight() || popRight() || selection_;
305 void MathCursor::first()
308 pushLeft(formula_->par());
312 void MathCursor::last()
319 bool positionable(MathCursor::cursor_type const & cursor,
320 MathCursor::cursor_type const & anchor)
322 // avoid deeper nested insets when selecting
323 if (cursor.size() > anchor.size())
326 // anchor might be deeper, should have same path then
327 for (MathCursor::cursor_type::size_type i = 0; i < cursor.size(); ++i)
328 if (cursor[i].par_ != anchor[i].par_)
331 // position should be ok.
336 void MathCursor::setPos(int x, int y)
339 cursor_type best_cursor;
340 double best_dist = 1e10;
342 MathIterator it = ibegin(formula()->par().nucleus());
343 MathIterator et = iend(formula()->par().nucleus());
344 for ( ; it != et; ++it) {
345 //lyxerr << "*it: " << *it << " *et: " << *et << "\n";
346 // avoid invalid nesting hen selecting
347 if (selection_ && !positionable(it.cursor(), Anchor_))
349 //lyxerr << it.position() << endl;
350 int xo = it.position().xpos();
351 int yo = it.position().ypos();
352 double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
355 best_cursor = it.cursor();
358 if (best_dist < 1e10)
359 Cursor_ = best_cursor;
360 //lyxerr << "x: " << x << " y: " << y << " dist: " << best_dist << "\n";
361 lyx::Assert(Cursor_.size());
367 void MathCursor::home(bool sel)
372 lastcode_ = LM_TC_VAR;
373 if (!par()->idxHome(idx(), pos()))
379 void MathCursor::end(bool sel)
384 lastcode_ = LM_TC_VAR;
385 if (!par()->idxEnd(idx(), pos()))
391 void MathCursor::plainErase()
393 array().erase(pos());
397 void MathCursor::plainInsert(MathAtom const & t)
399 array().insert(pos(), t);
404 void MathCursor::insert(char c, MathTextCodes t)
406 //lyxerr << "inserting '" << c << "'\n";
407 plainInsert(MathAtom(new MathCharInset(c, t)));
411 void MathCursor::insert(MathAtom const & t)
426 void MathCursor::niceInsert(MathAtom const & t)
429 insert(t); // inserting invalidates the pointer!
430 MathAtom const & p = prevAtom();
433 right(); // do not push for e.g. MathSymbolInset
439 void MathCursor::insert(MathArray const & ar)
445 array().insert(pos(), ar);
450 void MathCursor::paste(MathArray const & ar)
454 array().insert(pos(), ar);
459 void MathCursor::backspace()
471 MathScriptInset * p = prevAtom()->asScriptInset();
473 p->removeScript(p->hasUp());
474 // Don't delete if there is anything left
475 if (p->hasUp() || p->hasDown())
484 void MathCursor::erase()
494 // delete empty cells if necessary
495 if (array().empty()) {
498 par()->idxDelete(idx(), popit, removeit);
499 if (popit && popLeft() && removeit)
507 MathScriptInset * p = nextAtom()->asScriptInset();
509 p->removeScript(p->hasUp());
510 // Don't delete if there is anything left
511 if (p->hasUp() || p->hasDown())
519 void MathCursor::delLine()
528 if (par()->nrows() > 1) {
529 // grid are the only things with more than one row...
530 lyx::Assert(par()->asGridInset());
531 par()->asGridInset()->delRow(hullRow());
534 if (idx() > par()->nargs())
535 idx() = par()->nargs();
542 bool MathCursor::up(bool sel)
549 MathInset::idx_type i = 0;
550 MathInset::pos_type p = 0;
552 // check whether we could move into the inset
553 if (hasPrevAtom() && prevAtom()->idxLastUp(i, p)) {
554 pushRight(prevAtom());
560 if (hasNextAtom() && nextAtom()->idxFirstUp(i, p)) {
561 pushLeft(nextAtom());
568 cursor_type save = Cursor_;
576 bool MathCursor::down(bool sel)
583 MathInset::idx_type i = 0;
584 MathInset::pos_type p = 0;
586 // check whether we could move into the inset
587 if (hasPrevAtom() && prevAtom()->idxLastDown(i, p)) {
588 pushRight(prevAtom());
594 if (hasNextAtom() && nextAtom()->idxFirstDown(i, p)) {
595 pushLeft(nextAtom());
602 cursor_type save = Cursor_;
610 bool MathCursor::toggleLimits()
614 MathScriptInset * t = nextAtom()->asScriptInset();
617 int old = t->limits();
618 t->limits(old < 0 ? 1 : -1);
619 return old != t->limits();
623 void MathCursor::macroModeClose()
625 string s = macroName();
627 size_type old = pos();
629 array().erase(pos(), old);
635 int MathCursor::macroNamePos() const
637 for (int i = pos() - 1; i >= 0; --i) {
638 MathAtom & p = array().at(i);
639 if (p->code() == LM_TC_TEX && p->getChar() == '\\')
646 string MathCursor::macroName() const
649 for (int i = macroNamePos(); i >= 0 && i < int(pos()); ++i)
650 s += array().at(i)->getChar();
655 void MathCursor::selCopy()
659 theSelection.grab(*this);
665 void MathCursor::selCut()
669 theSelection.grab(*this);
670 theSelection.erase(*this);
673 theSelection.clear();
678 void MathCursor::selDel()
682 theSelection.erase(*this);
690 void MathCursor::selPaste()
693 theSelection.paste(*this);
694 //theSelection.grab(*this);
699 void MathCursor::selHandle(bool sel)
701 if (sel == selection_)
703 //theSelection.clear();
709 void MathCursor::selStart()
712 //theSelection.clear();
719 void MathCursor::selClear()
727 void MathCursor::selGet(MathArray & ar)
733 theSelection.grab(*this);
734 ar = theSelection.glue();
739 void MathCursor::drawSelection(Painter & pain) const
746 getSelection(i1, i2);
748 if (i1.idx_ == i2.idx_) {
749 MathXArray & c = i1.xcell();
750 int x1 = c.xo() + c.pos2x(i1.pos_);
751 int y1 = c.yo() - c.ascent();
752 int x2 = c.xo() + c.pos2x(i2.pos_);
753 int y2 = c.yo() + c.descent();
754 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
756 std::vector<MathInset::idx_type> indices
757 = i1.par_->idxBetween(i1.idx_, i2.idx_);
758 for (unsigned i = 0; i < indices.size(); ++i) {
759 MathXArray & c = i1.xcell(indices[i]);
761 int y1 = c.yo() - c.ascent();
762 int x2 = c.xo() + c.width();
763 int y2 = c.yo() + c.descent();
764 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
769 // draw anchor if different from selection boundary
770 MathCursorPos anc = Anchor_.back();
771 if (anc != i1 && anc != i2) {
772 MathXArray & c = anc.xcell();
773 int x = c.xo() + c.pos2x(anc.pos_);
774 int y1 = c.yo() - c.ascent();
775 int y2 = c.yo() + c.descent();
776 pain.line(x, y1, x, y2, LColor::math);
782 void MathCursor::handleFont(MathTextCodes t)
788 getSelection(i1, i2);
789 if (i1.idx_ == i2.idx_) {
790 MathArray & ar = i1.cell();
791 for (MathInset::pos_type pos = i1.pos_; pos != i2.pos_; ++pos)
792 ar.at(pos)->handleFont(t);
795 lastcode_ = (lastcode_ == t) ? LM_TC_VAR : t;
799 void MathCursor::handleDelim(string const & l, string const & r)
801 handleNest(new MathDelimInset(l, r));
805 void MathCursor::handleNest(MathInset * p)
809 p->cell(0) = theSelection.glue();
811 insert(MathAtom(p)); // this invalidates p!
812 pushRight(prevAtom());
816 void MathCursor::getPos(int & x, int & y)
819 #warning This should probably take cellXOffset and cellYOffset into account
821 x = xarray().xo() + xarray().pos2x(pos());
826 MathInset * MathCursor::par() const
828 return cursor().par_;
832 InsetFormulaBase * MathCursor::formula()
838 MathCursor::idx_type MathCursor::idx() const
840 return cursor().idx_;
844 MathCursor::idx_type & MathCursor::idx()
846 return cursor().idx_;
850 MathCursor::pos_type MathCursor::pos() const
852 return cursor().pos_;
856 MathCursor::pos_type & MathCursor::pos()
858 return cursor().pos_;
862 bool MathCursor::inMacroMode() const
864 return macroNamePos() != -1;
868 bool MathCursor::selection() const
874 MathGridInset * MathCursor::enclosingGrid(MathCursor::idx_type & idx) const
876 for (int i = Cursor_.size() - 1; i >= 0; --i) {
877 MathGridInset * p = Cursor_[i].par_->asGridInset();
879 idx = Cursor_[i].idx_;
887 void MathCursor::pullArg(bool goright)
890 MathArray a = array();
892 MathScriptInset const * p = par()->asScriptInset();
894 // special handling for scripts
895 const bool up = p->hasUp();
897 MathScriptInset * q = nextAtom()->asScriptInset();
901 array().insert(pos(), a);
907 array().insert(pos(), a);
914 void MathCursor::normalize() const
917 #warning This is evil!
919 MathCursor * it = const_cast<MathCursor *>(this);
921 if (idx() >= par()->nargs()) {
922 lyxerr << "this should not really happen - 1: "
923 << idx() << " " << par()->nargs() << "\n";
926 it->idx() = min(idx(), par()->nargs() - 1);
928 if (pos() > size()) {
929 lyxerr << "this should not really happen - 2: "
930 << pos() << " " << size() << " in idx: " << it->idx()
932 WriteStream wi(lyxerr, false);
933 it->par()->write(wi);
937 it->pos() = min(pos(), size());
941 MathCursor::size_type MathCursor::size() const
943 return array().size();
947 MathCursor::col_type MathCursor::hullCol() const
949 return Cursor_[0].par_->asGridInset()->col(Cursor_[0].idx_);
953 MathCursor::row_type MathCursor::hullRow() const
955 return Cursor_[0].par_->asGridInset()->row(Cursor_[0].idx_);
959 bool MathCursor::hasPrevAtom() const
965 bool MathCursor::hasNextAtom() const
967 return pos() < size();
971 MathAtom const & MathCursor::prevAtom() const
973 lyx::Assert(pos() > 0);
974 return array().at(pos() - 1);
978 MathAtom & MathCursor::prevAtom()
980 lyx::Assert(pos() > 0);
981 return array().at(pos() - 1);
985 MathAtom const & MathCursor::nextAtom() const
987 lyx::Assert(pos() < size());
988 return array().at(pos());
992 MathAtom & MathCursor::nextAtom()
994 lyx::Assert(pos() < size());
995 return array().at(pos());
999 MathArray & MathCursor::array() const
1001 static MathArray dummy;
1003 if (idx() >= par()->nargs()) {
1004 lyxerr << "############ idx_ " << idx() << " not valid\n";
1008 if (Cursor_.size() == 0) {
1009 lyxerr << "############ Cursor_.size() == 0 not valid\n";
1013 return cursor().cell();
1017 MathXArray & MathCursor::xarray() const
1019 static MathXArray dummy;
1021 if (Cursor_.size() == 0) {
1022 lyxerr << "############ Cursor_.size() == 0 not valid\n";
1026 return cursor().xcell();
1030 void MathCursor::idxNext()
1032 par()->idxNext(idx(), pos());
1036 void MathCursor::idxPrev()
1038 par()->idxPrev(idx(), pos());
1042 void MathCursor::splitCell()
1044 if (idx() + 1 == par()->nargs())
1046 MathArray ar = array();
1048 array().erase(pos(), size());
1051 array().insert(0, ar);
1055 void MathCursor::breakLine()
1057 // leave inner cells
1061 MathHullInset * p = formula()->par()->asHullInset();
1065 if (p->getType() == LM_OT_SIMPLE || p->getType() == LM_OT_EQUATION) {
1066 p->mutate(LM_OT_EQNARRAY);
1070 p->addRow(hullRow());
1073 const row_type r = hullRow();
1074 for (col_type c = hullCol() + 1; c < p->ncols(); ++c)
1075 p->cell(p->index(r, c)).swap(p->cell(p->index(r + 1, c)));
1079 p->cell(idx()).swap(p->cell(idx() + p->ncols() - 1));
1084 //void MathCursor::readLine(MathArray & ar) const
1086 // idx_type base = row() * par()->ncols();
1087 // for (idx_type off = 0; off < par()->ncols(); ++off)
1088 // ar.push_back(par()->cell(base + off));
1092 char MathCursor::valign() const
1095 MathGridInset * p = enclosingGrid(idx);
1096 return p ? p->valign() : '\0';
1100 char MathCursor::halign() const
1103 MathGridInset * p = enclosingGrid(idx);
1104 return p ? p->halign(idx % p->ncols()) : '\0';
1108 void MathCursor::getSelection(MathCursorPos & i1, MathCursorPos & i2) const
1110 MathCursorPos anc = normalAnchor();
1111 if (anc < cursor()) {
1121 MathCursorPos & MathCursor::cursor()
1123 lyx::Assert(Cursor_.size());
1124 return Cursor_.back();
1128 MathCursorPos const & MathCursor::cursor() const
1130 lyx::Assert(Cursor_.size());
1131 return Cursor_.back();
1135 bool MathCursor::goUpDown(bool up)
1140 // try to find an inset that knows better then we
1142 // we found a cell that think something "below" us.
1144 if (par()->idxUp(idx(), pos()))
1147 if (par()->idxDown(idx(), pos()))
1152 // have reached hull
1157 up ? formula()->ylow() : yo + 4,
1158 up ? yo - 4 : formula()->yhigh()
1162 int xlow, xhigh, ylow, yhigh;
1163 xarray().boundingBox(xlow, xhigh, ylow, yhigh);
1164 bruteFind(xo, yo, xlow, xhigh, ylow, yhigh);
1169 bool MathCursor::bruteFind(int x, int y, int xlow, int xhigh, int ylow, int yhigh)
1171 //lyxerr << "looking at range: "
1172 // << "[" << xlow << "..." << xhigh << "]"
1173 // << " x [" << ylow << "..." << yhigh << "]"
1174 // << " xo: " << x << " yo: " << y << "\n";
1176 cursor_type best_cursor;
1177 double best_dist = 1e10;
1179 MathIterator it = ibegin(formula()->par().nucleus());
1180 MathIterator et = iend(formula()->par().nucleus());
1181 for ( ; it != et; ++it) {
1182 int xo = it.position().xpos();
1183 int yo = it.position().ypos();
1184 if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
1185 double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
1186 if (d < best_dist) {
1188 best_cursor = it.cursor();
1192 if (best_dist < 1e10)
1193 Cursor_ = best_cursor;
1194 return best_dist < 1e10;
1198 bool MathCursor::idxLeft()
1200 return par()->idxLeft(idx(), pos());
1204 bool MathCursor::idxRight()
1206 return par()->idxRight(idx(), pos());
1210 bool MathCursor::interpret(string const & s)
1212 //lyxerr << "interpret 1: '" << s << "'\n";
1217 return interpret(s[0]);
1219 //lyxerr << "char: '" << s[0] << "' int: " << int(s[0]) << endl;
1220 //owner_->getIntl()->getTrans().TranslateAndInsert(s[0], lt);
1221 //lyxerr << "trans: '" << s[0] << "' int: " << int(s[0]) << endl;
1223 if (s.size() >= 5 && s.substr(0, 5) == "cases") {
1225 istringstream is(s.substr(5).c_str());
1227 n = std::max(1u, n);
1228 niceInsert(MathAtom(new MathCasesInset(n)));
1232 if (s.size() >= 6 && s.substr(0, 6) == "matrix") {
1237 istringstream is(s.substr(6).c_str());
1238 is >> m >> n >> v_align >> h_align;
1239 m = std::max(1u, m);
1240 n = std::max(1u, n);
1242 niceInsert(MathAtom(new MathArrayInset(m, n, v_align[0], h_align)));
1246 if (s.size() >= 7 && s.substr(0, 7) == "replace") {
1248 istringstream is(s.substr(7).c_str());
1251 mathed_parse_cell(rep.from, from);
1252 mathed_parse_cell(rep.to, to);
1253 lyxerr << "replacing '" << from << "' with '" << to << "'\n";
1254 par()->replace(rep);
1258 if (s == "\\over" || s == "\\choose" || s == "\\atop") {
1259 MathArray ar = array();
1260 MathAtom t = createMathInset(s.substr(1));
1261 t->asNestInset()->cell(0).swap(array());
1269 latexkeys const * l = in_word_set(s.substr(1));
1270 if (l && (l->token == LM_TK_FONT || l->token == LM_TK_OLDFONT)) {
1271 lastcode_ = static_cast<MathTextCodes>(l->id);
1275 niceInsert(createMathInset(s.substr(1)));
1280 bool MathCursor::interpret(char c)
1282 //lyxerr << "interpret 2: '" << c << "'\n";
1283 if (c == '^' || c == '_') {
1285 const bool up = (c == '^');
1287 if (hasPrevAtom() && prevAtom()->asScriptInset()) {
1288 prevAtom()->asScriptInset()->ensure(up);
1289 pushRight(prevAtom());
1292 } else if (hasNextAtom() && nextAtom()->asScriptInset()) {
1293 nextAtom()->asScriptInset()->ensure(up);
1294 pushLeft(nextAtom());
1298 plainInsert(MathAtom(new MathScriptInset(up)));
1299 prevAtom()->asScriptInset()->ensure(up);
1300 pushRight(prevAtom());
1311 if (inMacroMode()) {
1312 string name = macroName();
1314 if (name == "\\" && c == '#') {
1315 insert(c, LM_TC_TEX);
1319 if (name == "\\" && c == '\\') {
1321 interpret("\\backslash");
1325 if (name == "\\#" && '1' <= c && c <= '9') {
1326 insert(c, LM_TC_TEX);
1332 insert(c, LM_TC_TEX);
1337 insert(c, LM_TC_TEX);
1349 if (lastcode_ == LM_TC_TEXTRM) {
1350 // suppress direct insertion of to spaces in a row
1351 // the still allows typing '<space>a<space>' and deleting the 'a', but
1352 // it is better than nothing
1353 if (c == ' ' && hasPrevAtom() && prevAtom()->getChar() == ' ')
1355 insert(c, LM_TC_TEXTRM);
1360 if (hasPrevAtom() && prevAtom()->asSpaceInset()) {
1361 prevAtom()->asSpaceInset()->incSpace();
1365 if (mathcursor->popRight())
1368 // if are at the very end, leave the formula
1369 return pos() != size();
1373 if (strchr("{}", c)) {
1374 insert(c, LM_TC_TEX);
1380 niceInsert(MathAtom(new MathBraceInset));
1388 if (strchr("#$%", c)) {
1389 insert(MathAtom(new MathSpecialCharInset(c)));
1390 lastcode_ = LM_TC_VAR;
1394 if (isalpha(c) && lastcode_ == LM_TC_GREEK) {
1395 insert(c, LM_TC_VAR);
1399 if (isalpha(c) && lastcode_ == LM_TC_GREEK1) {
1400 insert(c, LM_TC_VAR);
1401 lastcode_ = LM_TC_VAR;
1406 insert(c, LM_TC_TEX);
1407 //bv->owner()->message(_("TeX mode"));
1411 // no special circumstances, so insert the character without any fuss
1412 insert(c, lastcode_);
1413 lastcode_ = LM_TC_MIN;
1419 MathCursorPos MathCursor::normalAnchor() const
1421 lyx::Assert(Anchor_.size() >= Cursor_.size());
1422 // use Anchor on the same level as Cursor
1423 MathCursorPos normal = Anchor_[Cursor_.size() - 1];
1424 if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) {
1425 // anchor is behind cursor -> move anchor behind the inset
1432 void MathCursor::stripFromLastEqualSign()
1434 // find position of last '=' in the array
1435 MathArray & ar = cursor().cell();
1436 MathArray::const_iterator et = ar.end();
1437 for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it)
1438 if ((*it)->getChar() == '=')
1441 // delete everything behind this position
1442 ar.erase(et - ar.begin(), ar.size());