]> git.lyx.org Git - lyx.git/blobdiff - src/Cursor.cpp
Get rid of Paragraph::ownerCode().
[lyx.git] / src / Cursor.cpp
index 572e062876d461d8680adb218b857e59c51eddc2..2fcca3b556d50650e6b2156c82f35c6b04ff7736 100644 (file)
@@ -246,16 +246,6 @@ bool bruteFind3(Cursor & cur, int x, int y, bool up)
        return true;
 }
 
-docstring parbreak(Paragraph const & par)
-{
-       odocstringstream os;
-       os << '\n';
-       // only add blank line if we're not in an ERT or Listings inset
-       if (par.ownerCode() != ERT_CODE && par.ownerCode() != LISTINGS_CODE)
-               os << '\n';
-       return os.str();
-}
-
 } // namespace anon
 
 
@@ -405,7 +395,10 @@ int Cursor::currentMode()
        LASSERT(!empty(), /**/);
        for (int i = depth() - 1; i >= 0; --i) {
                int res = operator[](i).inset().currentMode();
-               if (res != Inset::UNDECIDED_MODE)
+               bool locked_mode = operator[](i).inset().lockedMode();
+               // Also return UNDECIDED_MODE when the mode is locked,
+               // as in this case it is treated the same as TEXT_MODE
+               if (res != Inset::UNDECIDED_MODE || locked_mode)
                        return res;
        }
        return Inset::TEXT_MODE;
@@ -923,6 +916,8 @@ void Cursor::posVisToRowExtremity(bool left)
 
 CursorSlice Cursor::anchor() const
 {
+       if (!selection())
+               return top();
        LASSERT(anchor_.depth() >= depth(), /**/);
        CursorSlice normal = anchor_[depth() - 1];
        if (depth() < anchor_.depth() && top() <= normal) {
@@ -1585,7 +1580,7 @@ void Cursor::normalize()
                        << pos() << ' ' << lastpos() <<  " in idx: " << idx()
                       << " in atom: '";
                odocstringstream os;
-               WriteStream wi(os, false, true, false);
+               WriteStream wi(os, false, true, WriteStream::wsDefault);
                inset().asInsetMath()->write(wi);
                lyxerr << to_utf8(os.str()) << endl;
                pos() = lastpos();
@@ -1920,6 +1915,17 @@ void Cursor::errorMessage(docstring const & msg) const
 }
 
 
+static docstring parbreak(InsetCode code)
+{
+       odocstringstream os;
+       os << '\n';
+       // only add blank line if we're not in an ERT or Listings inset
+       if (code != ERT_CODE && code != LISTINGS_CODE)
+               os << '\n';
+       return os.str();
+}
+
+
 docstring Cursor::selectionAsString(bool with_label) const
 {
        if (!selection())
@@ -1951,13 +1957,13 @@ docstring Cursor::selectionAsString(bool with_label) const
                // First paragraph in selection
                docstring result = pars[startpit].
                        asString(startpos, pars[startpit].size(), label)
-                                + parbreak(pars[startpit]);
+                                + parbreak(inset().lyxCode());
 
                // The paragraphs in between (if any)
                for (pit_type pit = startpit + 1; pit != endpit; ++pit) {
                        Paragraph const & par = pars[pit];
                        result += par.asString(0, par.size(), label)
-                                 + parbreak(pars[pit]);
+                                 + parbreak(inset().lyxCode());
                }
 
                // Last paragraph in selection