]> git.lyx.org Git - features.git/commitdiff
Avoid crash with cursor down in math
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 20 Sep 2018 20:15:12 +0000 (22:15 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 20 Sep 2018 20:18:36 +0000 (22:18 +0200)
This can happen when the inset that contains the cursor is outside of
the screen.

THis is only a workaround. The real solution would be a
processUpdateFlags(FitCursor) call, but the code is not ready for that
yet.

Fixes bug #11296.

src/mathed/InsetMathGrid.cpp

index cb6f440539ba6083f394d4129fedd756175066f8..58784ad79b5672d641b11cf662a537da1e0627de 100644 (file)
@@ -22,6 +22,7 @@
 #include "Buffer.h"
 #include "BufferParams.h"
 #include "BufferView.h"
+#include "CoordCache.h"
 #include "Cursor.h"
 #include "CutAndPaste.h"
 #include "FuncRequest.h"
@@ -969,7 +970,14 @@ bool InsetMathGrid::idxUpDown(Cursor & cur, bool up) const
                LASSERT(cur.idx() > 0, return false);
                --cur.idx();
        }
-       cur.pos() = cur.cell().x2pos(&cur.bv(), cur.x_target() - cur.cell().xo(cur.bv()));
+       // FIXME: this is only a workaround to avoid a crash if the inset
+       // in not in coord cache. The best would be to force a FitCursor
+       // operation.
+       CoordCache::Arrays const & arraysCache = cur.bv().coordCache().arrays();
+       if (arraysCache.has(&cur.cell()))
+               cur.pos() = cur.cell().x2pos(&cur.bv(), cur.x_target() - cur.cell().xo(cur.bv()));
+       else
+               cur.pos() = 0;
        return true;
 }