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/MacroTable.h"
44 #include "support/limited_stack.h"
46 #include <boost/assert.hpp>
47 #include <boost/bind.hpp>
48 #include <boost/current_function.hpp>
65 positionable(DocIterator const & cursor, DocIterator const & anchor)
67 // avoid deeper nested insets when selecting
68 if (cursor.depth() > anchor.depth())
71 // anchor might be deeper, should have same path then
72 for (size_t i = 0; i < cursor.depth(); ++i)
73 if (&cursor[i].inset() != &anchor[i].inset())
76 // position should be ok.
81 // Find position closest to (x, y) in cell given by iter.
82 // Used only in mathed
83 DocIterator bruteFind2(Cursor const & c, int x, int y)
85 double best_dist = std::numeric_limits<double>::max();
92 et.top().pos() = et.top().asInsetMath()->cell(et.top().idx()).size();
93 for (size_t i = 0;; ++i) {
96 Inset const * inset = &it.inset();
97 std::map<Inset const *, Point> const & data =
98 c.bv().coordCache().getInsets().getData();
99 std::map<Inset const *, Point>::const_iterator I = data.find(inset);
101 // FIXME: in the case where the inset is not in the cache, this
102 // means that no part of it is visible on screen. In this case
103 // we don't do elaborate search and we just return the forwarded
104 // DocIterator at its beginning.
105 if (I == data.end()) {
111 inset->cursorPos(c.bv(), it.top(), c.boundary(), xo, yo);
112 // Convert to absolute
115 double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
116 // '<=' in order to take the last possible position
117 // this is important for clicking behind \sum in e.g. '\sum_i a'
118 LYXERR(Debug::DEBUG) << "i: " << i << " d: " << d
119 << " best: " << best_dist << endl;
120 if (d <= best_dist) {
132 /// moves position closest to (x, y) in given box
133 bool bruteFind(Cursor & cursor,
134 int x, int y, int xlow, int xhigh, int ylow, int yhigh)
136 BOOST_ASSERT(!cursor.empty());
137 Inset & inset = cursor[0].inset();
138 BufferView & bv = cursor.bv();
140 CoordCache::InnerParPosCache const & cache =
141 bv.coordCache().getParPos().find(cursor.bottom().text())->second;
142 // Get an iterator on the first paragraph in the cache
143 DocIterator it(inset);
144 it.push_back(CursorSlice(inset));
145 it.pit() = cache.begin()->first;
146 // Get an iterator after the last paragraph in the cache
147 DocIterator et(inset);
148 et.push_back(CursorSlice(inset));
149 et.pit() = boost::prior(cache.end())->first;
150 if (et.pit() >= et.lastpit())
151 et = doc_iterator_end(inset);
155 double best_dist = std::numeric_limits<double>::max();;
156 DocIterator best_cursor = et;
158 for ( ; it != et; it.forwardPos(true)) {
159 // avoid invalid nesting when selecting
160 if (!cursor.selection() || positionable(it, cursor.anchor_)) {
161 Point p = bv_funcs::getPos(bv, it, false);
164 if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
165 double const dx = xo - x;
166 double const dy = yo - y;
167 double const d = dx * dx + dy * dy;
168 // '<=' in order to take the last possible position
169 // this is important for clicking behind \sum in e.g. '\sum_i a'
170 if (d <= best_dist) {
171 // lyxerr << "*" << endl;
179 if (best_cursor != et) {
180 cursor.setCursor(best_cursor);
188 /// moves position closest to (x, y) in given box
189 bool bruteFind3(Cursor & cur, int x, int y, bool up)
191 BufferView & bv = cur.bv();
192 int ylow = up ? 0 : y + 1;
193 int yhigh = up ? y - 1 : bv.workHeight();
195 int xhigh = bv.workWidth();
197 // FIXME: bit more work needed to get 'from' and 'to' right.
198 pit_type from = cur.bottom().pit();
199 //pit_type to = cur.bottom().pit();
200 //lyxerr << "Pit start: " << from << endl;
202 //lyxerr << "bruteFind3: x: " << x << " y: " << y
203 // << " xlow: " << xlow << " xhigh: " << xhigh
204 // << " ylow: " << ylow << " yhigh: " << yhigh
206 Inset & inset = bv.buffer()->inset();
207 DocIterator it = doc_iterator_begin(inset);
209 DocIterator et = doc_iterator_end(inset);
211 double best_dist = std::numeric_limits<double>::max();
212 DocIterator best_cursor = et;
214 for ( ; it != et; it.forwardPos()) {
215 // avoid invalid nesting when selecting
216 if (bv_funcs::status(&bv, it) == bv_funcs::CUR_INSIDE
217 && (!cur.selection() || positionable(it, cur.anchor_))) {
218 Point p = bv_funcs::getPos(bv, it, false);
221 if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
222 double const dx = xo - x;
223 double const dy = yo - y;
224 double const d = dx * dx + dy * dy;
225 //lyxerr << "itx: " << xo << " ity: " << yo << " d: " << d
226 // << " dx: " << dx << " dy: " << dy
227 // << " idx: " << it.idx() << " pos: " << it.pos()
230 // '<=' in order to take the last possible position
231 // this is important for clicking behind \sum in e.g. '\sum_i a'
232 if (d <= best_dist) {
233 //lyxerr << "*" << endl;
241 //lyxerr << "best_dist: " << best_dist << " cur:\n" << best_cursor << endl;
242 if (best_cursor == et)
244 cur.setCursor(best_cursor);
248 docstring parbreak(Paragraph const & par)
250 odocstringstream ods;
252 // only add blank line if we're not in an ERT inset
253 if (par.ownerCode() != Inset::ERT_CODE)
261 // be careful: this is called from the bv's constructor, too, so
262 // bv functions are not yet available!
263 Cursor::Cursor(BufferView & bv)
264 : DocIterator(), bv_(&bv), anchor_(), x_target_(-1),
265 selection_(false), mark_(false), logicalpos_(false)
269 void Cursor::reset(Inset & inset)
272 push_back(CursorSlice(inset));
273 anchor_ = DocIterator(inset);
280 // this (intentionally) does neither touch anchor nor selection status
281 void Cursor::setCursor(DocIterator const & cur)
283 DocIterator::operator=(cur);
287 void Cursor::dispatch(FuncRequest const & cmd0)
289 LYXERR(Debug::DEBUG) << BOOST_CURRENT_FUNCTION
290 << " cmd: " << cmd0 << '\n'
296 FuncRequest cmd = cmd0;
299 for (; depth(); pop()) {
300 LYXERR(Debug::DEBUG) << "Cursor::dispatch: cmd: "
301 << cmd0 << endl << *this << endl;
302 BOOST_ASSERT(pos() <= lastpos());
303 BOOST_ASSERT(idx() <= lastidx());
304 BOOST_ASSERT(pit() <= lastpit());
306 // The common case is 'LFUN handled, need update', so make the
307 // LFUN handler's life easier by assuming this as default value.
308 // The handler can reset the update and val flags if necessary.
309 disp_.update(Update::FitCursor | Update::Force);
310 disp_.dispatched(true);
311 inset().dispatch(*this, cmd);
312 if (disp_.dispatched())
315 // it completely to get a 'bomb early' behaviour in case this
316 // object will be used again.
317 if (!disp_.dispatched()) {
318 LYXERR(Debug::DEBUG) << "RESTORING OLD CURSOR!" << endl;
320 disp_.update(Update::None);
321 disp_.dispatched(false);
326 DispatchResult Cursor::result() const
332 BufferView & Cursor::bv() const
339 Buffer & Cursor::buffer() const
342 BOOST_ASSERT(bv_->buffer());
343 return *bv_->buffer();
349 BOOST_ASSERT(depth() >= 1);
354 void Cursor::push(Inset & p)
356 push_back(CursorSlice(p));
360 void Cursor::pushLeft(Inset & p)
362 BOOST_ASSERT(!empty());
363 //lyxerr << "Entering inset " << t << " left" << endl;
369 bool Cursor::popLeft()
371 BOOST_ASSERT(!empty());
372 //lyxerr << "Leaving inset to the left" << endl;
373 inset().notifyCursorLeaves(*this);
381 bool Cursor::popRight()
383 BOOST_ASSERT(!empty());
384 //lyxerr << "Leaving inset to the right" << endl;
385 const pos_type lp = (depth() > 1) ? (*this)[depth() - 2].lastpos() : 0;
386 inset().notifyCursorLeaves(*this);
390 pos() += lastpos() - lp + 1;
395 int Cursor::currentMode()
397 BOOST_ASSERT(!empty());
398 for (int i = depth() - 1; i >= 0; --i) {
399 int res = operator[](i).inset().currentMode();
400 if (res != Inset::UNDECIDED_MODE)
403 return Inset::TEXT_MODE;
407 void Cursor::getPos(int & x, int & y) const
409 Point p = bv_funcs::getPos(bv(), *this, boundary());
415 Row const & Cursor::textRow() const
417 ParagraphMetrics const & pm = bv().parMetrics(text(), pit());
418 BOOST_ASSERT(!pm.rows().empty());
419 return pm.getRow(pos(), boundary());
423 void Cursor::resetAnchor()
430 bool Cursor::posLeft()
439 bool Cursor::posRight()
441 if (pos() == lastpos())
448 CursorSlice Cursor::anchor() const
450 BOOST_ASSERT(anchor_.depth() >= depth());
451 CursorSlice normal = anchor_[depth() - 1];
452 if (depth() < anchor_.depth() && top() <= normal) {
453 // anchor is behind cursor -> move anchor behind the inset
460 CursorSlice Cursor::selBegin() const
464 return anchor() < top() ? anchor() : top();
468 CursorSlice Cursor::selEnd() const
472 return anchor() > top() ? anchor() : top();
476 DocIterator Cursor::selectionBegin() const
480 DocIterator di = (anchor() < top() ? anchor_ : *this);
486 DocIterator Cursor::selectionEnd() const
490 DocIterator di = (anchor() > top() ? anchor_ : *this);
491 if (di.depth() > depth()) {
499 void Cursor::setSelection()
502 // A selection with no contents is not a selection
504 #warning doesnt look ok
506 if (pit() == anchor().pit() && pos() == anchor().pos())
511 void Cursor::setSelection(DocIterator const & where, int n)
520 void Cursor::clearSelection()
528 int & Cursor::x_target()
534 int Cursor::x_target() const
540 void Cursor::clearTargetX()
547 void Cursor::info(odocstream & os) const
549 for (int i = 1, n = depth(); i < n; ++i) {
550 operator[](i).inset().infoize(os);
554 Inset const * inset = prevInset();
555 // prevInset() can return 0 in certain case.
557 prevInset()->infoize2(os);
559 // overwite old message
564 bool Cursor::selHandle(bool sel)
566 //lyxerr << "Cursor::selHandle" << endl;
567 if (sel == selection())
572 cap::saveSelection(*this);
577 std::ostream & operator<<(std::ostream & os, Cursor const & cur)
579 os << "\n cursor: | anchor:\n";
580 for (size_t i = 0, n = cur.depth(); i != n; ++i) {
581 os << " " << cur[i] << " | ";
582 if (i < cur.anchor_.depth())
583 os << cur.anchor_[i];
585 os << "-------------------------------";
588 for (size_t i = cur.depth(), n = cur.anchor_.depth(); i < n; ++i) {
589 os << "------------------------------- | " << cur.anchor_[i] << "\n";
591 os << " selection: " << cur.selection_
592 << " x_target: " << cur.x_target_ << endl;
599 ///////////////////////////////////////////////////////////////////
601 // The part below is the non-integrated rest of the original math
602 // cursor. This should be either generalized for texted or moved
603 // back to mathed (in most cases to InsetMathNest).
605 ///////////////////////////////////////////////////////////////////
607 #include "mathed/InsetMathChar.h"
608 #include "mathed/InsetMathGrid.h"
609 #include "mathed/InsetMathScript.h"
610 #include "mathed/InsetMathUnknown.h"
611 #include "mathed/MathFactory.h"
612 #include "mathed/MathStream.h"
613 #include "mathed/MathSupport.h"
618 //#define FILEDEBUG 1
621 bool Cursor::isInside(Inset const * p)
623 for (size_t i = 0; i != depth(); ++i)
624 if (&operator[](i).inset() == p)
630 void Cursor::leaveInset(Inset const & inset)
632 for (size_t i = 0; i != depth(); ++i) {
633 if (&operator[](i).inset() == &inset) {
641 bool Cursor::openable(MathAtom const & t) const
652 // we can't move into anything new during selection
653 if (depth() >= anchor_.depth())
655 if (!ptr_cmp(t.nucleus(), &anchor_[depth()].inset()))
662 void Cursor::setScreenPos(int x, int y)
665 bruteFind(*this, x, y, 0, bv().workWidth(), 0, bv().workHeight());
670 void Cursor::plainErase()
676 void Cursor::markInsert()
678 insert(char_type(0));
682 void Cursor::markErase()
688 void Cursor::plainInsert(MathAtom const & t)
690 cell().insert(pos(), t);
695 void Cursor::insert(docstring const & str)
697 for_each(str.begin(), str.end(),
698 boost::bind(static_cast<void(Cursor::*)(char_type)>
699 (&Cursor::insert), this, _1));
703 void Cursor::insert(char_type c)
705 //lyxerr << "Cursor::insert char '" << c << "'" << endl;
706 BOOST_ASSERT(!empty());
708 cap::selClearOrDel(*this);
709 insert(new InsetMathChar(c));
711 text()->insertChar(*this, c);
716 void Cursor::insert(MathAtom const & t)
718 //lyxerr << "Cursor::insert MathAtom '" << t << "'" << endl;
720 cap::selClearOrDel(*this);
725 void Cursor::insert(Inset * inset)
728 insert(MathAtom(inset));
730 text()->insertInset(*this, inset);
734 void Cursor::niceInsert(docstring const & t)
745 void Cursor::niceInsert(MathAtom const & t)
748 docstring const safe = cap::grabAndEraseSelection(*this);
750 // enter the new inset and move the contents of the selection if possible
753 // be careful here: don't use 'pushLeft(t)' as this we need to
754 // push the clone, not the original
755 pushLeft(*nextInset());
756 // We may not use niceInsert here (recursion)
764 void Cursor::insert(MathData const & ar)
768 cap::eraseSelection(*this);
769 cell().insert(pos(), ar);
774 bool Cursor::backspace()
776 autocorrect() = false;
779 cap::eraseSelection(*this);
784 // If empty cell, and not part of a big cell
785 if (lastpos() == 0 && inset().nargs() == 1) {
787 // Directly delete empty cell: [|[]] => [|]
793 // [|], can not delete from inside
805 InsetMathUnknown * p = activeMacro();
806 if (p->name().size() > 1) {
807 p->setName(p->name().substr(0, p->name().size() - 1));
812 if (pos() != 0 && prevAtom()->nargs() > 0) {
813 // let's require two backspaces for 'big stuff' and
814 // highlight on the first
828 autocorrect() = false;
833 cap::eraseSelection(*this);
837 // delete empty cells if possible
838 if (pos() == lastpos() && inset().idxDelete(idx()))
841 // special behaviour when in last position of cell
842 if (pos() == lastpos()) {
843 bool one_cell = inset().nargs() == 1;
844 if (one_cell && lastpos() == 0) {
846 // Directly delete empty cell: [|[]] => [|]
852 // [|], can not delete from inside
857 inset().idxGlue(idx());
861 // 'clever' UI hack: only erase large items if previously slected
862 if (pos() != lastpos() && nextAtom()->nargs() > 0) {
877 DocIterator save = *this;
881 autocorrect() = false;
889 DocIterator save = *this;
893 autocorrect() = false;
898 bool Cursor::macroModeClose()
902 InsetMathUnknown * p = activeMacro();
904 docstring const s = p->name();
908 // do nothing if the macro name is empty
912 // trigger updates of macros, at least, if no full
913 // updates take place anyway
914 updateFlags(Update::Force);
916 docstring const name = s.substr(1);
917 InsetMathNest * const in = inset().asInsetMath()->asNestInset();
918 if (in && in->interpretString(*this, s))
920 plainInsert(createInsetMath(name));
925 docstring Cursor::macroName()
927 return inMacroMode() ? activeMacro()->name() : docstring();
931 void Cursor::handleNest(MathAtom const & a, int c)
933 //lyxerr << "Cursor::handleNest: " << c << endl;
935 asArray(cap::grabAndEraseSelection(*this), t.nucleus()->cell(c));
938 pushLeft(*nextInset());
942 int Cursor::targetX() const
944 if (x_target() != -1)
953 void Cursor::setTargetX()
962 bool Cursor::inMacroMode() const
966 InsetMathUnknown const * p = prevAtom()->asUnknownInset();
967 return p && !p->final();
971 InsetMathUnknown * Cursor::activeMacro()
973 return inMacroMode() ? prevAtom().nucleus()->asUnknownInset() : 0;
977 void Cursor::pullArg()
982 MathData ar = cell();
983 if (popLeft() && inMathed()) {
985 cell().insert(pos(), ar);
988 //formula()->mutateToText();
999 DocIterator::const_iterator it = begin();
1000 DocIterator::const_iterator et = end();
1001 for ( ; it != et; ++it)
1007 void Cursor::normalize()
1009 if (idx() > lastidx()) {
1010 lyxerr << "this should not really happen - 1: "
1011 << idx() << ' ' << nargs()
1012 << " in: " << &inset() << endl;
1016 if (pos() > lastpos()) {
1017 lyxerr << "this should not really happen - 2: "
1018 << pos() << ' ' << lastpos() << " in idx: " << idx()
1020 odocstringstream os;
1021 WriteStream wi(os, false, true);
1022 inset().asInsetMath()->write(wi);
1023 lyxerr << to_utf8(os.str()) << endl;
1029 bool Cursor::goUpDown(bool up)
1031 // Be warned: The 'logic' implemented in this function is highly
1032 // fragile. A distance of one pixel or a '<' vs '<=' _really
1033 // matters. So fiddle around with it only if you think you know
1034 // what you are doing!
1040 // check if we had something else in mind, if not, this is the future
1042 if (x_target() == -1)
1047 // try neigbouring script insets
1051 InsetMathScript const * p = prevAtom()->asScriptInset();
1052 if (p && p->has(up)) {
1054 push(*const_cast<InsetMathScript*>(p));
1055 idx() = p->idxOfScript(up);
1062 if (pos() != lastpos()) {
1063 InsetMathScript const * p = nextAtom()->asScriptInset();
1064 if (p && p->has(up)) {
1065 push(*const_cast<InsetMathScript*>(p));
1066 idx() = p->idxOfScript(up);
1073 // FIXME: Switch this on for more robust movement
1076 return bruteFind3(*this, xo, yo, up);
1079 //xarray().boundingBox(xlow, xhigh, ylow, yhigh);
1084 //if (bruteFind(*this, xo, yo, xlow, xhigh, ylow, yhigh)) {
1085 // lyxerr << "updown: handled by brute find in the same cell" << endl;
1089 // try to find an inset that knows better then we
1091 //lyxerr << "updown: We are in " << &inset() << " idx: " << idx() << endl;
1093 if (inset().idxUpDown(*this, up)) {
1094 //lyxerr << "idxUpDown triggered" << endl;
1095 // try to find best position within this inset
1097 setCursor(bruteFind2(*this, xo, yo));
1101 // no such inset found, just take something "above"
1103 //lyxerr << "updown: popleft failed (strange case)" << endl;
1104 int ylow = up ? 0 : yo + 1;
1105 int yhigh = up ? yo - 1 : bv().workHeight();
1106 return bruteFind(*this, xo, yo, 0, bv().workWidth(), ylow, yhigh);
1109 // any improvement so far?
1110 //lyxerr << "updown: popLeft succeeded" << endl;
1114 if (up ? ynew < yo : ynew > yo)
1118 // we should not come here.
1119 BOOST_ASSERT(false);
1124 void Cursor::handleFont(string const & font)
1126 LYXERR(Debug::DEBUG) << BOOST_CURRENT_FUNCTION << ": " << font << endl;
1130 safe = cap::grabAndEraseSelection(*this);
1133 if (lastpos() != 0) {
1134 // something left in the cell
1136 // cursor in first position
1138 } else if (pos() == lastpos()) {
1139 // cursor in last position
1142 // cursor in between. split cell
1143 MathData::iterator bt = cell().begin();
1144 MathAtom at = createInsetMath(from_utf8(font));
1145 at.nucleus()->cell(0) = MathData(bt, bt + pos());
1146 cell().erase(bt, bt + pos());
1151 // nothing left in the cell
1159 void Cursor::message(docstring const & msg) const
1161 theLyXFunc().setMessage(msg);
1165 void Cursor::errorMessage(docstring const & msg) const
1167 theLyXFunc().setErrorMessage(msg);
1171 docstring Cursor::selectionAsString(bool label) const
1177 Buffer const & buffer = *bv().buffer();
1178 ParagraphList const & pars = text()->paragraphs();
1180 // should be const ...
1181 pit_type startpit = selBegin().pit();
1182 pit_type endpit = selEnd().pit();
1183 size_t const startpos = selBegin().pos();
1184 size_t const endpos = selEnd().pos();
1186 if (startpit == endpit)
1187 return pars[startpit].asString(buffer, startpos, endpos, label);
1189 // First paragraph in selection
1190 docstring result = pars[startpit].
1191 asString(buffer, startpos, pars[startpit].size(), label)
1192 + parbreak(pars[startpit]);
1194 // The paragraphs in between (if any)
1195 for (pit_type pit = startpit + 1; pit != endpit; ++pit) {
1196 Paragraph const & par = pars[pit];
1197 result += par.asString(buffer, 0, par.size(), label)
1198 + parbreak(pars[pit]);
1201 // Last paragraph in selection
1202 result += pars[endpit].asString(buffer, 0, endpos, label);
1208 return cap::grabSelection(*this);
1214 docstring Cursor::currentState()
1217 odocstringstream os;
1223 return text()->currentState(*this);
1229 docstring Cursor::getPossibleLabel()
1231 return inMathed() ? from_ascii("eq:") : text()->getPossibleLabel(*this);
1235 Encoding const * Cursor::getEncoding() const
1242 // go up until first non-0 text is hit
1243 // (innermost text is 0 in mathed)
1244 for (s = depth() - 1; s >= 0; --s)
1245 if (operator[](s).text())
1247 CursorSlice const & sl = operator[](s);
1248 Text const & text = *sl.text();
1249 Font font = text.getPar(sl.pit()).getFont(
1250 bv().buffer()->params(), sl.pos(), outerFont(sl.pit(), text.paragraphs()));
1251 return font.language()->encoding();
1255 void Cursor::undispatched()
1257 disp_.dispatched(false);
1261 void Cursor::dispatched()
1263 disp_.dispatched(true);
1267 void Cursor::updateFlags(Update::flags f)
1273 void Cursor::noUpdate()
1275 disp_.update(Update::None);
1279 Font Cursor::getFont() const
1281 // HACK. far from being perfect...
1283 // go up until first non-0 text is hit
1284 // (innermost text is 0 in mathed)
1285 for (s = depth() - 1; s >= 0; --s)
1286 if (operator[](s).text())
1288 CursorSlice const & sl = operator[](s);
1289 Text const & text = *sl.text();
1290 Font font = text.getPar(sl.pit()).getFont(
1291 bv().buffer()->params(),
1293 outerFont(sl.pit(), text.paragraphs()));
1299 void Cursor::fixIfBroken()
1301 // find out last good level
1302 Cursor copy = *this;
1303 size_t newdepth = depth();
1304 while (!copy.empty()) {
1305 if (copy.idx() > copy.lastidx()) {
1306 lyxerr << "wrong idx " << copy.idx()
1307 << ", max is " << copy.lastidx()
1308 << " at level " << copy.depth()
1309 << ". Trying to correct this." << endl;
1310 lyxerr << "old: " << *this << endl;
1311 newdepth = copy.depth() - 1;
1313 else if (copy.pit() > copy.lastpit()) {
1314 lyxerr << "wrong pit " << copy.pit()
1315 << ", max is " << copy.lastpit()
1316 << " at level " << copy.depth()
1317 << ". Trying to correct this." << endl;
1318 lyxerr << "old: " << *this << endl;
1319 newdepth = copy.depth() - 1;
1321 else if (copy.pos() > copy.lastpos()) {
1322 lyxerr << "wrong pos " << copy.pos()
1323 << ", max is " << copy.lastpos()
1324 << " at level " << copy.depth()
1325 << ". Trying to correct this." << endl;
1326 lyxerr << "old: " << *this << endl;
1327 newdepth = copy.depth() - 1;
1331 // shrink cursor to a size where everything is valid, possibly
1333 while (depth() > newdepth) {
1335 lyxerr << "correcting cursor to level " << depth() << endl;
1336 lyxerr << "new: " << *this << endl;