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
29 #include "mathed/support.h"
30 #include "formulabase.h"
31 #include "math_cursor.h"
32 #include "math_arrayinset.h"
33 #include "math_bigopinset.h"
34 #include "math_decorationinset.h"
35 #include "math_deliminset.h"
36 #include "math_dotsinset.h"
37 #include "math_fracinset.h"
38 #include "math_funcinset.h"
39 #include "math_gridinset.h"
40 #include "math_macro.h"
41 #include "math_macroarg.h"
42 #include "math_macrotable.h"
43 #include "math_macrotemplate.h"
44 #include "math_matrixinset.h"
45 #include "math_rootinset.h"
46 #include "math_spaceinset.h"
47 #include "math_sqrtinset.h"
48 #include "support/lstrings.h"
49 #include "math_scriptinset.h"
50 #include "math_parser.h"
57 #define RECTANGULAR_SELECT 1
63 void grab(MathCursor const & cursor)
68 cursor.getSelection(i1, i2);
69 if (i1.idx_ == i2.idx_)
70 data_.push_back(MathArray(i1.cell(), i1.pos_, i2.pos_));
72 #ifdef RECTANGULAR_SELECT
73 std::vector<int> indices = i1.par_->idxBetween(i1.idx_, i2.idx_);
74 for (unsigned i = 0; i < indices.size(); ++i)
75 data_.push_back(i1.cell(indices[i]));
77 data_.push_back(MathArray(i1.cell(), i1.pos_, i1.cell().size()));
78 for (int i = i1.idx_ + 1; i < i2.idx_; ++i)
79 data_.push_back(i1.cell(i));
80 data_.push_back(MathArray(i2.cell(), 0, i2.pos_));
85 void erase(MathCursor & cursor)
89 cursor.getSelection(i1, i2);
90 if (i1.idx_ == i2.idx_) {
91 i1.cell().erase(i1.pos_, i2.pos_);
93 #ifdef RECTANGULAR_SELECT
94 std::vector<int> indices = i1.par_->idxBetween(i1.idx_, i2.idx_);
95 for (unsigned i = 0; i < indices.size(); ++i)
96 i1.cell(indices[i]).erase();
98 i1.cell().erase(i1.pos_, i1.cell().size());
99 for (int i = i1.idx_ + 1; i < i2.idx_; ++i)
101 i2.cell().erase(0, i2.pos_);
103 int from = i1.cell().size() ? i1.idx_ + 1 : i1.idx_;
104 int to = i2.cell().size() ? i2.idx_ : i2.idx_ + 1;
105 i1.par_->idxDeleteRange(from, to);
108 cursor.cursor() = i1;
111 void paste(MathCursor & cursor) const
113 #ifdef RECTANGULAR_SELECT
114 cursor.cursor().cell().push_back(glue());
116 unsigned na = cursor.cursor().par_->nargs();
117 unsigned idx = cursor.cursor().idx_;
118 unsigned end = std::min(idx + data_.size(), na);
119 for (int i = 0; i < end - idx; ++i)
120 cursor.cursor().cell(idx + i).push_back(data_[i]);
121 for (unsigned i = end - idx; i < data_.size(); ++i)
122 cursor.cursor().cell(end - 1).push_back(data_[i]);
126 // glues selection to one cell
127 MathArray glue() const
130 for (unsigned i = 0; i < data_.size(); ++i)
131 ar.push_back(data_[i]);
142 std::vector<MathArray> data_;
146 Selection theSelection;
149 bool IsMacro(short tok, int id)
151 return tok != LM_TK_STACK &&
154 tok != LM_TK_DECORATION &&
155 tok != LM_TK_SPACE &&
157 tok != LM_TK_FUNCLIM &&
158 tok != LM_TK_BIGSYM &&
159 !(tok == LM_TK_SYM && id < 255);
163 std::ostream & operator<<(std::ostream & os, MathCursorPos const & p)
165 os << "(par: " << p.par_ << " idx: " << p.idx_
166 << " pos: " << p.pos_ << ")";
173 MathCursor::MathCursor(InsetFormulaBase * formula)
176 lastcode = LM_TC_MIN;
183 void MathCursor::push(MathInset * par, bool first)
188 par->idxFirst(p.idx_, p.pos_);
190 par->idxLast(p.idx_, p.pos_);
191 Cursor_.push_back(p);
195 bool MathCursor::pop()
197 if (Cursor_.size() <= 1)
204 MathInset * MathCursor::parInset(int i) const
206 return Cursor_[i].par_;
210 void MathCursor::dump(char const * what) const
214 lyxerr << "MC: " << what << "\n";
215 for (unsigned i = 0; i < Cursor_.size(); ++i)
216 lyxerr << " i: " << i
217 << " pos: " << Cursor_[i].pos_
218 << " idx: " << Cursor_[i].idx_
219 << " par: " << Cursor_[i].par_ << "\n";
221 //lyxerr << " sel: " << selection << " data: " << array() << "\n";
225 void MathCursor::seldump(char const *) const
227 //lyxerr << "SEL: " << str << ": '" << theSelection << "'\n";
231 //lyxerr << "\n\n\\n=================vvvvvvvvvvvvv======================= "
232 // << str << "\ntheSelection: " << theSelection;
233 //for (unsigned int i = 0; i < Cursor_.size(); ++i)
234 // lyxerr << Cursor_[i].par_ << "\n'" << Cursor_[i].cell() << "'\n";
235 //lyxerr << "\ncursor.pos_: " << cursor().pos_;
236 //lyxerr << "\nanchor.pos_: " << anchor().pos_;
237 //lyxerr << "\n===================^^^^^^^^^^^^=====================\n\n\n";
241 bool MathCursor::isInside(MathInset * p) const
243 for (unsigned i = 0; i < Cursor_.size(); ++i)
244 if (parInset(i) == p)
250 bool MathCursor::openable(MathInset * p, bool sel, bool useupdown) const
254 if (!(p->isActive() || (useupdown && p->isUpDownInset())))
258 // we can't move into everything during selection
259 if (Cursor_.size() == Anchor_.size())
261 if (p != Anchor_[Cursor_.size()].par_)
268 bool MathCursor::plainLeft()
270 return array().prev(cursor().pos_);
274 bool MathCursor::Left(bool sel)
278 // was MacroModeBack()
279 if (!imacro->name().empty()) {
280 imacro->SetName(imacro->name().substr(0, imacro->name().length()-1));
281 imacro->Metrics(imacro->size());
289 MathInset * p = prevInset();
290 if (openable(p, sel, false)) {
297 if (cursor().par_->idxLeft(cursor().idx_, cursor().pos_))
305 bool MathCursor::plainRight()
307 return array().next(cursor().pos_);
311 bool MathCursor::Right(bool sel)
321 MathInset * p = nextInset();
322 if (openable(p, sel, false)) {
326 if (array().next(cursor().pos_))
328 if (cursor().par_->idxRight(cursor().idx_, cursor().pos_))
332 array().next(cursor().pos_);
337 void MathCursor::first()
340 push(formula_->par(), true);
344 void MathCursor::last()
347 push(formula_->par(), false);
351 void MathCursor::SetPos(int x, int y)
354 //lyxerr << "MathCursor::SetPos x: " << x << " y: " << y << "\n";
357 lastcode = LM_TC_MIN;
360 cursor().par_ = formula()->par();
365 //lyxerr << "found idx: " << idx_ << " cursor: " << cursor().pos_ << "\n";
366 int distmin = 1 << 30; // large enough
367 for (int i = 0; i < cursor().par_->nargs(); ++i) {
368 MathXArray const & ar = cursor().par_->xcell(i);
369 int x1 = x - ar.xo();
370 int y1 = y - ar.yo();
371 int c = ar.x2pos(x1);
372 int xx = abs(x1 - ar.pos2x(c));
374 //lyxerr << "idx: " << i << " xx: " << xx << " yy: " << yy
375 // << " c: " << c << " xo: " << ar.xo() << "\n";
376 if (yy + xx <= distmin) {
382 //lyxerr << "found idx: " << cursor().idx_ << " cursor: "
383 // << cursor().pos_ << "\n";
384 MathInset * n = nextInset();
385 MathInset * p = prevInset();
386 if (openable(n, selection, true) && n->covers(x, y))
388 else if (openable(p, selection, true) && p->covers(x, y)) {
398 void MathCursor::Home()
404 if (!cursor().par_->idxHome(cursor().idx_, cursor().pos_))
410 void MathCursor::End()
416 if (!cursor().par_->idxEnd(cursor().idx_, cursor().pos_)) {
418 array().next(cursor().pos_);
424 void MathCursor::insert(char c, MathTextCodes t)
426 //lyxerr << "inserting '" << c << "'\n";
433 if (macro_mode && !(MathIsAlphaFont(t) || t == LM_TC_MIN))
437 if (MathIsAlphaFont(t) || t == LM_TC_MIN) {
438 // was MacroModeinsert(c);
439 imacro->SetName(imacro->name() + static_cast<char>(c));
444 array().insert(cursor().pos_, c, t);
445 array().next(cursor().pos_);
451 void MathCursor::insert(MathInset * p)
462 array().insert(cursor().pos_, p);
463 array().next(cursor().pos_);
467 void MathCursor::insert(MathArray const & ar)
473 array().insert(cursor().pos_, ar);
474 cursor().pos_ += ar.size();
478 void MathCursor::Delete()
489 if (cursor().pos_ < array().size())
490 array().erase(cursor().pos_);
492 // delete empty cells if necessary
493 if (cursor().pos_ == 0 && array().size() == 0) {
496 cursor().par_->idxDelete(cursor().idx_, popit, removeit);
497 if (popit && pop() && removeit)
505 void MathCursor::DelLine()
514 if (cursor().par_->nrows() > 1)
515 cursor().par_->delRow(row());
519 bool MathCursor::Up(bool sel)
526 int x = xarray().pos2x(cursor().pos_);
527 if (cursor().par_->idxUp(cursor().idx_, cursor().pos_)) {
528 cursor().pos_ = xarray().x2pos(x);
536 // check whether we could move into an inset on the right or on the left
537 MathInset * p = nextInset();
540 if (p->idxFirstUp(idx, pos)) {
553 if (p->idxLastUp(idx, pos)) {
564 int x = xarray().pos2x(cursor().pos_);
565 if (cursor().idxUp()) {
566 cursor().pos_ = xarray().x2pos(x);
575 bool MathCursor::Down(bool sel)
582 int x = xarray().pos2x(cursor().pos_);
583 if (cursor().idxDown()) {
584 cursor().pos_ = xarray().x2pos(x);
592 // check whether we could move into an inset on the right or on the left
593 MathInset * p = nextInset();
596 if (p->idxFirstDown(idx, pos)) {
608 if (p->idxLastDown(idx, pos)) {
618 int x = xarray().pos2x(cursor().pos_);
619 if (cursor().par_->idxDown(cursor().idx_, cursor().pos_)) {
620 cursor().pos_ = xarray().x2pos(x);
629 bool MathCursor::toggleLimits()
633 MathInset * p = prevInset();
634 int old = p->limits();
635 p->limits(old < 0 ? 1 : -1);
636 return old != p->limits();
640 void MathCursor::SetSize(MathStyles size)
642 cursor().par_->UserSetSize(size);
647 void MathCursor::Interpret(string const & s)
649 lyxerr << "Interpret: '" << s << "' ('" << s.substr(0, 7) << "' " <<
650 in_word_set(s) << " \n";
653 MathUpDownInset * p = nearbyUpDownInset();
655 p = new MathScriptInset(true, false);
666 MathUpDownInset * p = nearbyUpDownInset();
668 p = new MathScriptInset(false, true);
678 if (s[0] == '!' || s[0] == ',' || s[0] == ':' || s[0] == ';') {
679 int sp = (s[0] == ',') ? 1:((s[0] == ':') ? 2:((s[0] == ';') ? 3: 0));
680 insert(new MathSpaceInset(sp));
685 latexkeys const * l = in_word_set(s);
689 p = new MathRootInset;
690 else if (MathMacroTable::hasTemplate(s))
691 p = new MathMacro(MathMacroTable::provideTemplate(s));
692 else if (s.size() > 7 && s.substr(0, 7) == "matrix ") {
697 istringstream is(s.substr(7).c_str());
698 is >> m >> n >> v_align >> h_align;
702 MathArrayInset * pp = new MathArrayInset(m, n);
703 pp->valign(v_align[0]);
708 p = new MathFuncInset(s, LM_OT_UNDEF);
712 p = new MathBigopInset(l->name, l->id);
716 MathTextCodes code = static_cast<MathTextCodes>(l->id);
718 insert(l->id, MathIsBOPS(code) ? LM_TC_BOPS : LM_TC_SYMB);
720 p = new MathFuncInset(l->name);
725 p = new MathFracInset("stackrel");
729 p = new MathFracInset("frac");
733 p = new MathSqrtInset;
736 case LM_TK_DECORATION:
737 p = new MathDecorationInset(l->name, l->id);
741 p = new MathFuncInset(l->name, LM_OT_FUNCLIM);
745 p = new MathSpaceInset(l->id);
749 p = new MathDotsInset(l->name, l->id);
753 p = new MathMacro(MathMacroTable::provideTemplate(s));
757 p = new MathFuncInset(l->name);
763 bool oldsel = selection;
773 p->Metrics(p->size());
778 void MathCursor::MacroModeOpen()
781 imacro = new MathFuncInset("");
785 lyxerr << "Math Warning: Already in macro mode" << endl;
789 void MathCursor::MacroModeClose()
793 latexkeys const * l = in_word_set(imacro->name());
794 if (!imacro->name().empty()
795 && (!l || (l && IsMacro(l->token, l->id)))
796 && !MathMacroTable::hasTemplate(imacro->name()))
799 //imacro->SetName(macrobf);
800 // This guarantees that the string will be removed by destructor
801 imacro->SetType(LM_OT_UNDEF);
803 imacro->SetName(l->name);
806 array().erase(cursor().pos_);
807 if (l || MathMacroTable::hasTemplate(imacro->name()))
808 Interpret(imacro->name());
809 imacro->SetName(string());
816 void MathCursor::SelCopy()
820 theSelection.grab(*this);
826 void MathCursor::SelCut()
830 theSelection.grab(*this);
831 theSelection.erase(*this);
837 void MathCursor::SelDel()
841 theSelection.erase(*this);
847 void MathCursor::SelPaste()
850 theSelection.paste(*this);
855 void MathCursor::SelHandle(bool sel)
857 if (sel && !selection)
859 if (!sel && selection)
864 void MathCursor::SelStart()
875 void MathCursor::SelClear()
881 void MathCursor::drawSelection(Painter & pain) const
888 getSelection(i1, i2);
890 //lyxerr << "selection from: " << i1 << " to " << i2 << "\n";
892 if (i1.idx_ == i2.idx_) {
893 MathXArray & c = i1.xcell();
894 int x1 = c.xo() + c.pos2x(i1.pos_);
895 int y1 = c.yo() - c.ascent();
896 int x2 = c.xo() + c.pos2x(i2.pos_);
897 int y2 = c.yo() + c.descent();
898 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
901 #if RECTANGULAR_SELECT
902 std::vector<int> indices = i1.par_->idxBetween(i1.idx_, i2.idx_);
903 for (unsigned i = 0; i < indices.size(); ++i) {
904 MathXArray & c = i1.xcell(indices[i]);
906 int y1 = c.yo() - c.ascent();
907 int x2 = c.xo() + c.width();
908 int y2 = c.yo() + c.descent();
909 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
913 MathXArray & c = i1.xcell();
914 int x1 = c.xo() + c.pos2x(i1.pos_);
915 int y1 = c.yo() - c.ascent();
916 int x2 = c.xo() + c.width();
917 int y2 = c.yo() + c.descent();
918 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
920 for (int idx = i1.idx_ + 1; idx < i2.idx_; ++idx) {
921 MathXArray & c = i1.xcell(idx);
923 int y1 = c.yo() - c.ascent();
924 int x2 = c.xo() + c.width();
925 int y2 = c.yo() + c.descent();
926 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
929 MathXArray & cr = i2.xcell();
931 y1 = cr.yo() - cr.ascent();
932 x2 = cr.xo() + cr.pos2x(i2.pos_);
933 y2 = cr.yo() + cr.descent();
934 pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
940 void MathCursor::handleFont(MathTextCodes t)
945 getSelection(i1, i2);
946 if (i1.idx_ == i2.idx_) {
947 MathArray & ar = i1.cell();
948 for (int pos = i1.pos_; pos != i2.pos_; ar.next(pos))
949 if (!ar.isInset(pos) && isalnum(ar.GetChar(pos))) {
950 MathTextCodes c = ar.GetCode(pos) == t ? LM_TC_VAR : t;
955 lastcode = (lastcode == t) ? LM_TC_VAR : t;
960 void MathCursor::handleAccent(string const & name, int code)
962 MathDecorationInset * p = new MathDecorationInset(name, code);
965 p->cell(0) = theSelection.glue();
972 void MathCursor::handleDelim(int l, int r)
974 MathDelimInset * p = new MathDelimInset(l, r);
977 p->cell(0) = theSelection.glue();
985 void MathCursor::GetPos(int & x, int & y)
987 x = xarray().xo() + xarray().pos2x(cursor().pos_);
992 MathTextCodes MathCursor::nextCode() const
994 return array().GetCode(cursor().pos_);
998 MathTextCodes MathCursor::prevCode() const
1000 return array().GetCode(cursor().pos_ - 1);
1004 MathInset * MathCursor::par() const
1006 return cursor().par_;
1010 InsetFormulaBase const * MathCursor::formula()
1016 int MathCursor::pos() const
1018 return cursor().pos_;
1022 bool MathCursor::InMacroMode() const
1028 bool MathCursor::Selection() const
1034 void MathCursor::clearLastCode()
1036 lastcode = LM_TC_MIN;
1040 void MathCursor::setLastCode(MathTextCodes t)
1046 MathTextCodes MathCursor::getLastCode() const
1052 MathInset * MathCursor::enclosing(MathInsetTypes t, int & idx) const
1054 for (int i = Cursor_.size() - 1; i >= 0; --i) {
1055 //lyxerr << "checking level " << i << "\n";
1056 if (Cursor_[i].par_->GetType() == t) {
1057 idx = Cursor_[i].idx_;
1058 return Cursor_[i].par_;
1065 void MathCursor::pullArg(bool goright)
1069 MathArray a = array();
1071 array().erase(cursor().pos_);
1072 array().insert(cursor().pos_, a);
1074 cursor().pos_ += a.size();
1079 MathStyles MathCursor::style() const
1081 return xarray().style();
1085 void MathCursor::normalize() const
1087 #ifdef WITH_WARNINGS
1088 #warning This is evil!
1090 MathCursor * it = const_cast<MathCursor *>(this);
1092 if (cursor().idx_ < 0 || cursor().idx_ > cursor().par_->nargs())
1093 lyxerr << "this should not really happen - 1\n";
1094 it->cursor().idx_ = max(cursor().idx_, 0);
1095 it->cursor().idx_ = min(cursor().idx_, cursor().par_->nargs());
1097 if (cursor().pos_ < 0 || cursor().pos_ > array().size())
1098 lyxerr << "this should not really happen - 2\n";
1099 it->cursor().pos_ = max(cursor().pos_, 0);
1100 it->cursor().pos_ = min(cursor().pos_, array().size());
1104 int MathCursor::col() const
1106 return par()->col(cursor().idx_);
1110 int MathCursor::row() const
1112 return par()->row(cursor().idx_);
1117 char MathCursorPos::GetChar() const
1119 return array().GetChar(cursor().pos_);
1123 string MathCursorPos::readString()
1126 int code = nextCode();
1127 for ( ; OK() && nextCode() == code; Next())
1135 MathInset * MathCursor::prevInset() const
1138 int c = cursor().pos_;
1139 if (!array().prev(c))
1141 return array().nextInset(c);
1145 MathInset * MathCursor::nextInset() const
1148 return array().nextInset(cursor().pos_);
1152 MathUpDownInset * MathCursor::nearbyUpDownInset() const
1155 MathInset * p = array().prevInset(cursor().pos_);
1156 if (p && p->isUpDownInset())
1157 return static_cast<MathUpDownInset *>(p);
1158 p = array().nextInset(cursor().pos_);
1159 if (p && p->isUpDownInset())
1160 return static_cast<MathUpDownInset *>(p);
1165 MathArray & MathCursor::array() const
1167 static MathArray dummy;
1168 if (!cursor().par_) {
1169 lyxerr << "############ par_ not valid\n";
1173 if (cursor().idx_ < 0 || cursor().idx_ >= cursor().par_->nargs()) {
1174 lyxerr << "############ idx_ " << cursor().idx_ << " not valid\n";
1178 return cursor().cell();
1182 MathXArray & MathCursor::xarray() const
1184 return cursor().xcell();
1188 bool MathCursor::nextIsInset() const
1190 return cursor().pos_ < array().size() && MathIsInset(nextCode());
1194 bool MathCursor::prevIsInset() const
1196 return cursor().pos_ > 0 && MathIsInset(prevCode());
1200 int MathCursor::xpos() const
1203 return xarray().pos2x(cursor().pos_);
1207 void MathCursor::gotoX(int x)
1209 cursor().pos_ = xarray().x2pos(x);
1213 void MathCursor::idxNext()
1215 cursor().par_->idxNext(cursor().idx_, cursor().pos_);
1219 void MathCursor::idxPrev()
1221 cursor().par_->idxPrev(cursor().idx_, cursor().pos_);
1225 void MathCursor::splitCell()
1227 if (cursor().idx_ == cursor().par_->nargs() - 1)
1229 MathArray ar = array();
1230 ar.erase(0, cursor().pos_);
1231 array().erase(cursor().pos_, array().size());
1234 array().insert(0, ar);
1238 void MathCursor::breakLine()
1240 MathMatrixInset * p = static_cast<MathMatrixInset *>(formula()->par());
1241 if (p->GetType() == LM_OT_SIMPLE || p->GetType() == LM_OT_EQUATION) {
1242 p->mutate(LM_OT_EQNARRAY);
1244 cursor().idx_ = p->nrows();
1250 const int r = row();
1251 for (int c = col() + 1; c < p->ncols(); ++c) {
1252 const int i1 = p->index(r, c);
1253 const int i2 = p->index(r + 1, c);
1254 lyxerr << "swapping cells " << i1 << " and " << i2 << "\n";
1255 p->cell(i1).swap(p->cell(i2));
1260 p->cell(cursor().idx_).swap(p->cell(cursor().idx_ + p->ncols() - 1));
1265 char MathCursor::valign() const
1269 static_cast<MathGridInset *>(enclosing(LM_OT_MATRIX, idx));
1270 return p ? p->valign() : 0;
1274 char MathCursor::halign() const
1278 static_cast<MathGridInset *>(enclosing(LM_OT_MATRIX, idx));
1279 return p ? p->halign(idx % p->ncols()) : 0;
1283 MathCursorPos MathCursor::firstSelectionPos() const
1285 MathCursorPos anc = normalAnchor();
1286 return anc < cursor() ? anc : cursor();
1290 MathCursorPos MathCursor::lastSelectionPos() const
1292 MathCursorPos anc = normalAnchor();
1293 return anc < cursor() ? cursor() : anc;
1297 void MathCursor::getSelection(MathCursorPos & i1, MathCursorPos & i2) const
1299 MathCursorPos anc = normalAnchor();
1300 if (anc < cursor()) {
1310 MathCursorPos & MathCursor::cursor()
1312 return Cursor_.back();
1316 MathCursorPos const & MathCursor::cursor() const
1318 return Cursor_.back();
1323 ////////////////////////////////////////////////////////////////////////
1326 bool operator==(MathCursorPos const & ti, MathCursorPos const & it)
1328 return ti.par_ == it.par_ && ti.idx_ == it.idx_ && ti.pos_ == it.pos_;
1332 bool operator<(MathCursorPos const & ti, MathCursorPos const & it)
1334 if (ti.par_ != it.par_) {
1335 lyxerr << "can't compare cursor and anchor in different insets\n";
1338 if (ti.idx_ != it.idx_)
1339 return ti.idx_ < it.idx_;
1340 return ti.pos_ < it.pos_;
1344 MathArray & MathCursorPos::cell(int idx) const
1346 return par_->cell(idx);
1349 MathArray & MathCursorPos::cell() const
1351 return par_->cell(idx_);
1355 MathXArray & MathCursorPos::xcell(int idx) const
1357 return par_->xcell(idx);
1361 MathXArray & MathCursorPos::xcell() const
1363 return par_->xcell(idx_);
1367 MathCursorPos MathCursor::normalAnchor() const
1369 // use Anchor on the same level as Cursor
1370 MathCursorPos normal = Anchor_[Cursor_.size() - 1];
1371 if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) {
1372 // anchor is behind cursor -> move anchor behind the inset
1373 normal.cell().next(normal.pos_);
1375 //lyxerr << "normalizing: from " << Anchor_[Anchor_.size() - 1] << " to "
1376 // << normal << "\n";
1381 bool MathCursorPos::idxUp()
1383 return par_->idxUp(idx_, pos_);
1387 bool MathCursorPos::idxDown()
1389 return par_->idxDown(idx_, pos_);
1393 bool MathCursorPos::idxLeft()
1395 return par_->idxLeft(idx_, pos_);
1399 bool MathCursorPos::idxRight()
1401 return par_->idxRight(idx_, pos_);