]> git.lyx.org Git - features.git/blobdiff - src/Text.cpp
Move Color::color enum to ColorCode.h
[features.git] / src / Text.cpp
index 456a127d41c54e915fcb25c3f09373e702a272b6..44f14e185dcebb7fccfd38d3d9c5906fe76c3fab 100644 (file)
@@ -38,7 +38,6 @@
 #include "FontIterator.h"
 #include "gettext.h"
 #include "Language.h"
-#include "Color.h"
 #include "Length.h"
 #include "Lexer.h"
 #include "LyXRC.h"
@@ -85,9 +84,7 @@ namespace lyx {
 
 using support::bformat;
 using support::contains;
-using support::lowercase;
 using support::split;
-using support::uppercase;
 
 using cap::cutSelection;
 using cap::pasteParagraphList;
@@ -102,17 +99,9 @@ void readParToken(Buffer const & buf, Paragraph & par, Lexer & lex,
        BufferParams const & bp = buf.params();
 
        if (token[0] != '\\') {
-#if 0
-               string::const_iterator cit = token.begin();
-               for (; cit != token.end(); ++cit)
-                       par.insertChar(par.size(), (*cit), font, change);
-#else
                docstring dstr = lex.getDocString();
-               docstring::const_iterator cit = dstr.begin();
-               docstring::const_iterator cend = dstr.end();
-               for (; cit != cend; ++cit)
-                       par.insertChar(par.size(), *cit, font, change);
-#endif
+               par.appendString(dstr, font, change);
+
        } else if (token == "\\begin_layout") {
                lex.eatLine();
                docstring layoutname = lex.getDocString();
@@ -216,12 +205,12 @@ void readParToken(Buffer const & buf, Paragraph & par, Lexer & lex,
                // Insets don't make sense in a free-spacing context! ---Kayvan
                if (par.isFreeSpacing()) {
                        if (token == "\\InsetSpace")
-                               par.insertChar(par.size(), ' ', font, change);
+                               par.appendChar(' ', font, change);
                        else if (lex.isOK()) {
                                lex.next();
                                string const next_token = lex.getString();
                                if (next_token == "\\-")
-                                       par.insertChar(par.size(), '-', font, change);
+                                       par.appendChar('-', font, change);
                                else {
                                        lex.printError("Token `$$Token' "
                                                       "is in free space "
@@ -239,7 +228,7 @@ void readParToken(Buffer const & buf, Paragraph & par, Lexer & lex,
                                        font, change);
                }
        } else if (token == "\\backslash") {
-               par.insertChar(par.size(), '\\', font, change);
+               par.appendChar('\\', font, change);
        } else if (token == "\\newline") {
                auto_ptr<Inset> inset(new InsetNewline);
                inset->read(buf, lex);
@@ -436,7 +425,6 @@ void Text::breakParagraph(Cursor & cur, bool inverse_logic)
 void Text::insertChar(Cursor & cur, char_type c)
 {
        BOOST_ASSERT(this == cur.text());
-       BOOST_ASSERT(c != Paragraph::META_INSET);
 
        cur.recordUndo(INSERT_UNDO);
 
@@ -807,7 +795,7 @@ void Text::deleteWordForward(Cursor & cur)
 {
        BOOST_ASSERT(this == cur.text());
        if (cur.lastpos() == 0)
-               cursorRight(cur);
+               cursorForward(cur);
        else {
                cur.resetAnchor();
                cur.selection() = true;
@@ -823,7 +811,7 @@ void Text::deleteWordBackward(Cursor & cur)
 {
        BOOST_ASSERT(this == cur.text());
        if (cur.lastpos() == 0)
-               cursorLeft(cur);
+               cursorBackward(cur);
        else {
                cur.resetAnchor();
                cur.selection() = true;
@@ -836,7 +824,7 @@ void Text::deleteWordBackward(Cursor & cur)
 
 
 // Kill to end of line.
-void Text::changeCase(Cursor & cur, Text::TextCase action)
+void Text::changeCase(Cursor & cur, TextCase action)
 {
        BOOST_ASSERT(this == cur.text());
        CursorSlice from;
@@ -859,72 +847,13 @@ void Text::changeCase(Cursor & cur, Text::TextCase action)
        pos_type begPos = from.pos();
        pos_type endPos = to.pos();
 
-       bool const trackChanges = cur.buffer().params().trackChanges;
-
        pos_type right = 0; // needed after the for loop
 
        for (pit_type pit = begPit; pit <= endPit; ++pit) {
-               pos_type parSize = pars_[pit].size();
-
-               pos_type pos = (pit == begPit ? begPos : 0);
-               right = (pit == endPit ? endPos : parSize);
-
-               // process sequences of modified characters; in change
-               // tracking mode, this approach results in much better
-               // usability than changing case on a char-by-char basis
-               docstring changes;
-
-               bool capitalize = true;
-
-               for (; pos < right; ++pos) {
-                       char_type oldChar = pars_[pit].getChar(pos);
-                       char_type newChar = oldChar;
-
-                       // ignore insets and don't play with deleted text!
-                       if (oldChar != Paragraph::META_INSET && !pars_[pit].isDeleted(pos)) {
-                               switch (action) {
-                               case text_lowercase:
-                                       newChar = lowercase(oldChar);
-                                       break;
-                               case text_capitalization:
-                                       if (capitalize) {
-                                               newChar = uppercase(oldChar);
-                                               capitalize = false;
-                                       }
-                                       break;
-                               case text_uppercase:
-                                       newChar = uppercase(oldChar);
-                                       break;
-                               }
-                       }
-
-                       if (!pars_[pit].isLetter(pos) || pars_[pit].isDeleted(pos)) {
-                               capitalize = true; // permit capitalization again
-                       }
-
-                       if (oldChar != newChar) {
-                               changes += newChar;
-                       }
-
-                       if (oldChar == newChar || pos == right - 1) {
-                               if (oldChar != newChar) {
-                                       pos++; // step behind the changing area
-                               }
-                               int erasePos = pos - changes.size();
-                               for (size_t i = 0; i < changes.size(); i++) {
-                                       pars_[pit].insertChar(pos, changes[i],
-                                               pars_[pit].getFontSettings(cur.buffer().params(),
-                                                               erasePos),
-                                               trackChanges);
-                                       if (!pars_[pit].eraseChar(erasePos, trackChanges)) {
-                                               ++erasePos;
-                                               ++pos; // advance
-                                               ++right; // expand selection
-                                       }
-                               }
-                               changes.clear();
-                       }
-               }
+               Paragraph & par = pars_[pit];
+               pos_type const pos = (pit == begPit ? begPos : 0);
+               right = (pit == endPit ? endPos : par.size());
+               par.changeCase(cur.buffer().params(), pos, right, action);
        }
 
        // the selection may have changed due to logically-only deleted chars
@@ -1086,9 +1015,9 @@ bool Text::backspace(Cursor & cur)
                // this is the code for a normal backspace, not pasting
                // any paragraphs
                cur.recordUndo(DELETE_UNDO);
-               // We used to do cursorLeftIntern() here, but it is
+               // We used to do cursorBackwardIntern() here, but it is
                // not a good idea since it triggers the auto-delete
-               // mechanism. So we do a cursorLeftIntern()-lite,
+               // mechanism. So we do a cursorBackwardIntern()-lite,
                // without the dreaded mechanism. (JMarc)
                setCursorIntern(cur, cur.pit(), cur.pos() - 1,
                                false, cur.boundary());
@@ -1136,10 +1065,8 @@ bool Text::dissolveInset(Cursor & cur) {
                // change it to the buffer language.
                ParagraphList::iterator it = plist.begin();
                ParagraphList::iterator it_end = plist.end();
-               for (; it != it_end; it++) {
-                       it->changeLanguage(b.params(), latex_language,
-                                       b.getLanguage());
-               }
+               for (; it != it_end; it++)
+                       it->changeLanguage(b.params(), latex_language, b.language());
 
                pasteParagraphList(cur, plist, b.params().getTextClassPtr(),
                                   b.errorList("Paste"));