]> git.lyx.org Git - lyx.git/blobdiff - src/cursor.C
convert author names and status messages to docstring
[lyx.git] / src / cursor.C
index 42a0c7cf1bfcc318e985ed8121705f6202d45f5e..5bccc4d13b2a146428f7c7fc8a5b7504dd58045d 100644 (file)
@@ -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 <sstream>
 #include <limits>
+#include <map>
 
 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<InsetBase const *, Point> const & data =
+                               c.bv().coordCache().getInsets().getData();
+                       std::map<InsetBase const *, Point>::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_;
@@ -390,6 +403,20 @@ void LCursor::getPos(int & x, int & y) const
 }
 
 
+Row & LCursor::textRow()
+{
+       BOOST_ASSERT(!paragraph().rows().empty());
+       return paragraph().getRow(pos(), boundary());
+}
+
+
+Row const & LCursor::textRow() const
+{
+       BOOST_ASSERT(!paragraph().rows().empty());
+       return paragraph().getRow(pos(), boundary());
+}
+
+
 void LCursor::resetAnchor()
 {
        anchor_ = *this;
@@ -747,10 +774,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 +832,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;
        }
@@ -1157,18 +1203,18 @@ docstring LCursor::selectionAsString(bool label) const
 }
 
 
-string LCursor::currentState()
+docstring LCursor::currentState()
 {
        if (inMathed()) {
                odocstringstream os;
                info(os);
-               return to_utf8(os.str());
+               return os.str();
        }
 
        if (inTexted())
                return text()->currentState(*this);
 
-       return string();
+       return docstring();
 }