]> git.lyx.org Git - lyx.git/blobdiff - src/Text.cpp
1.) some white spaces removed
[lyx.git] / src / Text.cpp
index cf4e584eac913e2913be99e015b53802a744e208..91b8a5f02a456ad58c5df78fd1736cfc0c0e8030 100644 (file)
 #include "insets/InsetSpecialChar.h"
 #include "insets/InsetTabular.h"
 
-#include "support/lassert.h"
 #include "support/convert.h"
 #include "support/debug.h"
 #include "support/docstream.h"
 #include "support/gettext.h"
+#include "support/lassert.h"
 #include "support/lstrings.h"
 #include "support/textutils.h"
 
@@ -757,6 +757,25 @@ void Text::selectWord(Cursor & cur, word_location loc)
 }
 
 
+void Text::selectAll(Cursor & cur)
+{
+       LASSERT(this == cur.text(), /**/);
+       if (cur.lastpos() == 0 && cur.lastpit() == 0)
+               return;
+       // If the cursor is at the beginning, make sure the cursor ends there
+       if (cur.pit() == 0 && cur.pos() == 0) {
+               setCursor(cur, cur.lastpit(), getPar(cur.lastpit()).size());
+               cur.resetAnchor();
+               setCursor(cur, 0, 0);           
+       } else {
+               setCursor(cur, 0, 0);
+               cur.resetAnchor();
+               setCursor(cur, cur.lastpit(), getPar(cur.lastpit()).size());
+       }
+       cur.setSelection();
+}
+
+
 // Select the word currently under the cursor when no
 // selection is currently set
 bool Text::selectWordWhenUnderCursor(Cursor & cur, word_location loc)
@@ -1281,6 +1300,7 @@ bool Text::read(Buffer const & buf, Lexer & lex,
                ErrorList & errorList, InsetText * insetPtr)
 {
        depth_type depth = 0;
+       bool res = true;
 
        while (lex.isOK()) {
                lex.nextToken();
@@ -1298,8 +1318,10 @@ bool Text::read(Buffer const & buf, Lexer & lex,
                if (token == "\\begin_body")
                        continue;
 
-               if (token == "\\end_document")
-                       return false;
+               if (token == "\\end_document") {
+                       res = false;
+                       break;
+               }
 
                if (token == "\\begin_layout") {
                        lex.pushToken(token);
@@ -1329,7 +1351,19 @@ bool Text::read(Buffer const & buf, Lexer & lex,
                        LYXERR0("Handling unknown body token: `" << token << '\'');
                }
        }
-       return true;
+
+       // avoid a crash on weird documents (bug 4859)
+       if (pars_.empty()) {
+               Paragraph par;
+               par.setInsetOwner(insetPtr);
+               par.params().depth(depth);
+               par.setFont(0, Font(inherit_font, 
+                                   buf.params().language));
+               par.setPlainOrDefaultLayout(buf.params().documentClass());
+               pars_.push_back(par);
+       }
+       
+       return res;
 }
 
 // Returns the current font and depth as a message.