3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Alejandro Aguilar Sierra
7 * \author Alfredo Braunstein
10 * Full author contact details are available in file CREDITS.
15 #include "BufferView.h"
16 #include "bufferview_funcs.h"
19 #include "coordcache.h"
20 #include "CutAndPaste.h"
22 #include "dispatchresult.h"
24 #include "funcrequest.h"
28 #include "lyxfunc.h" // only for setMessage()
32 #include "paragraph.h"
33 #include "paragraph_funcs.h"
34 #include "pariterator.h"
36 #include "insets/insettabular.h"
37 #include "insets/insettext.h"
39 #include "mathed/MathData.h"
40 #include "mathed/InsetMath.h"
41 #include "mathed/InsetMathScript.h"
42 #include "mathed/MathMacroTable.h"
44 #include "frontends/Selection.h"
46 #include "support/limited_stack.h"
48 #include <boost/assert.hpp>
49 #include <boost/bind.hpp>
50 #include <boost/current_function.hpp>
61 #ifndef CXX_GLOBAL_CSTD
70 positionable(DocIterator const & cursor, DocIterator const & anchor)
72 // avoid deeper nested insets when selecting
73 if (cursor.depth() > anchor.depth())
76 // anchor might be deeper, should have same path then
77 for (size_t i = 0; i < cursor.depth(); ++i)
78 if (&cursor[i].inset() != &anchor[i].inset())
81 // position should be ok.
86 // Find position closest to (x, y) in cell given by iter.
87 // Used only in mathed
88 DocIterator bruteFind2(LCursor const & c, int x, int y)
90 double best_dist = std::numeric_limits<double>::max();
97 et.top().pos() = et.top().asInsetMath()->cell(et.top().idx()).size();
98 for (size_t i = 0; ; ++i) {
101 InsetBase const * inset = &it.inset();
102 std::map<InsetBase const *, Point> const & data =
103 c.bv().coordCache().getInsets().getData();
104 std::map<InsetBase const *, Point>::const_iterator I = data.find(inset);
106 // FIXME: in the case where the inset is not in the cache, this
107 // means that no part of it is visible on screen. In this case
108 // we don't do elaborate search and we just return the forwarded
109 // DocIterator at its beginning.
110 if (I == data.end()) {
116 inset->cursorPos(c.bv(), it.top(), c.boundary(), xo, yo);
117 // Convert to absolute
120 double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
121 // '<=' in order to take the last possible position
122 // this is important for clicking behind \sum in e.g. '\sum_i a'
123 lyxerr[Debug::DEBUG] << "i: " << i << " d: " << d
124 << " best: " << best_dist << endl;
125 if (d <= best_dist) {
137 /// moves position closest to (x, y) in given box
138 bool bruteFind(LCursor & cursor,
139 int x, int y, int xlow, int xhigh, int ylow, int yhigh)
141 BOOST_ASSERT(!cursor.empty());
142 InsetBase & inset = cursor[0].inset();
143 BufferView & bv = cursor.bv();
145 CoordCache::InnerParPosCache const & cache =
146 bv.coordCache().getParPos().find(cursor.bottom().text())->second;
147 // Get an iterator on the first paragraph in the cache
148 DocIterator it(inset);
149 it.push_back(CursorSlice(inset));
150 it.pit() = cache.begin()->first;
151 // Get an iterator after the last paragraph in the cache
152 DocIterator et(inset);
153 et.push_back(CursorSlice(inset));
154 et.pit() = boost::prior(cache.end())->first;
155 if (et.pit() >= et.lastpit())
156 et = doc_iterator_end(inset);
160 double best_dist = std::numeric_limits<double>::max();;
161 DocIterator best_cursor = et;
163 for ( ; it != et; it.forwardPos(true)) {
164 // avoid invalid nesting when selecting
165 if (!cursor.selection() || positionable(it, cursor.anchor_)) {
166 Point p = bv_funcs::getPos(bv, it, false);
169 if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
170 double const dx = xo - x;
171 double const dy = yo - y;
172 double const d = dx * dx + dy * dy;
173 // '<=' in order to take the last possible position
174 // this is important for clicking behind \sum in e.g. '\sum_i a'
175 if (d <= best_dist) {
176 // lyxerr << "*" << endl;
184 if (best_cursor != et) {
185 cursor.setCursor(best_cursor);
193 /// moves position closest to (x, y) in given box
194 bool bruteFind3(LCursor & cur, int x, int y, bool up)
196 BufferView & bv = cur.bv();
197 int ylow = up ? 0 : y + 1;
198 int yhigh = up ? y - 1 : bv.workHeight();
200 int xhigh = bv.workWidth();
202 // FIXME: bit more work needed to get 'from' and 'to' right.
203 pit_type from = cur.bottom().pit();
204 //pit_type to = cur.bottom().pit();
205 //lyxerr << "Pit start: " << from << endl;
207 //lyxerr << "bruteFind3: x: " << x << " y: " << y
208 // << " xlow: " << xlow << " xhigh: " << xhigh
209 // << " ylow: " << ylow << " yhigh: " << yhigh
211 InsetBase & inset = bv.buffer()->inset();
212 DocIterator it = doc_iterator_begin(inset);
214 DocIterator et = doc_iterator_end(inset);
216 double best_dist = std::numeric_limits<double>::max();
217 DocIterator best_cursor = et;
219 for ( ; it != et; it.forwardPos()) {
220 // avoid invalid nesting when selecting
221 if (bv_funcs::status(&bv, it) == bv_funcs::CUR_INSIDE
222 && (!cur.selection() || positionable(it, cur.anchor_))) {
223 Point p = bv_funcs::getPos(bv, it, false);
226 if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
227 double const dx = xo - x;
228 double const dy = yo - y;
229 double const d = dx * dx + dy * dy;
230 //lyxerr << "itx: " << xo << " ity: " << yo << " d: " << d
231 // << " dx: " << dx << " dy: " << dy
232 // << " idx: " << it.idx() << " pos: " << it.pos()
235 // '<=' in order to take the last possible position
236 // this is important for clicking behind \sum in e.g. '\sum_i a'
237 if (d <= best_dist) {
238 //lyxerr << "*" << endl;
246 //lyxerr << "best_dist: " << best_dist << " cur:\n" << best_cursor << endl;
247 if (best_cursor == et)
249 cur.setCursor(best_cursor);
256 // be careful: this is called from the bv's constructor, too, so
257 // bv functions are not yet available!
258 LCursor::LCursor(BufferView & bv)
259 : DocIterator(), bv_(&bv), anchor_(), x_target_(-1),
260 selection_(false), mark_(false), logicalpos_(false)
264 void LCursor::reset(InsetBase & inset)
267 push_back(CursorSlice(inset));
268 anchor_ = DocIterator(inset);
275 // this (intentionally) does neither touch anchor nor selection status
276 void LCursor::setCursor(DocIterator const & cur)
278 DocIterator::operator=(cur);
282 void LCursor::dispatch(FuncRequest const & cmd0)
284 lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION
285 << " cmd: " << cmd0 << '\n'
291 FuncRequest cmd = cmd0;
292 LCursor safe = *this;
294 for (; depth(); pop()) {
295 lyxerr[Debug::DEBUG] << "LCursor::dispatch: cmd: "
296 << cmd0 << endl << *this << endl;
297 BOOST_ASSERT(pos() <= lastpos());
298 BOOST_ASSERT(idx() <= lastidx());
299 BOOST_ASSERT(pit() <= lastpit());
301 // The common case is 'LFUN handled, need update', so make the
302 // LFUN handler's life easier by assuming this as default value.
303 // The handler can reset the update and val flags if necessary.
304 disp_.update(Update::FitCursor | Update::Force);
305 disp_.dispatched(true);
306 inset().dispatch(*this, cmd);
307 if (disp_.dispatched())
310 // it completely to get a 'bomb early' behaviour in case this
311 // object will be used again.
312 if (!disp_.dispatched()) {
313 lyxerr[Debug::DEBUG] << "RESTORING OLD CURSOR!" << endl;
315 disp_.update(Update::None);
316 disp_.dispatched(false);
321 DispatchResult LCursor::result() const
327 BufferView & LCursor::bv() const
334 Buffer & LCursor::buffer() const
337 BOOST_ASSERT(bv_->buffer());
338 return *bv_->buffer();
344 BOOST_ASSERT(depth() >= 1);
349 void LCursor::push(InsetBase & p)
351 push_back(CursorSlice(p));
355 void LCursor::pushLeft(InsetBase & p)
357 BOOST_ASSERT(!empty());
358 //lyxerr << "Entering inset " << t << " left" << endl;
364 bool LCursor::popLeft()
366 BOOST_ASSERT(!empty());
367 //lyxerr << "Leaving inset to the left" << endl;
368 inset().notifyCursorLeaves(*this);
376 bool LCursor::popRight()
378 BOOST_ASSERT(!empty());
379 //lyxerr << "Leaving inset to the right" << endl;
380 const pos_type lp = (depth() > 1) ? (*this)[depth() - 2].lastpos() : 0;
381 inset().notifyCursorLeaves(*this);
385 pos() += lastpos() - lp + 1;
390 int LCursor::currentMode()
392 BOOST_ASSERT(!empty());
393 for (int i = depth() - 1; i >= 0; --i) {
394 int res = operator[](i).inset().currentMode();
395 if (res != InsetBase::UNDECIDED_MODE)
398 return InsetBase::TEXT_MODE;
402 void LCursor::getPos(int & x, int & y) const
404 Point p = bv_funcs::getPos(bv(), *this, boundary());
410 Row const & LCursor::textRow() const
412 ParagraphMetrics const & pm = bv().parMetrics(text(), pit());
413 BOOST_ASSERT(!pm.rows().empty());
414 return pm.getRow(pos(), boundary());
418 void LCursor::resetAnchor()
425 bool LCursor::posLeft()
434 bool LCursor::posRight()
436 if (pos() == lastpos())
443 CursorSlice LCursor::anchor() const
445 BOOST_ASSERT(anchor_.depth() >= depth());
446 CursorSlice normal = anchor_[depth() - 1];
447 if (depth() < anchor_.depth() && top() <= normal) {
448 // anchor is behind cursor -> move anchor behind the inset
455 CursorSlice LCursor::selBegin() const
459 return anchor() < top() ? anchor() : top();
463 CursorSlice LCursor::selEnd() const
467 return anchor() > top() ? anchor() : top();
471 DocIterator LCursor::selectionBegin() const
475 DocIterator di = (anchor() < top() ? anchor_ : *this);
481 DocIterator LCursor::selectionEnd() const
485 DocIterator di = (anchor() > top() ? anchor_ : *this);
486 if (di.depth() > depth()) {
494 void LCursor::setSelection()
497 // A selection with no contents is not a selection
499 #warning doesnt look ok
501 if (pit() == anchor().pit() && pos() == anchor().pos())
506 void LCursor::setSelection(DocIterator const & where, int n)
515 void LCursor::clearSelection()
523 int & LCursor::x_target()
529 int LCursor::x_target() const
535 void LCursor::clearTargetX()
542 void LCursor::info(odocstream & os) const
544 for (int i = 1, n = depth(); i < n; ++i) {
545 operator[](i).inset().infoize(os);
549 prevInset()->infoize2(os);
550 // overwite old message
555 bool LCursor::selHandle(bool sel)
557 //lyxerr << "LCursor::selHandle" << endl;
558 if (sel == selection())
563 theSelection().haveSelection(sel);
568 std::ostream & operator<<(std::ostream & os, LCursor const & cur)
570 os << "\n cursor: | anchor:\n";
571 for (size_t i = 0, n = cur.depth(); i != n; ++i) {
572 os << " " << cur[i] << " | ";
573 if (i < cur.anchor_.depth())
574 os << cur.anchor_[i];
576 os << "-------------------------------";
579 for (size_t i = cur.depth(), n = cur.anchor_.depth(); i < n; ++i) {
580 os << "------------------------------- | " << cur.anchor_[i] << "\n";
582 os << " selection: " << cur.selection_
583 << " x_target: " << cur.x_target_ << endl;
590 ///////////////////////////////////////////////////////////////////
592 // The part below is the non-integrated rest of the original math
593 // cursor. This should be either generalized for texted or moved
594 // back to mathed (in most cases to InsetMathNest).
596 ///////////////////////////////////////////////////////////////////
598 #include "mathed/InsetMathChar.h"
599 #include "mathed/InsetMathGrid.h"
600 #include "mathed/InsetMathScript.h"
601 #include "mathed/InsetMathUnknown.h"
602 #include "mathed/MathFactory.h"
603 #include "mathed/MathMacroArgument.h"
604 #include "mathed/MathStream.h"
605 #include "mathed/MathSupport.h"
610 //#define FILEDEBUG 1
613 bool LCursor::isInside(InsetBase const * p)
615 for (size_t i = 0; i != depth(); ++i)
616 if (&operator[](i).inset() == p)
622 void LCursor::leaveInset(InsetBase const & inset)
624 for (size_t i = 0; i != depth(); ++i) {
625 if (&operator[](i).inset() == &inset) {
633 bool LCursor::openable(MathAtom const & t) const
644 // we can't move into anything new during selection
645 if (depth() >= anchor_.depth())
647 if (!ptr_cmp(t.nucleus(), &anchor_[depth()].inset()))
654 void LCursor::setScreenPos(int x, int y)
657 bruteFind(*this, x, y, 0, bv().workWidth(), 0, bv().workHeight());
662 void LCursor::plainErase()
668 void LCursor::markInsert()
670 insert(char_type(0));
674 void LCursor::markErase()
680 void LCursor::plainInsert(MathAtom const & t)
682 cell().insert(pos(), t);
687 void LCursor::insert(docstring const & str)
689 for_each(str.begin(), str.end(),
690 boost::bind(static_cast<void(LCursor::*)(char_type)>
691 (&LCursor::insert), this, _1));
695 void LCursor::insert(char_type c)
697 //lyxerr << "LCursor::insert char '" << c << "'" << endl;
698 BOOST_ASSERT(!empty());
700 cap::selClearOrDel(*this);
701 insert(new InsetMathChar(c));
703 text()->insertChar(*this, c);
708 void LCursor::insert(MathAtom const & t)
710 //lyxerr << "LCursor::insert MathAtom '" << t << "'" << endl;
712 cap::selClearOrDel(*this);
717 void LCursor::insert(InsetBase * inset)
720 insert(MathAtom(inset));
722 text()->insertInset(*this, inset);
726 void LCursor::niceInsert(docstring const & t)
737 void LCursor::niceInsert(MathAtom const & t)
740 docstring const safe = cap::grabAndEraseSelection(*this);
742 // enter the new inset and move the contents of the selection if possible
745 // be careful here: don't use 'pushLeft(t)' as this we need to
746 // push the clone, not the original
747 pushLeft(*nextInset());
748 // We may not use niceInsert here (recursion)
756 void LCursor::insert(MathArray const & ar)
760 cap::eraseSelection(*this);
761 cell().insert(pos(), ar);
766 bool LCursor::backspace()
768 autocorrect() = false;
771 cap::eraseSelection(*this);
776 // If empty cell, and not part of a big cell
777 if (lastpos() == 0 && inset().nargs() == 1) {
779 // Directly delete empty cell: [|[]] => [|]
785 // [|], can not delete from inside
795 InsetMathUnknown * p = activeMacro();
796 if (p->name().size() > 1) {
797 p->setName(p->name().substr(0, p->name().size() - 1));
802 if (pos() != 0 && prevAtom()->nargs() > 0) {
803 // let's require two backspaces for 'big stuff' and
804 // highlight on the first
816 bool LCursor::erase()
818 autocorrect() = false;
823 cap::eraseSelection(*this);
827 // delete empty cells if possible
828 if (pos() == lastpos() && inset().idxDelete(idx()))
831 // special behaviour when in last position of cell
832 if (pos() == lastpos()) {
833 bool one_cell = inset().nargs() == 1;
834 if (one_cell && lastpos() == 0) {
836 // Directly delete empty cell: [|[]] => [|]
842 // [|], can not delete from inside
847 inset().idxGlue(idx());
851 // 'clever' UI hack: only erase large items if previously slected
852 if (pos() != lastpos() && nextAtom()->nargs() > 0) {
867 DocIterator save = *this;
871 autocorrect() = false;
879 DocIterator save = *this;
883 autocorrect() = false;
888 bool LCursor::macroModeClose()
892 InsetMathUnknown * p = activeMacro();
894 docstring const s = p->name();
898 // do nothing if the macro name is empty
902 // prevent entering of recursive macros
903 // FIXME: this is only a weak attempt... only prevents immediate
905 docstring const name = s.substr(1);
906 InsetBase const * macro = innerInsetOfType(InsetBase::MATHMACRO_CODE);
907 if (macro && macro->getInsetName() == name)
908 lyxerr << "can't enter recursive macro" << endl;
910 InsetMathNest * const in = inset().asInsetMath()->asNestInset();
911 if (in && in->interpretString(*this, s))
913 plainInsert(createInsetMath(name));
918 docstring LCursor::macroName()
920 return inMacroMode() ? activeMacro()->name() : docstring();
924 void LCursor::handleNest(MathAtom const & a, int c)
926 //lyxerr << "LCursor::handleNest: " << c << endl;
928 asArray(cap::grabAndEraseSelection(*this), t.nucleus()->cell(c));
931 pushLeft(*nextInset());
935 int LCursor::targetX() const
937 if (x_target() != -1)
946 void LCursor::setTargetX()
955 bool LCursor::inMacroMode() const
959 InsetMathUnknown const * p = prevAtom()->asUnknownInset();
960 return p && !p->final();
964 InsetMathUnknown * LCursor::activeMacro()
966 return inMacroMode() ? prevAtom().nucleus()->asUnknownInset() : 0;
970 void LCursor::pullArg()
975 MathArray ar = cell();
976 if (popLeft() && inMathed()) {
978 cell().insert(pos(), ar);
981 //formula()->mutateToText();
986 void LCursor::touch()
992 DocIterator::const_iterator it = begin();
993 DocIterator::const_iterator et = end();
994 for ( ; it != et; ++it)
1000 void LCursor::normalize()
1002 if (idx() > lastidx()) {
1003 lyxerr << "this should not really happen - 1: "
1004 << idx() << ' ' << nargs()
1005 << " in: " << &inset() << endl;
1009 if (pos() > lastpos()) {
1010 lyxerr << "this should not really happen - 2: "
1011 << pos() << ' ' << lastpos() << " in idx: " << idx()
1013 odocstringstream os;
1014 WriteStream wi(os, false, true);
1015 inset().asInsetMath()->write(wi);
1016 lyxerr << to_utf8(os.str()) << endl;
1022 bool LCursor::goUpDown(bool up)
1024 // Be warned: The 'logic' implemented in this function is highly
1025 // fragile. A distance of one pixel or a '<' vs '<=' _really
1026 // matters. So fiddle around with it only if you think you know
1027 // what you are doing!
1033 // check if we had something else in mind, if not, this is the future
1035 if (x_target() == -1)
1040 // try neigbouring script insets
1044 InsetMathScript const * p = prevAtom()->asScriptInset();
1045 if (p && p->has(up)) {
1047 push(*const_cast<InsetMathScript*>(p));
1048 idx() = p->idxOfScript(up);
1055 if (pos() != lastpos()) {
1056 InsetMathScript const * p = nextAtom()->asScriptInset();
1057 if (p && p->has(up)) {
1058 push(*const_cast<InsetMathScript*>(p));
1059 idx() = p->idxOfScript(up);
1066 // FIXME: Switch this on for more robust movement
1069 return bruteFind3(*this, xo, yo, up);
1072 //xarray().boundingBox(xlow, xhigh, ylow, yhigh);
1077 //if (bruteFind(*this, xo, yo, xlow, xhigh, ylow, yhigh)) {
1078 // lyxerr << "updown: handled by brute find in the same cell" << endl;
1082 // try to find an inset that knows better then we
1084 //lyxerr << "updown: We are in " << &inset() << " idx: " << idx() << endl;
1086 if (inset().idxUpDown(*this, up)) {
1087 //lyxerr << "idxUpDown triggered" << endl;
1088 // try to find best position within this inset
1090 setCursor(bruteFind2(*this, xo, yo));
1094 // no such inset found, just take something "above"
1096 //lyxerr << "updown: popleft failed (strange case)" << endl;
1097 int ylow = up ? 0 : yo + 1;
1098 int yhigh = up ? yo - 1 : bv().workHeight();
1099 return bruteFind(*this, xo, yo, 0, bv().workWidth(), ylow, yhigh);
1102 // any improvement so far?
1103 //lyxerr << "updown: popLeft succeeded" << endl;
1107 if (up ? ynew < yo : ynew > yo)
1111 // we should not come here.
1112 BOOST_ASSERT(false);
1117 void LCursor::handleFont(string const & font)
1119 lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION << ": " << font << endl;
1123 safe = cap::grabAndEraseSelection(*this);
1126 if (lastpos() != 0) {
1127 // something left in the cell
1129 // cursor in first position
1131 } else if (pos() == lastpos()) {
1132 // cursor in last position
1135 // cursor in between. split cell
1136 MathArray::iterator bt = cell().begin();
1137 MathAtom at = createInsetMath(from_utf8(font));
1138 at.nucleus()->cell(0) = MathArray(bt, bt + pos());
1139 cell().erase(bt, bt + pos());
1144 // nothing left in the cell
1152 void LCursor::message(docstring const & msg) const
1154 theLyXFunc().setMessage(msg);
1158 void LCursor::errorMessage(docstring const & msg) const
1160 theLyXFunc().setErrorMessage(msg);
1164 docstring LCursor::selectionAsString(bool label) const
1170 Buffer const & buffer = *bv().buffer();
1171 ParagraphList const & pars = text()->paragraphs();
1173 // should be const ...
1174 pit_type startpit = selBegin().pit();
1175 pit_type endpit = selEnd().pit();
1176 size_t const startpos = selBegin().pos();
1177 size_t const endpos = selEnd().pos();
1179 if (startpit == endpit)
1180 return pars[startpit].asString(buffer, startpos, endpos, label);
1182 // First paragraph in selection
1183 docstring result = pars[startpit].
1184 asString(buffer, startpos, pars[startpit].size(), label) + "\n\n";
1186 // The paragraphs in between (if any)
1187 for (pit_type pit = startpit + 1; pit != endpit; ++pit) {
1188 Paragraph const & par = pars[pit];
1189 result += par.asString(buffer, 0, par.size(), label) + "\n\n";
1192 // Last paragraph in selection
1193 result += pars[endpit].asString(buffer, 0, endpos, label);
1199 return cap::grabSelection(*this);
1205 docstring LCursor::currentState()
1208 odocstringstream os;
1214 return text()->currentState(*this);
1220 docstring LCursor::getPossibleLabel()
1222 return inMathed() ? from_ascii("eq:") : text()->getPossibleLabel(*this);
1226 Encoding const * LCursor::getEncoding() const
1233 // go up until first non-0 text is hit
1234 // (innermost text is 0 in mathed)
1235 for (s = depth() - 1; s >= 0; --s)
1236 if (operator[](s).text())
1238 CursorSlice const & sl = operator[](s);
1239 LyXText const & text = *sl.text();
1240 LyXFont font = text.getPar(sl.pit()).getFont(
1241 bv().buffer()->params(), sl.pos(), outerFont(sl.pit(), text.paragraphs()));
1242 return font.language()->encoding();
1246 void LCursor::undispatched()
1248 disp_.dispatched(false);
1252 void LCursor::dispatched()
1254 disp_.dispatched(true);
1258 void LCursor::updateFlags(Update::flags f)
1264 void LCursor::noUpdate()
1266 disp_.update(Update::None);
1270 LyXFont LCursor::getFont() const
1272 // HACK. far from being perfect...
1274 // go up until first non-0 text is hit
1275 // (innermost text is 0 in mathed)
1276 for (s = depth() - 1; s >= 0; --s)
1277 if (operator[](s).text())
1279 CursorSlice const & sl = operator[](s);
1280 LyXText const & text = *sl.text();
1281 LyXFont font = text.getPar(sl.pit()).getFont(
1282 bv().buffer()->params(),
1284 outerFont(sl.pit(), text.paragraphs()));
1290 void LCursor::fixIfBroken()
1292 // find out last good level
1293 LCursor copy = *this;
1294 size_t newdepth = depth();
1295 while (!copy.empty()) {
1296 if (copy.idx() > copy.lastidx()) {
1297 lyxerr << "wrong idx " << copy.idx()
1298 << ", max is " << copy.lastidx()
1299 << " at level " << copy.depth()
1300 << ". Trying to correct this." << endl;
1301 newdepth = copy.depth() - 1;
1303 else if (copy.pit() > copy.lastpit()) {
1304 lyxerr << "wrong pit " << copy.pit()
1305 << ", max is " << copy.lastpit()
1306 << " at level " << copy.depth()
1307 << ". Trying to correct this." << endl;
1308 newdepth = copy.depth() - 1;
1310 else if (copy.pos() > copy.lastpos()) {
1311 lyxerr << "wrong pos " << copy.pos()
1312 << ", max is " << copy.lastpos()
1313 << " at level " << copy.depth()
1314 << ". Trying to correct this." << endl;
1315 newdepth = copy.depth() - 1;
1319 // shrink cursor to a size where everything is valid, possibly
1321 while (depth() > newdepth) {
1323 lyxerr << "correcting cursor to level " << depth() << endl;