]> git.lyx.org Git - lyx.git/blobdiff - src/Text.cpp
reorder.
[lyx.git] / src / Text.cpp
index 144c070ef8d58251f740669b568b06d46a340503..c758008d530ab073d38a1da0d4e3b3beb6296141 100644 (file)
@@ -37,6 +37,7 @@
 #include "Language.h"
 #include "Length.h"
 #include "Lexer.h"
+#include "lyxfind.h"
 #include "LyXRC.h"
 #include "Paragraph.h"
 #include "paragraph_funcs.h"
@@ -59,7 +60,6 @@
 #include "insets/InsetSpecialChar.h"
 #include "insets/InsetTabular.h"
 
-#include "support/convert.h"
 #include "support/debug.h"
 #include "support/docstream.h"
 #include "support/gettext.h"
@@ -187,6 +187,15 @@ void readParToken(Buffer const & buf, Paragraph & par, Lexer & lex,
                else
                        lex.printError("Unknown bar font flag "
                                       "`$$Token'");
+       } else if (token == "\\strikeout") {
+               lex.next();
+               font.fontInfo().setStrikeout(font.setLyXMisc(lex.getString()));
+       } else if (token == "\\uuline") {
+               lex.next();
+               font.fontInfo().setUuline(font.setLyXMisc(lex.getString()));
+       } else if (token == "\\uwave") {
+               lex.next();
+               font.fontInfo().setUwave(font.setLyXMisc(lex.getString()));
        } else if (token == "\\noun") {
                lex.next();
                font.fontInfo().setNoun(font.setLyXMisc(lex.getString()));
@@ -569,7 +578,7 @@ void Text::charInserted(Cursor & cur)
            && !par.isLetter(cur.pos() - 1)) {
                // get the word in front of cursor
                LASSERT(this == cur.text(), /**/);
-               cur.paragraph().updateWords(cur.top());
+               cur.paragraph().updateWords();
        }
 }
 
@@ -757,6 +766,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)
@@ -773,8 +801,11 @@ void Text::acceptOrRejectChanges(Cursor & cur, ChangeOp op)
 {
        LASSERT(this == cur.text(), /**/);
 
-       if (!cur.selection())
-               return;
+       if (!cur.selection()) {
+               Change const & change = cur.paragraph().lookupChange(cur.pos());
+               if (!(change.changed() && findNextChange(&cur.bv())))
+                       return;
+       }
 
        cur.recordUndoSelection();
 
@@ -1227,39 +1258,8 @@ bool Text::dissolveInset(Cursor & cur)
 void Text::getWord(CursorSlice & from, CursorSlice & to,
        word_location const loc) const
 {
-       Paragraph const & from_par = pars_[from.pit()];
-       switch (loc) {
-       case WHOLE_WORD_STRICT:
-               if (from.pos() == 0 || from.pos() == from_par.size()
-                   || !from_par.isLetter(from.pos())
-                   || !from_par.isLetter(from.pos() - 1)) {
-                       to = from;
-                       return;
-               }
-               // no break here, we go to the next
-
-       case WHOLE_WORD:
-               // If we are already at the beginning of a word, do nothing
-               if (!from.pos() || !from_par.isLetter(from.pos() - 1))
-                       break;
-               // no break here, we go to the next
-
-       case PREVIOUS_WORD:
-               // always move the cursor to the beginning of previous word
-               while (from.pos() && from_par.isLetter(from.pos() - 1))
-                       --from.pos();
-               break;
-       case NEXT_WORD:
-               LYXERR0("Text::getWord: NEXT_WORD not implemented yet");
-               break;
-       case PARTIAL_WORD:
-               // no need to move the 'from' cursor
-               break;
-       }
        to = from;
-       Paragraph const & to_par = pars_[to.pit()];
-       while (to.pos() < to_par.size() && to_par.isLetter(to.pos()))
-               ++to.pos();
+       pars_[to.pit()].locateWord(from.pos(), to.pos(), loc);
 }
 
 
@@ -1281,6 +1281,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();
@@ -1299,16 +1300,8 @@ bool Text::read(Buffer const & buf, Lexer & lex,
                        continue;
 
                if (token == "\\end_document") {
-                       // 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));
-                               pars_.push_back(par);
-                       }
-                       return false;
+                       res = false;
+                       break;
                }
 
                if (token == "\\begin_layout") {
@@ -1327,7 +1320,7 @@ bool Text::read(Buffer const & buf, Lexer & lex,
                        // register the words in the global word list
                        CursorSlice sl = CursorSlice(*insetPtr);
                        sl.pit() = pars_.size() - 1;
-                       pars_.back().updateWords(sl);
+                       pars_.back().updateWords();
                } else if (token == "\\begin_deeper") {
                        ++depth;
                } else if (token == "\\end_deeper") {
@@ -1339,7 +1332,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.