]> git.lyx.org Git - lyx.git/blobdiff - src/Cursor.cpp
installer: further preparation
[lyx.git] / src / Cursor.cpp
index 8afbdf3cb45942aa580b6bf5c9a356c567b7077d..3ad16f49ffae594d6add6982b5457586fccf2198 100644 (file)
 #include "TextMetrics.h"
 #include "TocBackend.h"
 
-#include "support/lassert.h"
 #include "support/debug.h"
 #include "support/docstream.h"
+#include "support/ExceptionMessage.h"
+#include "support/gettext.h"
+#include "support/lassert.h"
 
 #include "insets/InsetTabular.h"
 #include "insets/InsetText.h"
@@ -185,7 +187,7 @@ bool bruteFind(Cursor & cursor,
 }
 */
 
-
+/*
 /// moves position closest to (x, y) in given box
 bool bruteFind3(Cursor & cur, int x, int y, bool up)
 {
@@ -247,7 +249,7 @@ bool bruteFind3(Cursor & cur, int x, int y, bool up)
        cur.setCursor(best_cursor);
        return true;
 }
-
+*/
 } // namespace anon
 
 
@@ -286,6 +288,8 @@ void Cursor::reset()
        push_back(CursorSlice(buffer()->inset()));
        anchor_ = doc_iterator_begin(buffer());
        anchor_.clear();
+       new_word_ = doc_iterator_begin(buffer());
+       new_word_.clear();
        clearTargetX();
        selection_ = false;
        mark_ = false;
@@ -338,6 +342,7 @@ bool Cursor::getStatus(FuncRequest const & cmd, FuncStatus & status) const
        bool res = false;
        for ( ; cur.depth(); cur.pop()) {
                //lyxerr << "\nCursor::getStatus: cmd: " << cmd << endl << *this << endl;
+               // LASSERT: Is it safe to continue here, or should we return?
                LASSERT(cur.idx() <= cur.lastidx(), /**/);
                LASSERT(cur.pit() <= cur.lastpit(), /**/);
                LASSERT(cur.pos() <= cur.lastpos(), /**/);
@@ -395,6 +400,7 @@ void Cursor::dispatch(FuncRequest const & cmd0)
        for (; depth(); pop(), boundary(false)) {
                LYXERR(Debug::DEBUG, "Cursor::dispatch: cmd: "
                        << cmd0 << endl << *this);
+               // LASSERT: Is it safe to continue here, or should we return?
                LASSERT(pos() <= lastpos(), /**/);
                LASSERT(idx() <= lastidx(), /**/);
                LASSERT(pit() <= lastpit(), /**/);
@@ -454,14 +460,14 @@ DispatchResult const & Cursor::result() const
 
 BufferView & Cursor::bv() const
 {
-       LASSERT(bv_, /**/);
+       LBUFERR(bv_);
        return *bv_;
 }
 
 
 void Cursor::pop()
 {
-       LASSERT(depth() >= 1, /**/);
+       LBUFERR(depth() >= 1);
        pop_back();
 }
 
@@ -507,7 +513,7 @@ bool Cursor::popForward()
 
 int Cursor::currentMode()
 {
-       LASSERT(!empty(), /**/);
+       LASSERT(!empty(), return Inset::UNDECIDED_MODE);
        for (int i = depth() - 1; i >= 0; --i) {
                int res = operator[](i).inset().currentMode();
                bool locked_mode = operator[](i).inset().lockedMode();
@@ -532,7 +538,6 @@ Row const & Cursor::textRow() const
 {
        CursorSlice const & cs = innerTextSlice();
        ParagraphMetrics const & pm = bv().parMetrics(cs.text(), cs.pit());
-       LASSERT(!pm.rows().empty(), /**/);
        return pm.getRow(pos(), boundary());
 }
 
@@ -1134,7 +1139,12 @@ CursorSlice Cursor::normalAnchor() const
 {
        if (!selection())
                return top();
-       LASSERT(anchor_.depth() >= depth(), /**/);
+       // LASSERT: There have been several bugs around this code, that seem
+       // to involve failures to reset the anchor. We can at least not crash
+       // in release mode by resetting it ourselves.
+       LASSERT(anchor_.depth() >= depth(), 
+               const_cast<DocIterator &>(anchor_) = *this);
+
        CursorSlice normal = anchor_[depth() - 1];
        if (depth() < anchor_.depth() && top() <= normal) {
                // anchor is behind cursor -> move anchor behind the inset
@@ -1435,7 +1445,7 @@ void Cursor::insert(docstring const & str)
 void Cursor::insert(char_type c)
 {
        //lyxerr << "Cursor::insert char '" << c << "'" << endl;
-       LASSERT(!empty(), /**/);
+       LASSERT(!empty(), return);
        if (inMathed()) {
                cap::selClearOrDel(*this);
                insert(new InsetMathChar(c));
@@ -1456,7 +1466,7 @@ void Cursor::insert(MathAtom const & t)
 
 void Cursor::insert(Inset * inset0)
 {
-       LASSERT(inset0, /**/);
+       LASSERT(inset0, return);
        if (inMathed())
                insert(MathAtom(inset0->asInsetMath()));
        else {
@@ -1523,8 +1533,6 @@ void Cursor::insert(MathData const & ar)
 
 bool Cursor::backspace()
 {
-       autocorrect() = false;
-
        if (selection()) {
                cap::eraseSelection(*this);
                return true;
@@ -1575,7 +1583,6 @@ bool Cursor::backspace()
 
 bool Cursor::erase()
 {
-       autocorrect() = false;
        if (inMacroMode())
                return true;
 
@@ -1630,7 +1637,6 @@ bool Cursor::up()
        if (disp_.dispatched())
                return true;
        setCursor(save);
-       autocorrect() = false;
        return false;
 }
 
@@ -1644,7 +1650,6 @@ bool Cursor::down()
        if (disp_.dispatched())
                return true;
        setCursor(save);
-       autocorrect() = false;
        return false;
 }
 
@@ -1965,7 +1970,7 @@ bool Cursor::atFirstOrLastRow(bool up)
 
 bool Cursor::upDownInText(bool up, bool & updateNeeded)
 {
-       LASSERT(text(), /**/);
+       LASSERT(text(), return false);
 
        // where are we?
        int xo = 0;
@@ -2043,12 +2048,8 @@ bool Cursor::upDownInText(bool up, bool & updateNeeded)
 
                        updateNeeded |= bv().checkDepm(dummy, *this);
                        updateTextTargetOffset();
-                       if (updateNeeded) {
+                       if (updateNeeded)
                                forceBufferUpdate();
-                               // DEPM may have requested a screen update
-                               this->screenUpdateFlags(
-                                       this->screenUpdate() | dummy.screenUpdate());
-                       }
                }
                return false;
        }
@@ -2073,8 +2074,7 @@ bool Cursor::upDownInText(bool up, bool & updateNeeded)
                        ++dummy.pos();
                if (bv().checkDepm(dummy, old)) {
                        updateNeeded = true;
-                       // Make sure that cur gets back whatever happened to dummy (Lgb)
-                       // This will include any screen update requested by DEPM
+                       // Make sure that cur gets back whatever happened to dummy (Lgb) 
                        operator=(dummy);
                }
        } else {