]> git.lyx.org Git - lyx.git/blobdiff - src/paragraph.C
do not create invalid .lyx files when importing \i{}, \j{}, \l{} or \L{}.
[lyx.git] / src / paragraph.C
index afe3b71f346fbed1c9bc8ae624fada0c5f163bc3..b030b7ff8fe796e6fb84c52a5f9326256510faa7 100644 (file)
@@ -56,6 +56,8 @@
 
 namespace lyx {
 
+using lyx::support::contains;
+using lyx::support::rsplit;
 using support::subst;
 
 using std::distance;
@@ -736,7 +738,21 @@ string const corrected_env(string const & suffix, string const & env,
                output += correction(env);
        else
                output += env;
-       return output + "}";
+       output += "}";
+       if (suffix == "\\begin")
+               output += "\n";
+       return output;
+}
+
+
+int adjust_column_count(string const & str, int oldcol)
+{
+       if (!contains(str, "\n"))
+               return oldcol + str.size();
+       else {
+               string tmp;
+               return rsplit(str, tmp, '\n').size();
+       }
 }
 
 } // namespace anon
@@ -782,7 +798,7 @@ int Paragraph::startTeXParParams(BufferParams const & bparams,
                else
                        output = corrected_env("\\begin", "flushright", ownerCode());
                os << from_ascii(output);
-               column += output.size();
+               column = adjust_column_count(output, column);
                break;
        } case LYX_ALIGN_RIGHT: {
                string output;
@@ -791,13 +807,13 @@ int Paragraph::startTeXParParams(BufferParams const & bparams,
                else
                        output = corrected_env("\\begin", "flushleft", ownerCode());
                os << from_ascii(output);
-               column += output.size();
+               column = adjust_column_count(output, column);
                break;
        } case LYX_ALIGN_CENTER: {
                string output;
                output = corrected_env("\\begin", "center", ownerCode());
                os << from_ascii(output);
-               column += output.size();
+               column = adjust_column_count(output, column);
                break;
        }
        }
@@ -837,26 +853,26 @@ int Paragraph::endTeXParParams(BufferParams const & bparams,
        case LYX_ALIGN_LEFT: {
                string output;
                if (getParLanguage(bparams)->babel() != "hebrew")
-                       output = corrected_env("\\par\\end", "flushleft", ownerCode());
+                       output = corrected_env("\n\\par\\end", "flushleft", ownerCode());
                else
-                       output = corrected_env("\\par\\end", "flushright", ownerCode());
+                       output = corrected_env("\n\\par\\end", "flushright", ownerCode());
                os << from_ascii(output);
-               column += output.size();
+               column = adjust_column_count(output, column);
                break;
        } case LYX_ALIGN_RIGHT: {
                string output;
                if (getParLanguage(bparams)->babel() != "hebrew")
-                       output = corrected_env("\\par\\end", "flushright", ownerCode());
+                       output = corrected_env("\n\\par\\end", "flushright", ownerCode());
                else
-                       output = corrected_env("\\par\\end", "flushleft", ownerCode());
+                       output = corrected_env("\n\\par\\end", "flushleft", ownerCode());
                os << from_ascii(output);
-               column += output.size();
+               column = adjust_column_count(output, column);
                break;
        } case LYX_ALIGN_CENTER: {
                string output;
-               output = corrected_env("\\par\\end", "center", ownerCode());
+               output = corrected_env("\n\\par\\end", "center", ownerCode());
                os << from_ascii(output);
-               column += output.size();
+               column = adjust_column_count(output, column);
                break;
        }
        }
@@ -1240,7 +1256,6 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf,
                        if (style->pass_thru)
                                 os.put(c);
                        else
-                                // FIXME UNICODE
                                 os << sgml::escapeChar(c);
                }
                font_old = font;
@@ -1308,7 +1323,8 @@ bool Paragraph::isRightToLeftPar(BufferParams const & bparams) const
 void Paragraph::changeLanguage(BufferParams const & bparams,
                               Language const * from, Language const * to)
 {
-       for (pos_type i = 0; i < size(); ++i) {
+       // change language including dummy font change at the end
+       for (pos_type i = 0; i <= size(); ++i) {
                LyXFont font = getFontSettings(bparams, i);
                if (font.language() == from) {
                        font.setLanguage(to);
@@ -1392,7 +1408,6 @@ docstring const Paragraph::asString(Buffer const & buffer,
 
        for (pos_type i = beg; i < end; ++i) {
                value_type const c = getUChar(buffer.params(), i);
-               // FIXME: isPrintable does not work for lyx::char_type
                if (isPrintable(c))
                        os.put(c);
                else if (c == META_INSET)
@@ -1422,6 +1437,12 @@ bool Paragraph::isChanged(pos_type start, pos_type end) const
 }
 
 
+bool Paragraph::isMergedOnEndOfParDeletion(bool trackChanges) const
+{
+       return pimpl_->isMergedOnEndOfParDeletion(trackChanges);
+}
+
+
 void Paragraph::setChange(Change const & change)
 {
        pimpl_->setChange(change);
@@ -1570,6 +1591,7 @@ char_type Paragraph::transformChar(char_type c, pos_type pos) const
 {
        if (!Encodings::is_arabic(c))
                if (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 && isDigit(c))
+                       // FIXME UNICODE What does this do?
                        return c + (0xb0 - '0');
                else
                        return c;