]> git.lyx.org Git - lyx.git/blobdiff - src/Text.cpp
* GuiToolbar.cpp:
[lyx.git] / src / Text.cpp
index 19b3ead091d3002eb767e46ce0d462b013064453..8e6361a6f09449a8b8cc0acff6ed780668787888 100644 (file)
@@ -102,10 +102,10 @@ void readParToken(Buffer const & buf, Paragraph & par, Lexer & lex,
                if (layoutname.empty())
                        layoutname = tclass.defaultLayoutName();
 
-               if (par.forceEmptyLayout()) {
+               if (par.forcePlainLayout()) {
                        // in this case only the empty layout is allowed
                        layoutname = tclass.emptyLayoutName();
-               } else if (par.useEmptyLayout()) {
+               } else if (par.usePlainLayout()) {
                        // in this case, default layout maps to empty layout 
                        if (layoutname == tclass.defaultLayoutName())
                                layoutname = tclass.emptyLayoutName();
@@ -115,16 +115,11 @@ void readParToken(Buffer const & buf, Paragraph & par, Lexer & lex,
                                layoutname = tclass.defaultLayoutName();
                }
 
-               bool hasLayout = tclass.hasLayout(layoutname);
-
-               if (!hasLayout) {
-                       errorList.push_back(ErrorItem(_("Unknown layout"),
-                       bformat(_("Layout '%1$s' does not exist in textclass '%2$s'\nTrying to use the default instead.\n"),
-                       layoutname, from_utf8(tclass.name())), par.id(), 0, par.size()));
-                       layoutname = par.useEmptyLayout() ? 
-                                       tclass.emptyLayoutName() :
-                                       tclass.defaultLayoutName();
-               }
+               // When we apply an unknown layout to a document, we add this layout to the textclass
+               // of this document. For example, when you apply class article to a beamer document,
+               // all unknown layouts such as frame will be added to document class article so that
+               // these layouts can keep their original names.
+               tclass.addLayoutIfNeeded(layoutname);
 
                par.setLayout(bp.documentClass()[layoutname]);
 
@@ -207,7 +202,7 @@ void readParToken(Buffer const & buf, Paragraph & par, Lexer & lex,
        } else if (token == "\\backslash") {
                par.appendChar('\\', font, change);
        } else if (token == "\\LyXTable") {
-               auto_ptr<Inset> inset(new InsetTabular(buf));
+               auto_ptr<Inset> inset(new InsetTabular(const_cast<Buffer &>(buf)));
                inset->read(lex);
                par.insertInset(par.size(), inset.release(), font, change);
        } else if (token == "\\lyxline") {
@@ -584,20 +579,46 @@ bool Text::cursorForwardOneWord(Cursor & cur)
 {
        LASSERT(this == cur.text(), /**/);
 
-       Cursor old = cur;
+       pos_type const lastpos = cur.lastpos();
+       pit_type pit = cur.pit();
+       pos_type pos = cur.pos();
+       Paragraph const & par = cur.paragraph();
+
+       // Paragraph boundary is a word boundary
+       if (pos == lastpos) {
+               if (pit != cur.lastpit())
+                       return setCursor(cur, pit + 1, 0);
+               else
+                       return false;
+       }
 
-       if (old.pos() == old.lastpos() && old.pit() != old.lastpit()) {
-               ++old.pit();
-               old.pos() = 0;
+       if (lyxrc.mac_like_word_movement) {
+               // Skip through trailing punctuation and spaces.
+               while (pos != lastpos && (par.isChar(pos) || par.isSpace(pos)))
+                        ++pos;
+
+               // Skip over either a non-char inset or a full word
+               if (pos != lastpos && !par.isLetter(pos))
+                       ++pos;
+               else while (pos != lastpos && par.isLetter(pos))
+                            ++pos;
        } else {
-               // Advance through word.
-               while (old.pos() != old.lastpos() && old.paragraph().isLetter(old.pos()))
-                       ++old.pos();
-               // Skip through trailing nonword stuff.
-               while (old.pos() != old.lastpos() && !old.paragraph().isLetter(old.pos()))
-                       ++old.pos();
+               LASSERT(pos < lastpos, /**/); // see above
+               if (par.isLetter(pos))
+                       while (pos != lastpos && par.isLetter(pos))
+                               ++pos;
+               else if (par.isChar(pos))
+                       while (pos != lastpos && par.isChar(pos))
+                               ++pos;
+               else if (!par.isSpace(pos)) // non-char inset
+                       ++pos;
+
+               // Skip over white space
+               while (pos != lastpos && par.isSpace(pos))
+                            ++pos;             
        }
-       return setCursor(cur, old.pit(), old.pos());
+
+       return setCursor(cur, pit, pos);
 }
 
 
@@ -605,20 +626,40 @@ bool Text::cursorBackwardOneWord(Cursor & cur)
 {
        LASSERT(this == cur.text(), /**/);
 
-       Cursor old = cur;
+       pit_type pit = cur.pit();
+       pos_type pos = cur.pos();
+       Paragraph & par = cur.paragraph();
+
+       // Paragraph boundary is a word boundary
+       if (pos == 0 && pit != 0)
+               return setCursor(cur, pit - 1, getPar(pit - 1).size());
 
-       if (old.pos() == 0 && old.pit() != 0) {
-               --old.pit();
-               old.pos() = old.lastpos();
+       if (lyxrc.mac_like_word_movement) {
+               // Skip through punctuation and spaces.
+               while (pos != 0 && (par.isChar(pos - 1) || par.isSpace(pos - 1)))
+                       --pos;
+
+               // Skip over either a non-char inset or a full word
+               if (pos != 0 && !par.isLetter(pos - 1) && !par.isChar(pos - 1))
+                       --pos;
+               else while (pos != 0 && par.isLetter(pos - 1))
+                            --pos;
        } else {
-               // Skip through initial nonword stuff.
-               while (old.pos() != 0 && !old.paragraph().isLetter(old.pos() - 1))
-                       --old.pos();
-               // Advance through word.
-               while (old.pos() != 0 && old.paragraph().isLetter(old.pos() - 1))
-                       --old.pos();
+               // 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))
+                               --pos;
+               else if (pos != 0 && par.isChar(pos - 1))
+                       while (pos != 0 && par.isChar(pos - 1))
+                               --pos;
+               else if (pos != 0 && !par.isSpace(pos - 1)) // non-char inset
+                       --pos;
        }
-       return setCursor(cur, old.pit(), old.pos());
+
+       return setCursor(cur, pit, pos);
 }
 
 
@@ -984,7 +1025,7 @@ bool Text::handleBibitems(Cursor & cur)
        } 
 
        // otherwise reset to default
-       cur.paragraph().setEmptyOrDefaultLayout(bufparams.documentClass());
+       cur.paragraph().setPlainOrDefaultLayout(bufparams.documentClass());
        return true;
 }
 
@@ -1074,7 +1115,7 @@ bool Text::backspacePos0(Cursor & cur)
        // or the empty layout.
        else if (par.layout() == prevpar.layout()
                 || tclass.isDefaultLayout(par.layout())
-                || tclass.isEmptyLayout(par.layout())) {
+                || tclass.isPlainLayout(par.layout())) {
                cur.recordUndo(ATOMIC_UNDO, prevcur.pit());
                mergeParagraph(bufparams, plist, prevcur.pit());
                needsUpdate = true;