]> git.lyx.org Git - lyx.git/blobdiff - src/Text.cpp
Get rid of Paragraph::ownerCode().
[lyx.git] / src / Text.cpp
index 7f1861efb2e35649797c38ae95c6f568a4a4f116..73c16f1d775388a8d0b55b05eb13b5e808201d74 100644 (file)
@@ -60,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"
@@ -188,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()));
@@ -210,32 +218,24 @@ void readParToken(Buffer const & buf, Paragraph & par, Lexer & lex,
                par.insertInset(par.size(), new InsetLine, font, change);
        } else if (token == "\\change_unchanged") {
                change = Change(Change::UNCHANGED);
-       } else if (token == "\\change_inserted") {
+       } else if (token == "\\change_inserted" || token == "\\change_deleted") {
                lex.eatLine();
                istringstream is(lex.getString());
                unsigned int aid;
                time_t ct;
                is >> aid >> ct;
-               if (aid >= bp.author_map.size()) {
+               map<unsigned int, int> const & am = bp.author_map;
+               if (am.find(aid) == am.end()) {
                        errorList.push_back(ErrorItem(_("Change tracking error"),
-                                           bformat(_("Unknown author index for insertion: %1$d\n"), aid),
+                                           bformat(_("Unknown author index for change: %1$d\n"), aid),
                                            par.id(), 0, par.size()));
                        change = Change(Change::UNCHANGED);
-               } else
-                       change = Change(Change::INSERTED, bp.author_map[aid], ct);
-       } else if (token == "\\change_deleted") {
-               lex.eatLine();
-               istringstream is(lex.getString());
-               unsigned int aid;
-               time_t ct;
-               is >> aid >> ct;
-               if (aid >= bp.author_map.size()) {
-                       errorList.push_back(ErrorItem(_("Change tracking error"),
-                                           bformat(_("Unknown author index for deletion: %1$d\n"), aid),
-                                           par.id(), 0, par.size()));
-                       change = Change(Change::UNCHANGED);
-               } else
-                       change = Change(Change::DELETED, bp.author_map[aid], ct);
+               } else {
+                       if (token == "\\change_inserted")
+                               change = Change(Change::INSERTED, am.find(aid)->second, ct);
+                       else
+                               change = Change(Change::DELETED, am.find(aid)->second, ct);
+               }
        } else {
                lex.eatLine();
                errorList.push_back(ErrorItem(_("Unknown token"),
@@ -545,7 +545,8 @@ void Text::insertChar(Cursor & cur, char_type c)
        cur.checkBufferStructure();
 
 //             cur.updateFlags(Update::Force);
-       setCursor(cur.top(), cur.pit(), cur.pos() + 1);
+       bool boundary = tm.isRTLBoundary(cur.pit(), cur.pos() + 1);
+       setCursor(cur, cur.pit(), cur.pos() + 1, false, boundary);
        charInserted(cur);
 }
 
@@ -566,8 +567,8 @@ void Text::charInserted(Cursor & cur)
 
        // register word if a non-letter was entered
        if (cur.pos() > 1
-           && par.isLetter(cur.pos() - 2)
-           && !par.isLetter(cur.pos() - 1)) {
+           && !par.isWordSeparator(cur.pos() - 2)
+           && par.isWordSeparator(cur.pos() - 1)) {
                // get the word in front of cursor
                LASSERT(this == cur.text(), /**/);
                cur.paragraph().updateWords();
@@ -601,14 +602,14 @@ bool Text::cursorForwardOneWord(Cursor & cur)
                         ++pos;
 
                // Skip over either a non-char inset or a full word
-               if (pos != lastpos && !par.isLetter(pos))
+               if (pos != lastpos && par.isWordSeparator(pos))
                        ++pos;
-               else while (pos != lastpos && par.isLetter(pos))
+               else while (pos != lastpos && !par.isWordSeparator(pos))
                             ++pos;
        } else {
                LASSERT(pos < lastpos, /**/); // see above
-               if (par.isLetter(pos))
-                       while (pos != lastpos && par.isLetter(pos))
+               if (!par.isWordSeparator(pos))
+                       while (pos != lastpos && !par.isWordSeparator(pos))
                                ++pos;
                else if (par.isChar(pos))
                        while (pos != lastpos && par.isChar(pos))
@@ -643,17 +644,17 @@ bool Text::cursorBackwardOneWord(Cursor & cur)
                        --pos;
 
                // Skip over either a non-char inset or a full word
-               if (pos != 0 && !par.isLetter(pos - 1) && !par.isChar(pos - 1))
+               if (pos != 0 && par.isWordSeparator(pos - 1) && !par.isChar(pos - 1))
                        --pos;
-               else while (pos != 0 && par.isLetter(pos - 1))
+               else while (pos != 0 && !par.isWordSeparator(pos - 1))
                             --pos;
        } else {
                // Skip over white space
                while (pos != 0 && par.isSpace(pos - 1))
                             --pos;
 
-               if (pos != 0 && par.isLetter(pos - 1))
-                       while (pos != 0 && par.isLetter(pos - 1))
+               if (pos != 0 && !par.isWordSeparator(pos - 1))
+                       while (pos != 0 && !par.isWordSeparator(pos - 1))
                                --pos;
                else if (pos != 0 && par.isChar(pos - 1))
                        while (pos != 0 && par.isChar(pos - 1))
@@ -681,9 +682,9 @@ bool Text::cursorVisLeftOneWord(Cursor & cur)
                // collect some information about current cursor position
                temp_cur.getSurroundingPos(left_pos, right_pos);
                left_is_letter = 
-                       (left_pos > -1 ? temp_cur.paragraph().isLetter(left_pos) : false);
+                       (left_pos > -1 ? !temp_cur.paragraph().isWordSeparator(left_pos) : false);
                right_is_letter = 
-                       (right_pos > -1 ? temp_cur.paragraph().isLetter(right_pos) : false);
+                       (right_pos > -1 ? !temp_cur.paragraph().isWordSeparator(right_pos) : false);
 
                // if we're not at a letter/non-letter boundary, continue moving
                if (left_is_letter == right_is_letter)
@@ -718,9 +719,9 @@ bool Text::cursorVisRightOneWord(Cursor & cur)
                // collect some information about current cursor position
                temp_cur.getSurroundingPos(left_pos, right_pos);
                left_is_letter = 
-                       (left_pos > -1 ? temp_cur.paragraph().isLetter(left_pos) : false);
+                       (left_pos > -1 ? !temp_cur.paragraph().isWordSeparator(left_pos) : false);
                right_is_letter = 
-                       (right_pos > -1 ? temp_cur.paragraph().isLetter(right_pos) : false);
+                       (right_pos > -1 ? !temp_cur.paragraph().isWordSeparator(right_pos) : false);
 
                // if we're not at a letter/non-letter boundary, continue moving
                if (left_is_letter == right_is_letter)
@@ -794,8 +795,8 @@ void Text::acceptOrRejectChanges(Cursor & cur, ChangeOp op)
        LASSERT(this == cur.text(), /**/);
 
        if (!cur.selection()) {
-               Change const & change = cur.paragraph().lookupChange(cur.pos());
-               if (!(change.changed() && findNextChange(&cur.bv())))
+               bool const changed = cur.paragraph().isChanged(cur.pos());
+               if (!(changed && findNextChange(&cur.bv())))
                        return;
        }
 
@@ -832,9 +833,9 @@ void Text::acceptOrRejectChanges(Cursor & cur, ChangeOp op)
                pos_type right = (pit == endPit ? endPos : parSize);
 
                if (op == ACCEPT) {
-                       pars_[pit].acceptChanges(cur.buffer()->params(), left, right);
+                       pars_[pit].acceptChanges(left, right);
                } else {
-                       pars_[pit].rejectChanges(cur.buffer()->params(), left, right);
+                       pars_[pit].rejectChanges(left, right);
                }
        }
 
@@ -911,7 +912,7 @@ void Text::rejectChanges(BufferParams const & bparams)
        // (do not consider end-of-par)
        for (pit_type pit = 0; pit < pars_size; ++pit) {
                if (!pars_[pit].empty())   // prevent assertion failure
-                       pars_[pit].rejectChanges(bparams, 0, pars_[pit].size());
+                       pars_[pit].rejectChanges(0, pars_[pit].size());
        }
 
        // next, reject imaginary end-of-par characters
@@ -1240,7 +1241,10 @@ bool Text::dissolveInset(Cursor & cur)
                // restore position
                cur.pit() = min(cur.lastpit(), spit);
                cur.pos() = min(cur.lastpos(), spos);
-       }
+       } else
+               // this is the least that needs to be done (bug 6003)
+               // in the above case, pasteParagraphList handles this
+               cur.buffer()->updateLabels();
        cur.clearSelection();
        cur.resetAnchor();
        return true;
@@ -1352,7 +1356,7 @@ docstring Text::currentState(Cursor const & cur) const
 
        Change change = par.lookupChange(cur.pos());
 
-       if (change.type != Change::UNCHANGED) {
+       if (change.changed()) {
                Author const & a = buf.params().authors().get(change.author);
                os << _("Change: ") << a.name();
                if (!a.email().empty())
@@ -1603,8 +1607,8 @@ bool Text::completionSupported(Cursor const & cur) const
 {
        Paragraph const & par = cur.paragraph();
        return cur.pos() > 0
-               && (cur.pos() >= par.size() || !par.isLetter(cur.pos()))
-               && par.isLetter(cur.pos() - 1);
+               && (cur.pos() >= par.size() || par.isWordSeparator(cur.pos()))
+               && !par.isWordSeparator(cur.pos() - 1);
 }