]> 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 c0c53c3e524220eed2aefacf3aef80680facef39..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;
        }
        }
@@ -1421,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);