]> git.lyx.org Git - lyx.git/blobdiff - src/Cursor.cpp
Fix a copy-paste error introduced in b754fb02
[lyx.git] / src / Cursor.cpp
index f2a61c28cc1c90df04a71ed647af348e0cd115fe..be042940a081b3806ca129c6f0d657f8f081b99e 100644 (file)
@@ -95,20 +95,18 @@ DocIterator bruteFind2(Cursor const & c, int x, int y)
                int xo;
                int yo;
                Inset const * inset = &it.inset();
-               map<Inset const *, Geometry> const & data =
-                       c.bv().coordCache().getInsets().getData();
-               map<Inset const *, Geometry>::const_iterator I = data.find(inset);
+               CoordCache const & cache = c.bv().coordCache();
 
                // FIXME: in the case where the inset is not in the cache, this
                // means that no part of it is visible on screen. In this case
                // we don't do elaborate search and we just return the forwarded
                // DocIterator at its beginning.
-               if (I == data.end()) {
+               if (!cache.getInsets().has(inset)) {
                        it.top().pos() = 0;
                        return it;
                }
 
-               Point o = I->second.pos;
+               Point const o = cache.getInsets().xy(inset);
                inset->cursorPos(c.bv(), it.top(), c.boundary(), xo, yo);
                // Convert to absolute
                xo += o.x_;
@@ -336,7 +334,7 @@ void Cursor::dispatch(FuncRequest const & cmd0)
        Cursor old = *this;
        disp_ = DispatchResult();
 
-       buffer()->undo().beginUndoGroup();
+       beginUndoGroup();
 
        // Is this a function that acts on inset at point?
        if (lyxaction.funcHasFlag(cmd.action(), LyXAction::AtPoint)
@@ -348,7 +346,7 @@ void Cursor::dispatch(FuncRequest const & cmd0)
                        << cmd0 << endl << *this);
                nextInset()->dispatch(*this, tmpcmd);
                if (disp_.dispatched()) {
-                       buffer()->undo().endUndoGroup();
+                       endUndoGroup();
                        return;
                }
        }
@@ -393,7 +391,7 @@ void Cursor::dispatch(FuncRequest const & cmd0)
                // are possible which would change it
                beforeDispatchCursor_ = safe.beforeDispatchCursor_;
        }
-       buffer()->undo().endUndoGroup();
+       endUndoGroup();
 
        // notify insets we just left
        if (*this != old) {
@@ -402,7 +400,7 @@ void Cursor::dispatch(FuncRequest const & cmd0)
                bool badcursor = notifyCursorLeavesOrEnters(old, *this);
                if (badcursor) {
                        fixIfBroken();
-                       bv().fixInlineCompletionPos();
+                       bv().resetInlineCompletionPos();
                }
                old.endUndoGroup();
        }
@@ -503,6 +501,7 @@ Row const & Cursor::textRow() const
 void Cursor::resetAnchor()
 {
        anchor_ = *this;
+       checkNewWordPosition();
 }
 
 
@@ -519,6 +518,67 @@ void Cursor::setCursorToAnchor()
 }
 
 
+void Cursor::markNewWordPosition()
+{
+       if (lyxrc.spellcheck_continuously && inTexted() && new_word_.empty()) {
+               FontSpan nw = locateWord(WHOLE_WORD);
+               if (nw.size() == 1) {
+                       LYXERR(Debug::DEBUG, "start new word: "
+                               << " par: " << pit()
+                               << " pos: " << nw.first);
+                       new_word_ = *this;
+               }
+       }
+}
+
+
+void Cursor::clearNewWordPosition()
+{
+       if (!new_word_.empty()) {
+               LYXERR(Debug::DEBUG, "clear new word: "
+                       << " par: " << pit()
+                       << " pos: " << pos());
+               new_word_.resize(0);
+       }
+}
+
+
+void Cursor::checkNewWordPosition()
+{
+       if (!lyxrc.spellcheck_continuously || new_word_.empty())
+               return ;
+       if (!inTexted())
+               clearNewWordPosition();
+       else {
+               // forget the position of the current new word if
+               // 1) the paragraph changes or
+               // 2) the count of nested insets changes or
+               // 3) the cursor pos is out of paragraph bound
+               if (pit() != new_word_.pit() ||
+                       depth() != new_word_.depth() ||
+                       new_word_.pos() > new_word_.lastpos()) {
+                       clearNewWordPosition();
+               } else if (new_word_.fixIfBroken())
+                       // 4) or the remembered position was "broken"
+                       clearNewWordPosition();
+               else {
+                       FontSpan nw = locateWord(WHOLE_WORD);
+                       if (nw.size()) {
+                               FontSpan ow = new_word_.locateWord(WHOLE_WORD);
+                               if (nw.intersect(ow).empty())
+                                       clearNewWordPosition();
+                               else
+                                       LYXERR(Debug::DEBUG, "new word: "
+                                                  << " par: " << pit()
+                                                  << " pos: " << nw.first << ".." << nw.last);
+                       } else {
+                               clearNewWordPosition();
+                       }
+               }
+       }
+}
+
+
 bool Cursor::posBackward()
 {
        if (pos() == 0)
@@ -1337,7 +1397,7 @@ void Cursor::insert(Inset * inset0)
 }
 
 
-void Cursor::niceInsert(docstring const & t, Parse::flags f, bool enter)
+int Cursor::niceInsert(docstring const & t, Parse::flags f, bool enter)
 {
        MathData ar(buffer());
        asArray(t, ar, f);
@@ -1345,6 +1405,7 @@ void Cursor::niceInsert(docstring const & t, Parse::flags f, bool enter)
                niceInsert(ar[0]);
        else
                insert(ar);
+       return ar.size();
 }
 
 
@@ -1538,8 +1599,11 @@ bool Cursor::macroModeClose()
 
        docstring const name = s.substr(1);
        InsetMathNest * const in = inset().asInsetMath()->asNestInset();
-       if (in && in->interpretString(*this, s))
+       if (in && in->interpretString(*this, s)) {
+               // end undo group that was opened before in was created
+               endUndoGroup();
                return true;
+       }
        MathAtom atom = buffer()->getMacro(name, *this, false) ?
                MathAtom(new MathMacro(buffer(), name)) : createInsetMath(name, buffer());
 
@@ -1572,7 +1636,9 @@ bool Cursor::macroModeClose()
                else
                        insert(selection);
        }
-       
+
+       // end undo group that was opened before in was created
+       endUndoGroup();
        return true;
 }
 
@@ -1624,7 +1690,7 @@ bool Cursor::inMacroMode() const
 {
        if (!inMathed())
                return false;
-       if (pos() == 0)
+       if (pos() == 0 || cell().empty())
                return false;
        InsetMathUnknown const * p = prevAtom()->asUnknownInset();
        return p && !p->final();
@@ -1907,8 +1973,12 @@ 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;
        }
@@ -1933,7 +2003,8 @@ 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) 
+                       // Make sure that cur gets back whatever happened to dummy (Lgb)
+                       // This will include any screen update requested by DEPM
                        operator=(dummy);
                }
        } else {
@@ -2214,6 +2285,7 @@ bool Cursor::fixIfBroken()
        bool const broken_anchor = anchor_.fixIfBroken();
        
        if (broken_cursor || broken_anchor) {
+               clearNewWordPosition();
                clearSelection();
                return true;
        }
@@ -2346,7 +2418,7 @@ void Cursor::beginUndoGroup() const
 
 void Cursor::endUndoGroup() const
 {
-       buffer()->undo().endUndoGroup();
+       buffer()->undo().endUndoGroup(*this);
 }