]> git.lyx.org Git - lyx.git/blobdiff - src/Cursor.cpp
Two places where coverity urges us to limit string length
[lyx.git] / src / Cursor.cpp
index e694a13dddac879d35e442f6c31e2a652794b1b2..3fd2578f272707f21a6e1e3386c21ec75ceabfe6 100644 (file)
@@ -1906,10 +1906,13 @@ bool Cursor::upDownInText(bool up, bool & updateNeeded)
                int yo = bv().getPos(*this).y_;
                Cursor old = *this;
                // To next/previous row
+               // FIXME: the y position is often guessed wrongly across styles and
+               // insets, which leads to weird behaviour.
                if (up)
                        tm.editXY(*this, xo, yo - textRow().ascent() - 1);
                else
                        tm.editXY(*this, xo, yo + textRow().descent() + 1);
+               x_target_ = old.x_target_;
                clearSelection();
 
                // This happens when you move out of an inset.
@@ -2425,8 +2428,8 @@ bool Cursor::confirmDeletion(bool const before) const
                        return inset->confirmDeletion();
        } else {
                DocIterator dit = selectionBegin();
-               DocIterator const sel_end = selectionEnd();
-               for (; dit < sel_end; dit.posForward())
+               CursorSlice const end = selectionEnd().top();
+               for (; dit.top() < end; dit.top().forwardPos())
                        if (Inset const * inset = dit.nextInset())
                                if (inset->confirmDeletion())
                                        return true;
@@ -2443,6 +2446,8 @@ void Cursor::moveToClosestEdge(int const x, bool const edit)
                if (edit && (inset->hasSettings() || !inset->contextMenuName().empty()))
                        return;
                CoordCache::Insets const & insetCache = bv().coordCache().getInsets();
+               if (!insetCache.has(inset))
+                       return;
                int const wid = insetCache.dim(inset).wid;
                Point p = insetCache.xy(inset);
                if (x > p.x_ + (wid + 1) / 2)