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"
18 #include "coordcache.h"
19 #include "CutAndPaste.h"
21 #include "dispatchresult.h"
23 #include "funcrequest.h"
27 #include "lyxfunc.h" // only for setMessage()
31 #include "paragraph.h"
32 #include "paragraph_funcs.h"
33 #include "pariterator.h"
35 #include "insets/insettabular.h"
36 #include "insets/insettext.h"
38 #include "mathed/MathData.h"
39 #include "mathed/InsetMath.h"
40 #include "mathed/InsetMathScript.h"
41 #include "mathed/MathMacroTable.h"
42 #include "mathed/MathParser.h"
44 #include "support/limited_stack.h"
46 #include <boost/assert.hpp>
47 #include <boost/bind.hpp>
48 #include <boost/current_function.hpp>
59 #ifndef CXX_GLOBAL_CSTD
68 positionable(DocIterator const & cursor, DocIterator const & anchor)
70 // avoid deeper nested insets when selecting
71 if (cursor.depth() > anchor.depth())
74 // anchor might be deeper, should have same path then
75 for (size_t i = 0; i < cursor.depth(); ++i)
76 if (&cursor[i].inset() != &anchor[i].inset())
79 // position should be ok.
84 // Find position closest to (x, y) in cell given by iter.
85 // Used only in mathed
86 DocIterator bruteFind2(LCursor const & c, int x, int y)
88 double best_dist = std::numeric_limits<double>::max();
95 et.top().pos() = et.top().asInsetMath()->cell(et.top().idx()).size();
96 for (size_t i = 0; ; ++i) {
99 InsetBase const * inset = &it.inset();
100 std::map<InsetBase const *, Point> const & data =
101 c.bv().coordCache().getInsets().getData();
102 std::map<InsetBase const *, Point>::const_iterator I = data.find(inset);
104 // FIXME: in the case where the inset is not in the cache, this
105 // means that no part of it is visible on screen. In this case
106 // we don't do elaborate search and we just return the forwarded
107 // DocIterator at its beginning.
108 if (I == data.end()) {
114 inset->cursorPos(c.bv(), it.top(), c.boundary(), xo, yo);
115 // Convert to absolute
118 double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
119 // '<=' in order to take the last possible position
120 // this is important for clicking behind \sum in e.g. '\sum_i a'
121 lyxerr[Debug::DEBUG] << "i: " << i << " d: " << d
122 << " best: " << best_dist << endl;
123 if (d <= best_dist) {
135 /// moves position closest to (x, y) in given box
136 bool bruteFind(LCursor & cursor,
137 int x, int y, int xlow, int xhigh, int ylow, int yhigh)
139 BOOST_ASSERT(!cursor.empty());
140 InsetBase & inset = cursor[0].inset();
141 BufferView & bv = cursor.bv();
143 CoordCache::InnerParPosCache const & cache =
144 bv.coordCache().getParPos().find(cursor.bottom().text())->second;
145 // Get an iterator on the first paragraph in the cache
146 DocIterator it(inset);
147 it.push_back(CursorSlice(inset));
148 it.pit() = cache.begin()->first;
149 // Get an iterator after the last paragraph in the cache
150 DocIterator et(inset);
151 et.push_back(CursorSlice(inset));
152 et.pit() = boost::prior(cache.end())->first;
153 if (et.pit() >= et.lastpit())
154 et = doc_iterator_end(inset);
158 double best_dist = std::numeric_limits<double>::max();;
159 DocIterator best_cursor = et;
161 for ( ; it != et; it.forwardPos(true)) {
162 // avoid invalid nesting when selecting
163 if (!cursor.selection() || positionable(it, cursor.anchor_)) {
164 Point p = bv_funcs::getPos(bv, it, false);
167 if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
168 double const dx = xo - x;
169 double const dy = yo - y;
170 double const d = dx * dx + dy * dy;
171 // '<=' in order to take the last possible position
172 // this is important for clicking behind \sum in e.g. '\sum_i a'
173 if (d <= best_dist) {
174 // lyxerr << "*" << endl;
182 if (best_cursor != et) {
183 cursor.setCursor(best_cursor);
191 /// moves position closest to (x, y) in given box
192 bool bruteFind3(LCursor & cur, int x, int y, bool up)
194 BufferView & bv = cur.bv();
195 int ylow = up ? 0 : y + 1;
196 int yhigh = up ? y - 1 : bv.workHeight();
198 int xhigh = bv.workWidth();
200 // FIXME: bit more work needed to get 'from' and 'to' right.
201 pit_type from = cur.bottom().pit();
202 //pit_type to = cur.bottom().pit();
203 //lyxerr << "Pit start: " << from << endl;
205 //lyxerr << "bruteFind3: x: " << x << " y: " << y
206 // << " xlow: " << xlow << " xhigh: " << xhigh
207 // << " ylow: " << ylow << " yhigh: " << yhigh
209 InsetBase & inset = bv.buffer()->inset();
210 DocIterator it = doc_iterator_begin(inset);
212 DocIterator et = doc_iterator_end(inset);
214 double best_dist = std::numeric_limits<double>::max();
215 DocIterator best_cursor = et;
217 for ( ; it != et; it.forwardPos()) {
218 // avoid invalid nesting when selecting
219 if (bv_funcs::status(&bv, it) == bv_funcs::CUR_INSIDE
220 && (!cur.selection() || positionable(it, cur.anchor_))) {
221 Point p = bv_funcs::getPos(bv, it, false);
224 if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
225 double const dx = xo - x;
226 double const dy = yo - y;
227 double const d = dx * dx + dy * dy;
228 //lyxerr << "itx: " << xo << " ity: " << yo << " d: " << d
229 // << " dx: " << dx << " dy: " << dy
230 // << " idx: " << it.idx() << " pos: " << it.pos()
233 // '<=' in order to take the last possible position
234 // this is important for clicking behind \sum in e.g. '\sum_i a'
235 if (d <= best_dist) {
236 //lyxerr << "*" << endl;
244 //lyxerr << "best_dist: " << best_dist << " cur:\n" << best_cursor << endl;
245 if (best_cursor == et)
247 cur.setCursor(best_cursor);
254 // be careful: this is called from the bv's constructor, too, so
255 // bv functions are not yet available!
256 LCursor::LCursor(BufferView & bv)
257 : DocIterator(), bv_(&bv), anchor_(), x_target_(-1),
258 selection_(false), mark_(false), logicalpos_(false)
262 void LCursor::reset(InsetBase & inset)
265 push_back(CursorSlice(inset));
266 anchor_ = DocIterator(inset);
273 // this (intentionally) does neither touch anchor nor selection status
274 void LCursor::setCursor(DocIterator const & cur)
276 DocIterator::operator=(cur);
280 void LCursor::dispatch(FuncRequest const & cmd0)
282 lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION
283 << " cmd: " << cmd0 << '\n'
289 FuncRequest cmd = cmd0;
290 LCursor safe = *this;
292 for (; depth(); pop()) {
293 lyxerr[Debug::DEBUG] << "LCursor::dispatch: cmd: "
294 << cmd0 << endl << *this << endl;
295 BOOST_ASSERT(pos() <= lastpos());
296 BOOST_ASSERT(idx() <= lastidx());
297 BOOST_ASSERT(pit() <= lastpit());
299 // The common case is 'LFUN handled, need update', so make the
300 // LFUN handler's life easier by assuming this as default value.
301 // The handler can reset the update and val flags if necessary.
302 disp_.update(Update::FitCursor | Update::Force);
303 disp_.dispatched(true);
304 inset().dispatch(*this, cmd);
305 if (disp_.dispatched())
308 // it completely to get a 'bomb early' behaviour in case this
309 // object will be used again.
310 if (!disp_.dispatched()) {
311 lyxerr[Debug::DEBUG] << "RESTORING OLD CURSOR!" << endl;
313 disp_.update(Update::None);
314 disp_.dispatched(false);
319 DispatchResult LCursor::result() const
325 BufferView & LCursor::bv() const
332 Buffer & LCursor::buffer() const
335 BOOST_ASSERT(bv_->buffer());
336 return *bv_->buffer();
342 BOOST_ASSERT(depth() >= 1);
347 void LCursor::push(InsetBase & p)
349 push_back(CursorSlice(p));
353 void LCursor::pushLeft(InsetBase & p)
355 BOOST_ASSERT(!empty());
356 //lyxerr << "Entering inset " << t << " left" << endl;
362 bool LCursor::popLeft()
364 BOOST_ASSERT(!empty());
365 //lyxerr << "Leaving inset to the left" << endl;
366 inset().notifyCursorLeaves(*this);
374 bool LCursor::popRight()
376 BOOST_ASSERT(!empty());
377 //lyxerr << "Leaving inset to the right" << endl;
378 inset().notifyCursorLeaves(*this);
387 int LCursor::currentMode()
389 BOOST_ASSERT(!empty());
390 for (int i = depth() - 1; i >= 0; --i) {
391 int res = operator[](i).inset().currentMode();
392 if (res != InsetBase::UNDECIDED_MODE)
395 return InsetBase::TEXT_MODE;
399 void LCursor::getPos(int & x, int & y) const
401 Point p = bv_funcs::getPos(bv(), *this, boundary());
407 void LCursor::resetAnchor()
414 bool LCursor::posLeft()
423 bool LCursor::posRight()
425 if (pos() == lastpos())
432 CursorSlice LCursor::anchor() const
434 BOOST_ASSERT(anchor_.depth() >= depth());
435 CursorSlice normal = anchor_[depth() - 1];
436 if (depth() < anchor_.depth() && top() <= normal) {
437 // anchor is behind cursor -> move anchor behind the inset
444 CursorSlice LCursor::selBegin() const
448 return anchor() < top() ? anchor() : top();
452 CursorSlice LCursor::selEnd() const
456 return anchor() > top() ? anchor() : top();
460 DocIterator LCursor::selectionBegin() const
464 DocIterator di = (anchor() < top() ? anchor_ : *this);
470 DocIterator LCursor::selectionEnd() const
474 DocIterator di = (anchor() > top() ? anchor_ : *this);
475 if (di.depth() > depth()) {
483 void LCursor::setSelection()
486 // A selection with no contents is not a selection
488 #warning doesnt look ok
490 if (pit() == anchor().pit() && pos() == anchor().pos())
495 void LCursor::setSelection(DocIterator const & where, int n)
504 void LCursor::clearSelection()
512 int & LCursor::x_target()
518 int LCursor::x_target() const
524 void LCursor::clearTargetX()
531 void LCursor::info(odocstream & os) const
533 for (int i = 1, n = depth(); i < n; ++i) {
534 operator[](i).inset().infoize(os);
538 prevInset()->infoize2(os);
539 // overwite old message
544 bool LCursor::selHandle(bool sel)
546 //lyxerr << "LCursor::selHandle" << endl;
547 if (sel == selection())
556 std::ostream & operator<<(std::ostream & os, LCursor const & cur)
558 os << "\n cursor: | anchor:\n";
559 for (size_t i = 0, n = cur.depth(); i != n; ++i) {
560 os << " " << cur[i] << " | ";
561 if (i < cur.anchor_.depth())
562 os << cur.anchor_[i];
564 os << "-------------------------------";
567 for (size_t i = cur.depth(), n = cur.anchor_.depth(); i < n; ++i) {
568 os << "------------------------------- | " << cur.anchor_[i] << "\n";
570 os << " selection: " << cur.selection_
571 << " x_target: " << cur.x_target_ << endl;
578 ///////////////////////////////////////////////////////////////////
580 // The part below is the non-integrated rest of the original math
581 // cursor. This should be either generalized for texted or moved
582 // back to mathed (in most cases to InsetMathNest).
584 ///////////////////////////////////////////////////////////////////
586 #include "mathed/InsetMathChar.h"
587 #include "mathed/InsetMathGrid.h"
588 #include "mathed/InsetMathScript.h"
589 #include "mathed/InsetMathUnknown.h"
590 #include "mathed/MathFactory.h"
591 #include "mathed/MathMacroArgument.h"
592 #include "mathed/MathStream.h"
593 #include "mathed/MathSupport.h"
598 //#define FILEDEBUG 1
601 bool LCursor::isInside(InsetBase const * p)
603 for (size_t i = 0; i != depth(); ++i)
604 if (&operator[](i).inset() == p)
610 void LCursor::leaveInset(InsetBase const & inset)
612 for (size_t i = 0; i != depth(); ++i) {
613 if (&operator[](i).inset() == &inset) {
621 bool LCursor::openable(MathAtom const & t) const
632 // we can't move into anything new during selection
633 if (depth() >= anchor_.depth())
635 if (!ptr_cmp(t.nucleus(), &anchor_[depth()].inset()))
642 void LCursor::setScreenPos(int x, int y)
645 bruteFind(*this, x, y, 0, bv().workWidth(), 0, bv().workHeight());
650 void LCursor::plainErase()
656 void LCursor::markInsert()
658 insert(char_type(0));
662 void LCursor::markErase()
668 void LCursor::plainInsert(MathAtom const & t)
670 cell().insert(pos(), t);
675 void LCursor::insert(docstring const & str)
677 for_each(str.begin(), str.end(),
678 boost::bind(static_cast<void(LCursor::*)(char_type)>
679 (&LCursor::insert), this, _1));
683 void LCursor::insert(char_type c)
685 //lyxerr << "LCursor::insert char '" << c << "'" << endl;
686 BOOST_ASSERT(!empty());
688 cap::selClearOrDel(*this);
689 insert(new InsetMathChar(c));
691 text()->insertChar(*this, c);
696 void LCursor::insert(MathAtom const & t)
698 //lyxerr << "LCursor::insert MathAtom '" << t << "'" << endl;
700 cap::selClearOrDel(*this);
705 void LCursor::insert(InsetBase * inset)
708 insert(MathAtom(inset));
710 text()->insertInset(*this, inset);
714 void LCursor::niceInsert(docstring const & t)
725 void LCursor::niceInsert(MathAtom const & t)
728 docstring const safe = cap::grabAndEraseSelection(*this);
730 // enter the new inset and move the contents of the selection if possible
733 // be careful here: don't use 'pushLeft(t)' as this we need to
734 // push the clone, not the original
735 pushLeft(*nextInset());
736 // We may not use niceInsert here (recursion)
744 void LCursor::insert(MathArray const & ar)
748 cap::eraseSelection(*this);
749 cell().insert(pos(), ar);
754 bool LCursor::backspace()
756 autocorrect() = false;
764 // If empty cell, and not part of a big cell
765 if (lastpos() == 0 && inset().nargs() == 1) {
767 // Directly delete empty cell: [|[]] => [|]
773 // [|], can not delete from inside
783 InsetMathUnknown * p = activeMacro();
784 if (p->name().size() > 1) {
785 p->setName(p->name().substr(0, p->name().size() - 1));
790 if (pos() != 0 && prevAtom()->nargs() > 0) {
791 // let's require two backspaces for 'big stuff' and
792 // highlight on the first
804 bool LCursor::erase()
806 autocorrect() = false;
815 // delete empty cells if possible
816 if (pos() == lastpos() && inset().idxDelete(idx()))
819 // special behaviour when in last position of cell
820 if (pos() == lastpos()) {
821 bool one_cell = inset().nargs() == 1;
822 if (one_cell && lastpos() == 0) {
824 // Directly delete empty cell: [|[]] => [|]
830 // [|], can not delete from inside
835 inset().idxGlue(idx());
839 // 'clever' UI hack: only erase large items if previously slected
840 if (pos() != lastpos() && nextAtom()->nargs() > 0) {
855 DocIterator save = *this;
859 autocorrect() = false;
867 DocIterator save = *this;
871 autocorrect() = false;
876 bool LCursor::macroModeClose()
880 InsetMathUnknown * p = activeMacro();
882 docstring const s = p->name();
886 // do nothing if the macro name is empty
890 // prevent entering of recursive macros
891 // FIXME: this is only a weak attempt... only prevents immediate
893 docstring const name = s.substr(1);
894 InsetBase const * macro = innerInsetOfType(InsetBase::MATHMACRO_CODE);
895 if (macro && macro->getInsetName() == name)
896 lyxerr << "can't enter recursive macro" << endl;
898 InsetMathNest * const in = inset().asInsetMath()->asNestInset();
899 if (in && in->interpretString(*this, s))
901 plainInsert(createInsetMath(name));
906 docstring LCursor::macroName()
908 return inMacroMode() ? activeMacro()->name() : docstring();
912 void LCursor::handleNest(MathAtom const & a, int c)
914 //lyxerr << "LCursor::handleNest: " << c << endl;
916 asArray(cap::grabAndEraseSelection(*this), t.nucleus()->cell(c));
919 pushLeft(*nextInset());
923 int LCursor::targetX() const
925 if (x_target() != -1)
934 void LCursor::setTargetX()
943 bool LCursor::inMacroMode() const
947 InsetMathUnknown const * p = prevAtom()->asUnknownInset();
948 return p && !p->final();
952 InsetMathUnknown * LCursor::activeMacro()
954 return inMacroMode() ? prevAtom().nucleus()->asUnknownInset() : 0;
958 void LCursor::pullArg()
963 MathArray ar = cell();
964 if (popLeft() && inMathed()) {
966 cell().insert(pos(), ar);
969 //formula()->mutateToText();
974 void LCursor::touch()
980 DocIterator::const_iterator it = begin();
981 DocIterator::const_iterator et = end();
982 for ( ; it != et; ++it)
988 void LCursor::normalize()
990 if (idx() > lastidx()) {
991 lyxerr << "this should not really happen - 1: "
992 << idx() << ' ' << nargs()
993 << " in: " << &inset() << endl;
997 if (pos() > lastpos()) {
998 lyxerr << "this should not really happen - 2: "
999 << pos() << ' ' << lastpos() << " in idx: " << idx()
1001 odocstringstream os;
1002 WriteStream wi(os, false, true);
1003 inset().asInsetMath()->write(wi);
1004 lyxerr << to_utf8(os.str()) << endl;
1010 bool LCursor::goUpDown(bool up)
1012 // Be warned: The 'logic' implemented in this function is highly
1013 // fragile. A distance of one pixel or a '<' vs '<=' _really
1014 // matters. So fiddle around with it only if you think you know
1015 // what you are doing!
1021 // check if we had something else in mind, if not, this is the future
1023 if (x_target() == -1)
1028 // try neigbouring script insets
1032 InsetMathScript const * p = prevAtom()->asScriptInset();
1033 if (p && p->has(up)) {
1035 push(*const_cast<InsetMathScript*>(p));
1036 idx() = p->idxOfScript(up);
1043 if (pos() != lastpos()) {
1044 InsetMathScript const * p = nextAtom()->asScriptInset();
1045 if (p && p->has(up)) {
1046 push(*const_cast<InsetMathScript*>(p));
1047 idx() = p->idxOfScript(up);
1054 // FIXME: Switch this on for more robust movement
1057 return bruteFind3(*this, xo, yo, up);
1060 //xarray().boundingBox(xlow, xhigh, ylow, yhigh);
1065 //if (bruteFind(*this, xo, yo, xlow, xhigh, ylow, yhigh)) {
1066 // lyxerr << "updown: handled by brute find in the same cell" << endl;
1070 // try to find an inset that knows better then we
1072 //lyxerr << "updown: We are in " << &inset() << " idx: " << idx() << endl;
1074 if (inset().idxUpDown(*this, up)) {
1075 //lyxerr << "idxUpDown triggered" << endl;
1076 // try to find best position within this inset
1078 setCursor(bruteFind2(*this, xo, yo));
1082 // no such inset found, just take something "above"
1084 //lyxerr << "updown: popleft failed (strange case)" << endl;
1085 int ylow = up ? 0 : yo + 1;
1086 int yhigh = up ? yo - 1 : bv().workHeight();
1087 return bruteFind(*this, xo, yo, 0, bv().workWidth(), ylow, yhigh);
1090 // any improvement so far?
1091 //lyxerr << "updown: popLeft succeeded" << endl;
1095 if (up ? ynew < yo : ynew > yo)
1099 // we should not come here.
1100 BOOST_ASSERT(false);
1105 void LCursor::handleFont(string const & font)
1107 lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION << ": " << font << endl;
1111 safe = cap::grabAndEraseSelection(*this);
1114 if (lastpos() != 0) {
1115 // something left in the cell
1117 // cursor in first position
1119 } else if (pos() == lastpos()) {
1120 // cursor in last position
1123 // cursor in between. split cell
1124 MathArray::iterator bt = cell().begin();
1125 MathAtom at = createInsetMath(from_utf8(font));
1126 at.nucleus()->cell(0) = MathArray(bt, bt + pos());
1127 cell().erase(bt, bt + pos());
1132 // nothing left in the cell
1140 void LCursor::message(docstring const & msg) const
1142 theLyXFunc().setMessage(msg);
1146 void LCursor::errorMessage(docstring const & msg) const
1148 theLyXFunc().setErrorMessage(msg);
1152 docstring LCursor::selectionAsString(bool label) const
1158 Buffer const & buffer = *bv().buffer();
1159 ParagraphList const & pars = text()->paragraphs();
1161 // should be const ...
1162 pit_type startpit = selBegin().pit();
1163 pit_type endpit = selEnd().pit();
1164 size_t const startpos = selBegin().pos();
1165 size_t const endpos = selEnd().pos();
1167 if (startpit == endpit)
1168 return pars[startpit].asString(buffer, startpos, endpos, label);
1170 // First paragraph in selection
1171 docstring result = pars[startpit].
1172 asString(buffer, startpos, pars[startpit].size(), label) + "\n\n";
1174 // The paragraphs in between (if any)
1175 for (pit_type pit = startpit + 1; pit != endpit; ++pit) {
1176 Paragraph const & par = pars[pit];
1177 result += par.asString(buffer, 0, par.size(), label) + "\n\n";
1180 // Last paragraph in selection
1181 result += pars[endpit].asString(buffer, 0, endpos, label);
1187 return cap::grabSelection(*this);
1193 string LCursor::currentState()
1196 odocstringstream os;
1198 return to_utf8(os.str());
1202 return text()->currentState(*this);
1208 docstring LCursor::getPossibleLabel()
1210 return inMathed() ? from_ascii("eq:") : text()->getPossibleLabel(*this);
1214 Encoding const * LCursor::getEncoding() const
1221 // go up until first non-0 text is hit
1222 // (innermost text is 0 in mathed)
1223 for (s = depth() - 1; s >= 0; --s)
1224 if (operator[](s).text())
1226 CursorSlice const & sl = operator[](s);
1227 LyXText const & text = *sl.text();
1228 LyXFont font = text.getPar(sl.pit()).getFont(
1229 bv().buffer()->params(), sl.pos(), outerFont(sl.pit(), text.paragraphs()));
1230 return font.language()->encoding();
1234 void LCursor::undispatched()
1236 disp_.dispatched(false);
1240 void LCursor::dispatched()
1242 disp_.dispatched(true);
1246 void LCursor::updateFlags(Update::flags f)
1252 void LCursor::noUpdate()
1254 disp_.update(Update::None);
1258 LyXFont LCursor::getFont() const
1260 // HACK. far from being perfect...
1262 // go up until first non-0 text is hit
1263 // (innermost text is 0 in mathed)
1264 for (s = depth() - 1; s >= 0; --s)
1265 if (operator[](s).text())
1267 CursorSlice const & sl = operator[](s);
1268 LyXText const & text = *sl.text();
1269 LyXFont font = text.getPar(sl.pit()).getFont(
1270 bv().buffer()->params(),
1272 outerFont(sl.pit(), text.paragraphs()));
1278 void LCursor::fixIfBroken()
1280 // find out last good level
1281 LCursor copy = *this;
1282 size_t newdepth = depth();
1283 while (!copy.empty()) {
1284 if (copy.idx() > copy.lastidx()) {
1285 lyxerr << "wrong idx " << copy.idx()
1286 << ", max is " << copy.lastidx()
1287 << " at level " << copy.depth()
1288 << ". Trying to correct this." << endl;
1289 newdepth = copy.depth() - 1;
1291 else if (copy.pit() > copy.lastpit()) {
1292 lyxerr << "wrong pit " << copy.pit()
1293 << ", max is " << copy.lastpit()
1294 << " at level " << copy.depth()
1295 << ". Trying to correct this." << endl;
1296 newdepth = copy.depth() - 1;
1298 else if (copy.pos() > copy.lastpos()) {
1299 lyxerr << "wrong pos " << copy.pos()
1300 << ", max is " << copy.lastpos()
1301 << " at level " << copy.depth()
1302 << ". Trying to correct this." << endl;
1303 newdepth = copy.depth() - 1;
1307 // shrink cursor to a size where everything is valid, possibly
1309 while (depth() > newdepth) {
1311 lyxerr << "correcting cursor to level " << depth() << endl;