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"
43 #include "support/limited_stack.h"
45 #include <boost/assert.hpp>
46 #include <boost/bind.hpp>
47 #include <boost/current_function.hpp>
58 #ifndef CXX_GLOBAL_CSTD
67 positionable(DocIterator const & cursor, DocIterator const & anchor)
69 // avoid deeper nested insets when selecting
70 if (cursor.depth() > anchor.depth())
73 // anchor might be deeper, should have same path then
74 for (size_t i = 0; i < cursor.depth(); ++i)
75 if (&cursor[i].inset() != &anchor[i].inset())
78 // position should be ok.
83 // Find position closest to (x, y) in cell given by iter.
84 // Used only in mathed
85 DocIterator bruteFind2(LCursor const & c, int x, int y)
87 double best_dist = std::numeric_limits<double>::max();
94 et.top().pos() = et.top().asInsetMath()->cell(et.top().idx()).size();
95 for (size_t i = 0; ; ++i) {
98 InsetBase const * inset = &it.inset();
99 std::map<InsetBase const *, Point> const & data =
100 c.bv().coordCache().getInsets().getData();
101 std::map<InsetBase const *, Point>::const_iterator I = data.find(inset);
103 // FIXME: in the case where the inset is not in the cache, this
104 // means that no part of it is visible on screen. In this case
105 // we don't do elaborate search and we just return the forwarded
106 // DocIterator at its beginning.
107 if (I == data.end()) {
113 inset->cursorPos(c.bv(), it.top(), c.boundary(), xo, yo);
114 // Convert to absolute
117 double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
118 // '<=' in order to take the last possible position
119 // this is important for clicking behind \sum in e.g. '\sum_i a'
120 lyxerr[Debug::DEBUG] << "i: " << i << " d: " << d
121 << " best: " << best_dist << endl;
122 if (d <= best_dist) {
134 /// moves position closest to (x, y) in given box
135 bool bruteFind(LCursor & cursor,
136 int x, int y, int xlow, int xhigh, int ylow, int yhigh)
138 BOOST_ASSERT(!cursor.empty());
139 InsetBase & inset = cursor[0].inset();
140 BufferView & bv = cursor.bv();
142 CoordCache::InnerParPosCache const & cache =
143 bv.coordCache().getParPos().find(cursor.bottom().text())->second;
144 // Get an iterator on the first paragraph in the cache
145 DocIterator it(inset);
146 it.push_back(CursorSlice(inset));
147 it.pit() = cache.begin()->first;
148 // Get an iterator after the last paragraph in the cache
149 DocIterator et(inset);
150 et.push_back(CursorSlice(inset));
151 et.pit() = boost::prior(cache.end())->first;
152 if (et.pit() >= et.lastpit())
153 et = doc_iterator_end(inset);
157 double best_dist = std::numeric_limits<double>::max();;
158 DocIterator best_cursor = et;
160 for ( ; it != et; it.forwardPos(true)) {
161 // avoid invalid nesting when selecting
162 if (!cursor.selection() || positionable(it, cursor.anchor_)) {
163 Point p = bv_funcs::getPos(bv, it, false);
166 if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
167 double const dx = xo - x;
168 double const dy = yo - y;
169 double const d = dx * dx + dy * dy;
170 // '<=' in order to take the last possible position
171 // this is important for clicking behind \sum in e.g. '\sum_i a'
172 if (d <= best_dist) {
173 // lyxerr << "*" << endl;
181 if (best_cursor != et) {
182 cursor.setCursor(best_cursor);
190 /// moves position closest to (x, y) in given box
191 bool bruteFind3(LCursor & cur, int x, int y, bool up)
193 BufferView & bv = cur.bv();
194 int ylow = up ? 0 : y + 1;
195 int yhigh = up ? y - 1 : bv.workHeight();
197 int xhigh = bv.workWidth();
199 // FIXME: bit more work needed to get 'from' and 'to' right.
200 pit_type from = cur.bottom().pit();
201 //pit_type to = cur.bottom().pit();
202 //lyxerr << "Pit start: " << from << endl;
204 //lyxerr << "bruteFind3: x: " << x << " y: " << y
205 // << " xlow: " << xlow << " xhigh: " << xhigh
206 // << " ylow: " << ylow << " yhigh: " << yhigh
208 InsetBase & inset = bv.buffer()->inset();
209 DocIterator it = doc_iterator_begin(inset);
211 DocIterator et = doc_iterator_end(inset);
213 double best_dist = std::numeric_limits<double>::max();
214 DocIterator best_cursor = et;
216 for ( ; it != et; it.forwardPos()) {
217 // avoid invalid nesting when selecting
218 if (bv_funcs::status(&bv, it) == bv_funcs::CUR_INSIDE
219 && (!cur.selection() || positionable(it, cur.anchor_))) {
220 Point p = bv_funcs::getPos(bv, it, false);
223 if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
224 double const dx = xo - x;
225 double const dy = yo - y;
226 double const d = dx * dx + dy * dy;
227 //lyxerr << "itx: " << xo << " ity: " << yo << " d: " << d
228 // << " dx: " << dx << " dy: " << dy
229 // << " idx: " << it.idx() << " pos: " << it.pos()
232 // '<=' in order to take the last possible position
233 // this is important for clicking behind \sum in e.g. '\sum_i a'
234 if (d <= best_dist) {
235 //lyxerr << "*" << endl;
243 //lyxerr << "best_dist: " << best_dist << " cur:\n" << best_cursor << endl;
244 if (best_cursor == et)
246 cur.setCursor(best_cursor);
253 // be careful: this is called from the bv's constructor, too, so
254 // bv functions are not yet available!
255 LCursor::LCursor(BufferView & bv)
256 : DocIterator(), bv_(&bv), anchor_(), x_target_(-1),
257 selection_(false), mark_(false), logicalpos_(false)
261 void LCursor::reset(InsetBase & inset)
264 push_back(CursorSlice(inset));
265 anchor_ = DocIterator(inset);
272 // this (intentionally) does neither touch anchor nor selection status
273 void LCursor::setCursor(DocIterator const & cur)
275 DocIterator::operator=(cur);
279 void LCursor::dispatch(FuncRequest const & cmd0)
281 lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION
282 << " cmd: " << cmd0 << '\n'
288 FuncRequest cmd = cmd0;
289 LCursor safe = *this;
291 for (; depth(); pop()) {
292 lyxerr[Debug::DEBUG] << "LCursor::dispatch: cmd: "
293 << cmd0 << endl << *this << endl;
294 BOOST_ASSERT(pos() <= lastpos());
295 BOOST_ASSERT(idx() <= lastidx());
296 BOOST_ASSERT(pit() <= lastpit());
298 // The common case is 'LFUN handled, need update', so make the
299 // LFUN handler's life easier by assuming this as default value.
300 // The handler can reset the update and val flags if necessary.
301 disp_.update(Update::FitCursor | Update::Force);
302 disp_.dispatched(true);
303 inset().dispatch(*this, cmd);
304 if (disp_.dispatched())
307 // it completely to get a 'bomb early' behaviour in case this
308 // object will be used again.
309 if (!disp_.dispatched()) {
310 lyxerr[Debug::DEBUG] << "RESTORING OLD CURSOR!" << endl;
312 disp_.update(Update::None);
313 disp_.dispatched(false);
318 DispatchResult LCursor::result() const
324 BufferView & LCursor::bv() const
331 Buffer & LCursor::buffer() const
334 BOOST_ASSERT(bv_->buffer());
335 return *bv_->buffer();
341 BOOST_ASSERT(depth() >= 1);
346 void LCursor::push(InsetBase & p)
348 push_back(CursorSlice(p));
352 void LCursor::pushLeft(InsetBase & p)
354 BOOST_ASSERT(!empty());
355 //lyxerr << "Entering inset " << t << " left" << endl;
361 bool LCursor::popLeft()
363 BOOST_ASSERT(!empty());
364 //lyxerr << "Leaving inset to the left" << endl;
365 inset().notifyCursorLeaves(*this);
373 bool LCursor::popRight()
375 BOOST_ASSERT(!empty());
376 //lyxerr << "Leaving inset to the right" << endl;
377 inset().notifyCursorLeaves(*this);
386 int LCursor::currentMode()
388 BOOST_ASSERT(!empty());
389 for (int i = depth() - 1; i >= 0; --i) {
390 int res = operator[](i).inset().currentMode();
391 if (res != InsetBase::UNDECIDED_MODE)
394 return InsetBase::TEXT_MODE;
398 void LCursor::getPos(int & x, int & y) const
400 Point p = bv_funcs::getPos(bv(), *this, boundary());
406 void LCursor::resetAnchor()
413 bool LCursor::posLeft()
422 bool LCursor::posRight()
424 if (pos() == lastpos())
431 CursorSlice LCursor::anchor() const
433 BOOST_ASSERT(anchor_.depth() >= depth());
434 CursorSlice normal = anchor_[depth() - 1];
435 if (depth() < anchor_.depth() && top() <= normal) {
436 // anchor is behind cursor -> move anchor behind the inset
443 CursorSlice LCursor::selBegin() const
447 return anchor() < top() ? anchor() : top();
451 CursorSlice LCursor::selEnd() const
455 return anchor() > top() ? anchor() : top();
459 DocIterator LCursor::selectionBegin() const
463 DocIterator di = (anchor() < top() ? anchor_ : *this);
469 DocIterator LCursor::selectionEnd() const
473 DocIterator di = (anchor() > top() ? anchor_ : *this);
474 if (di.depth() > depth()) {
482 void LCursor::setSelection()
485 // A selection with no contents is not a selection
487 #warning doesnt look ok
489 if (pit() == anchor().pit() && pos() == anchor().pos())
494 void LCursor::setSelection(DocIterator const & where, int n)
503 void LCursor::clearSelection()
511 int & LCursor::x_target()
517 int LCursor::x_target() const
523 void LCursor::clearTargetX()
530 void LCursor::info(odocstream & os) const
532 for (int i = 1, n = depth(); i < n; ++i) {
533 operator[](i).inset().infoize(os);
537 prevInset()->infoize2(os);
538 // overwite old message
543 bool LCursor::selHandle(bool sel)
545 //lyxerr << "LCursor::selHandle" << endl;
546 if (sel == selection())
555 std::ostream & operator<<(std::ostream & os, LCursor const & cur)
557 os << "\n cursor: | anchor:\n";
558 for (size_t i = 0, n = cur.depth(); i != n; ++i) {
559 os << " " << cur[i] << " | ";
560 if (i < cur.anchor_.depth())
561 os << cur.anchor_[i];
563 os << "-------------------------------";
566 for (size_t i = cur.depth(), n = cur.anchor_.depth(); i < n; ++i) {
567 os << "------------------------------- | " << cur.anchor_[i] << "\n";
569 os << " selection: " << cur.selection_
570 << " x_target: " << cur.x_target_ << endl;
577 ///////////////////////////////////////////////////////////////////
579 // The part below is the non-integrated rest of the original math
580 // cursor. This should be either generalized for texted or moved
581 // back to mathed (in most cases to InsetMathNest).
583 ///////////////////////////////////////////////////////////////////
585 #include "mathed/InsetMathChar.h"
586 #include "mathed/InsetMathGrid.h"
587 #include "mathed/InsetMathScript.h"
588 #include "mathed/InsetMathUnknown.h"
589 #include "mathed/MathFactory.h"
590 #include "mathed/MathMacroArgument.h"
591 #include "mathed/MathStream.h"
592 #include "mathed/MathSupport.h"
597 //#define FILEDEBUG 1
600 bool LCursor::isInside(InsetBase const * p)
602 for (size_t i = 0; i != depth(); ++i)
603 if (&operator[](i).inset() == p)
609 void LCursor::leaveInset(InsetBase const & inset)
611 for (size_t i = 0; i != depth(); ++i) {
612 if (&operator[](i).inset() == &inset) {
620 bool LCursor::openable(MathAtom const & t) const
631 // we can't move into anything new during selection
632 if (depth() >= anchor_.depth())
634 if (!ptr_cmp(t.nucleus(), &anchor_[depth()].inset()))
641 void LCursor::setScreenPos(int x, int y)
644 bruteFind(*this, x, y, 0, bv().workWidth(), 0, bv().workHeight());
649 void LCursor::plainErase()
655 void LCursor::markInsert()
657 insert(char_type(0));
661 void LCursor::markErase()
667 void LCursor::plainInsert(MathAtom const & t)
669 cell().insert(pos(), t);
674 void LCursor::insert(docstring const & str)
676 for_each(str.begin(), str.end(),
677 boost::bind(static_cast<void(LCursor::*)(char_type)>
678 (&LCursor::insert), this, _1));
682 void LCursor::insert(char_type c)
684 //lyxerr << "LCursor::insert char '" << c << "'" << endl;
685 BOOST_ASSERT(!empty());
687 cap::selClearOrDel(*this);
688 insert(new InsetMathChar(c));
690 text()->insertChar(*this, c);
695 void LCursor::insert(MathAtom const & t)
697 //lyxerr << "LCursor::insert MathAtom '" << t << "'" << endl;
699 cap::selClearOrDel(*this);
704 void LCursor::insert(InsetBase * inset)
707 insert(MathAtom(inset));
709 text()->insertInset(*this, inset);
713 void LCursor::niceInsert(docstring const & t)
724 void LCursor::niceInsert(MathAtom const & t)
727 docstring const safe = cap::grabAndEraseSelection(*this);
729 // enter the new inset and move the contents of the selection if possible
732 // be careful here: don't use 'pushLeft(t)' as this we need to
733 // push the clone, not the original
734 pushLeft(*nextInset());
735 // We may not use niceInsert here (recursion)
743 void LCursor::insert(MathArray const & ar)
747 cap::eraseSelection(*this);
748 cell().insert(pos(), ar);
753 bool LCursor::backspace()
755 autocorrect() = false;
763 // If empty cell, and not part of a big cell
764 if (lastpos() == 0 && inset().nargs() == 1) {
766 // Directly delete empty cell: [|[]] => [|]
772 // [|], can not delete from inside
782 InsetMathUnknown * p = activeMacro();
783 if (p->name().size() > 1) {
784 p->setName(p->name().substr(0, p->name().size() - 1));
789 if (pos() != 0 && prevAtom()->nargs() > 0) {
790 // let's require two backspaces for 'big stuff' and
791 // highlight on the first
803 bool LCursor::erase()
805 autocorrect() = false;
814 // delete empty cells if possible
815 if (pos() == lastpos() && inset().idxDelete(idx()))
818 // special behaviour when in last position of cell
819 if (pos() == lastpos()) {
820 bool one_cell = inset().nargs() == 1;
821 if (one_cell && lastpos() == 0) {
823 // Directly delete empty cell: [|[]] => [|]
829 // [|], can not delete from inside
834 inset().idxGlue(idx());
838 // 'clever' UI hack: only erase large items if previously slected
839 if (pos() != lastpos() && nextAtom()->nargs() > 0) {
854 DocIterator save = *this;
858 autocorrect() = false;
866 DocIterator save = *this;
870 autocorrect() = false;
875 bool LCursor::macroModeClose()
879 InsetMathUnknown * p = activeMacro();
881 docstring const s = p->name();
885 // do nothing if the macro name is empty
889 // prevent entering of recursive macros
890 // FIXME: this is only a weak attempt... only prevents immediate
892 docstring const name = s.substr(1);
893 InsetBase const * macro = innerInsetOfType(InsetBase::MATHMACRO_CODE);
894 if (macro && macro->getInsetName() == name)
895 lyxerr << "can't enter recursive macro" << endl;
897 InsetMathNest * const in = inset().asInsetMath()->asNestInset();
898 if (in && in->interpretString(*this, s))
900 plainInsert(createInsetMath(name));
905 docstring LCursor::macroName()
907 return inMacroMode() ? activeMacro()->name() : docstring();
911 void LCursor::handleNest(MathAtom const & a, int c)
913 //lyxerr << "LCursor::handleNest: " << c << endl;
915 asArray(cap::grabAndEraseSelection(*this), t.nucleus()->cell(c));
918 pushLeft(*nextInset());
922 int LCursor::targetX() const
924 if (x_target() != -1)
933 void LCursor::setTargetX()
942 bool LCursor::inMacroMode() const
946 InsetMathUnknown const * p = prevAtom()->asUnknownInset();
947 return p && !p->final();
951 InsetMathUnknown * LCursor::activeMacro()
953 return inMacroMode() ? prevAtom().nucleus()->asUnknownInset() : 0;
957 void LCursor::pullArg()
962 MathArray ar = cell();
963 if (popLeft() && inMathed()) {
965 cell().insert(pos(), ar);
968 //formula()->mutateToText();
973 void LCursor::touch()
979 DocIterator::const_iterator it = begin();
980 DocIterator::const_iterator et = end();
981 for ( ; it != et; ++it)
987 void LCursor::normalize()
989 if (idx() > lastidx()) {
990 lyxerr << "this should not really happen - 1: "
991 << idx() << ' ' << nargs()
992 << " in: " << &inset() << endl;
996 if (pos() > lastpos()) {
997 lyxerr << "this should not really happen - 2: "
998 << pos() << ' ' << lastpos() << " in idx: " << idx()
1000 odocstringstream os;
1001 WriteStream wi(os, false, true);
1002 inset().asInsetMath()->write(wi);
1003 lyxerr << to_utf8(os.str()) << endl;
1009 bool LCursor::goUpDown(bool up)
1011 // Be warned: The 'logic' implemented in this function is highly
1012 // fragile. A distance of one pixel or a '<' vs '<=' _really
1013 // matters. So fiddle around with it only if you think you know
1014 // what you are doing!
1020 // check if we had something else in mind, if not, this is the future
1022 if (x_target() == -1)
1027 // try neigbouring script insets
1031 InsetMathScript const * p = prevAtom()->asScriptInset();
1032 if (p && p->has(up)) {
1034 push(*const_cast<InsetMathScript*>(p));
1035 idx() = p->idxOfScript(up);
1042 if (pos() != lastpos()) {
1043 InsetMathScript const * p = nextAtom()->asScriptInset();
1044 if (p && p->has(up)) {
1045 push(*const_cast<InsetMathScript*>(p));
1046 idx() = p->idxOfScript(up);
1053 // FIXME: Switch this on for more robust movement
1056 return bruteFind3(*this, xo, yo, up);
1059 //xarray().boundingBox(xlow, xhigh, ylow, yhigh);
1064 //if (bruteFind(*this, xo, yo, xlow, xhigh, ylow, yhigh)) {
1065 // lyxerr << "updown: handled by brute find in the same cell" << endl;
1069 // try to find an inset that knows better then we
1071 //lyxerr << "updown: We are in " << &inset() << " idx: " << idx() << endl;
1073 if (inset().idxUpDown(*this, up)) {
1074 //lyxerr << "idxUpDown triggered" << endl;
1075 // try to find best position within this inset
1077 setCursor(bruteFind2(*this, xo, yo));
1081 // no such inset found, just take something "above"
1083 //lyxerr << "updown: popleft failed (strange case)" << endl;
1084 int ylow = up ? 0 : yo + 1;
1085 int yhigh = up ? yo - 1 : bv().workHeight();
1086 return bruteFind(*this, xo, yo, 0, bv().workWidth(), ylow, yhigh);
1089 // any improvement so far?
1090 //lyxerr << "updown: popLeft succeeded" << endl;
1094 if (up ? ynew < yo : ynew > yo)
1098 // we should not come here.
1099 BOOST_ASSERT(false);
1104 void LCursor::handleFont(string const & font)
1106 lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION << ": " << font << endl;
1110 safe = cap::grabAndEraseSelection(*this);
1113 if (lastpos() != 0) {
1114 // something left in the cell
1116 // cursor in first position
1118 } else if (pos() == lastpos()) {
1119 // cursor in last position
1122 // cursor in between. split cell
1123 MathArray::iterator bt = cell().begin();
1124 MathAtom at = createInsetMath(from_utf8(font));
1125 at.nucleus()->cell(0) = MathArray(bt, bt + pos());
1126 cell().erase(bt, bt + pos());
1131 // nothing left in the cell
1139 void LCursor::message(docstring const & msg) const
1141 theLyXFunc().setMessage(msg);
1145 void LCursor::errorMessage(docstring const & msg) const
1147 theLyXFunc().setErrorMessage(msg);
1151 docstring LCursor::selectionAsString(bool label) const
1157 Buffer const & buffer = *bv().buffer();
1158 ParagraphList const & pars = text()->paragraphs();
1160 // should be const ...
1161 pit_type startpit = selBegin().pit();
1162 pit_type endpit = selEnd().pit();
1163 size_t const startpos = selBegin().pos();
1164 size_t const endpos = selEnd().pos();
1166 if (startpit == endpit)
1167 return pars[startpit].asString(buffer, startpos, endpos, label);
1169 // First paragraph in selection
1170 docstring result = pars[startpit].
1171 asString(buffer, startpos, pars[startpit].size(), label) + "\n\n";
1173 // The paragraphs in between (if any)
1174 for (pit_type pit = startpit + 1; pit != endpit; ++pit) {
1175 Paragraph const & par = pars[pit];
1176 result += par.asString(buffer, 0, par.size(), label) + "\n\n";
1179 // Last paragraph in selection
1180 result += pars[endpit].asString(buffer, 0, endpos, label);
1186 return cap::grabSelection(*this);
1192 string LCursor::currentState()
1195 odocstringstream os;
1197 return to_utf8(os.str());
1201 return text()->currentState(*this);
1207 docstring LCursor::getPossibleLabel()
1209 return inMathed() ? from_ascii("eq:") : text()->getPossibleLabel(*this);
1213 Encoding const * LCursor::getEncoding() const
1220 // go up until first non-0 text is hit
1221 // (innermost text is 0 in mathed)
1222 for (s = depth() - 1; s >= 0; --s)
1223 if (operator[](s).text())
1225 CursorSlice const & sl = operator[](s);
1226 LyXText const & text = *sl.text();
1227 LyXFont font = text.getPar(sl.pit()).getFont(
1228 bv().buffer()->params(), sl.pos(), outerFont(sl.pit(), text.paragraphs()));
1229 return font.language()->encoding();
1233 void LCursor::undispatched()
1235 disp_.dispatched(false);
1239 void LCursor::dispatched()
1241 disp_.dispatched(true);
1245 void LCursor::updateFlags(Update::flags f)
1251 void LCursor::noUpdate()
1253 disp_.update(Update::None);
1257 LyXFont LCursor::getFont() const
1259 // HACK. far from being perfect...
1261 // go up until first non-0 text is hit
1262 // (innermost text is 0 in mathed)
1263 for (s = depth() - 1; s >= 0; --s)
1264 if (operator[](s).text())
1266 CursorSlice const & sl = operator[](s);
1267 LyXText const & text = *sl.text();
1268 LyXFont font = text.getPar(sl.pit()).getFont(
1269 bv().buffer()->params(),
1271 outerFont(sl.pit(), text.paragraphs()));
1277 void LCursor::fixIfBroken()
1279 // find out last good level
1280 LCursor copy = *this;
1281 size_t newdepth = depth();
1282 while (!copy.empty()) {
1283 if (copy.idx() > copy.lastidx()) {
1284 lyxerr << "wrong idx " << copy.idx()
1285 << ", max is " << copy.lastidx()
1286 << " at level " << copy.depth()
1287 << ". Trying to correct this." << endl;
1288 newdepth = copy.depth() - 1;
1290 else if (copy.pit() > copy.lastpit()) {
1291 lyxerr << "wrong pit " << copy.pit()
1292 << ", max is " << copy.lastpit()
1293 << " at level " << copy.depth()
1294 << ". Trying to correct this." << endl;
1295 newdepth = copy.depth() - 1;
1297 else if (copy.pos() > copy.lastpos()) {
1298 lyxerr << "wrong pos " << copy.pos()
1299 << ", max is " << copy.lastpos()
1300 << " at level " << copy.depth()
1301 << ". Trying to correct this." << endl;
1302 newdepth = copy.depth() - 1;
1306 // shrink cursor to a size where everything is valid, possibly
1308 while (depth() > newdepth) {
1310 lyxerr << "correcting cursor to level " << depth() << endl;