]> git.lyx.org Git - lyx.git/blobdiff - src/Cursor.cpp
Do not use \&@#^_~$ as lstinline delimiter, as suggested by Herbert
[lyx.git] / src / Cursor.cpp
index c49673cf4ca9a57b250d3018cc3170a955cb08c0..b0154fd3204c79f5cc7a10305607690d6681d6c5 100644 (file)
 #include "FuncRequest.h"
 #include "Language.h"
 #include "lfuns.h"
-#include "LyXFont.h"
+#include "Font.h"
 #include "LyXFunc.h" // only for setMessage()
 #include "LyXRC.h"
 #include "Row.h"
-#include "LyXText.h"
+#include "Text.h"
 #include "Paragraph.h"
 #include "paragraph_funcs.h"
 #include "ParIterator.h"
@@ -245,6 +245,17 @@ namespace {
                return true;
        }
 
+       docstring parbreak(Paragraph const & par)
+       {
+               odocstringstream ods;
+               ods << '\n';
+               // only add blank line if we're not in an ERT or Listings inset
+               if (par.ownerCode() != Inset::ERT_CODE 
+                   && par.ownerCode() != Inset::LISTINGS_CODE)
+                       ods << '\n';
+               return ods.str();
+       }
+
 } // namespace anon
 
 
@@ -1178,12 +1189,14 @@ docstring Cursor::selectionAsString(bool label) const
 
                // First paragraph in selection
                docstring result = pars[startpit].
-                       asString(buffer, startpos, pars[startpit].size(), label) + "\n\n";
+                       asString(buffer, startpos, pars[startpit].size(), label)
+                                + parbreak(pars[startpit]);
 
                // The paragraphs in between (if any)
                for (pit_type pit = startpit + 1; pit != endpit; ++pit) {
                        Paragraph const & par = pars[pit];
-                       result += par.asString(buffer, 0, par.size(), label) + "\n\n";
+                       result += par.asString(buffer, 0, par.size(), label)
+                                 + parbreak(pars[pit]);
                }
 
                // Last paragraph in selection
@@ -1233,8 +1246,8 @@ Encoding const * Cursor::getEncoding() const
                if (operator[](s).text())
                        break;
        CursorSlice const & sl = operator[](s);
-       LyXText const & text = *sl.text();
-       LyXFont font = text.getPar(sl.pit()).getFont(
+       Text const & text = *sl.text();
+       Font font = text.getPar(sl.pit()).getFont(
                bv().buffer()->params(), sl.pos(), outerFont(sl.pit(), text.paragraphs()));
        return font.language()->encoding();
 }
@@ -1264,7 +1277,7 @@ void Cursor::noUpdate()
 }
 
 
-LyXFont Cursor::getFont() const
+Font Cursor::getFont() const
 {
        // HACK. far from being perfect...
        int s = 0;
@@ -1274,8 +1287,8 @@ LyXFont Cursor::getFont() const
                if (operator[](s).text())
                        break;
        CursorSlice const & sl = operator[](s);
-       LyXText const & text = *sl.text();
-       LyXFont font = text.getPar(sl.pit()).getFont(
+       Text const & text = *sl.text();
+       Font font = text.getPar(sl.pit()).getFont(
                bv().buffer()->params(),
                sl.pos(),
                outerFont(sl.pit(), text.paragraphs()));
@@ -1286,50 +1299,10 @@ LyXFont Cursor::getFont() const
 
 void Cursor::fixIfBroken()
 {
-       // find out last good level
-       Cursor copy = *this;
-       size_t newdepth = depth();
-       while (!copy.empty()) {
-               if (copy.idx() > copy.lastidx()) {
-                       lyxerr << "wrong idx " << copy.idx()
-                              << ", max is " << copy.lastidx()
-                              << " at level " << copy.depth()
-                              << ". Trying to correct this."  << endl;
-                       lyxerr << "old: " << *this << endl;
-                       newdepth = copy.depth() - 1;
-               }
-               else if (copy.pit() > copy.lastpit()) {
-                       lyxerr << "wrong pit " << copy.pit()
-                              << ", max is " << copy.lastpit()
-                              << " at level " << copy.depth()
-                              << ". Trying to correct this."  << endl;
-                       lyxerr << "old: " << *this << endl;
-                       newdepth = copy.depth() - 1;
-               }
-               else if (copy.pos() > copy.lastpos()) {
-                       lyxerr << "wrong pos " << copy.pos()
-                              << ", max is " << copy.lastpos()
-                              << " at level " << copy.depth()
-                              << ". Trying to correct this."  << endl;
-                       lyxerr << "old: " << *this << endl;
-                       newdepth = copy.depth() - 1;
-               }
-               copy.pop();
+       if (DocIterator::fixIfBroken()) {
+                       clearSelection();
+                       resetAnchor();
        }
-       // shrink cursor to a size where everything is valid, possibly
-       // leaving insets
-       while (depth() > newdepth) {
-               pop();
-               lyxerr << "correcting cursor to level " << depth() << endl;
-               lyxerr << "new: " << *this << endl;
-               clearSelection();
-       }
-}
-
-
-bool Cursor::isRTL() const
-{
-       return top().paragraph().isRightToLeftPar(bv().buffer()->params());
 }