X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fcursor.C;h=4d95d0de0b632c4c3d09b0f0b0c3f2741f21616d;hb=e5b8f6956160631022fede155f55bad7951eecb8;hp=e63050cf7db7fcf06d04a33111c200e32cb158c3;hpb=37e164c6f9e792e51ceac0ad58885ee5b3758330;p=lyx.git diff --git a/src/cursor.C b/src/cursor.C index e63050cf7d..4d95d0de0b 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -39,7 +39,6 @@ #include "mathed/InsetMath.h" #include "mathed/InsetMathScript.h" #include "mathed/MathMacroTable.h" -#include "mathed/MathParser.h" #include "support/limited_stack.h" @@ -49,6 +48,7 @@ #include #include +#include namespace lyx { @@ -96,7 +96,20 @@ namespace { int xo; int yo; InsetBase const * inset = &it.inset(); - Point o = c.bv().coordCache().getInsets().xy(inset); + std::map const & data = + c.bv().coordCache().getInsets().getData(); + std::map::const_iterator I = data.find(inset); + + // 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()) { + it.top().pos() = 0; + return it; + } + + Point o = I->second; inset->cursorPos(c.bv(), it.top(), c.boundary(), xo, yo); // Convert to absolute xo += o.x_; @@ -747,10 +760,22 @@ bool LCursor::backspace() } if (pos() == 0) { - if (inset().nargs() == 1 && depth() == 1 && lastpos() == 0) + // If empty cell, and not part of a big cell + if (lastpos() == 0 && inset().nargs() == 1) { + popLeft(); + // Directly delete empty cell: [|[]] => [|] + if (inMathed()) { + plainErase(); + resetAnchor(); + return true; + } + // [|], can not delete from inside return false; - pullArg(); - return true; + } else { + // move to left + popLeft(); + return true; + } } if (inMacroMode()) { @@ -793,12 +818,19 @@ bool LCursor::erase() // special behaviour when in last position of cell if (pos() == lastpos()) { bool one_cell = inset().nargs() == 1; - if (one_cell && depth() == 1 && lastpos() == 0) + if (one_cell && lastpos() == 0) { + popLeft(); + // Directly delete empty cell: [|[]] => [|] + if (inMathed()) { + plainErase(); + resetAnchor(); + return true; + } + // [|], can not delete from inside return false; + } // remove markup - if (one_cell) - pullArg(); - else + if (!one_cell) inset().idxGlue(idx()); return true; } @@ -900,9 +932,6 @@ int LCursor::targetX() const void LCursor::setTargetX() { - // For now this is good enough. A better solution would be to - // avoid this rebreak by setting cursorX only after drawing - bottom().text()->redoParagraph(bottom().pit()); int x; int y; getPos(x, y); @@ -1175,9 +1204,9 @@ string LCursor::currentState() } -string LCursor::getPossibleLabel() +docstring LCursor::getPossibleLabel() { - return inMathed() ? "eq:" : text()->getPossibleLabel(*this); + return inMathed() ? from_ascii("eq:") : text()->getPossibleLabel(*this); }