]> git.lyx.org Git - features.git/commitdiff
Need cellvarwidth also in left-aligned cells if they use newlines (#12587)
authorJuergen Spitzmueller <spitz@lyx.org>
Tue, 11 Oct 2022 14:01:29 +0000 (16:01 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Tue, 11 Oct 2022 14:01:29 +0000 (16:01 +0200)
src/insets/InsetTabular.cpp
src/insets/InsetTabular.h

index e2529a9fd0abe03b3ba1aefb0e370c26f5d4905d..082d4d97617e547e40b235a57756f9a5c17a3a82 100644 (file)
@@ -3007,7 +3007,7 @@ void Tabular::TeXCellPreamble(otexstream & os, idx_type cell,
                   << "}\n";
        } else if (getUsebox(cell) == BOX_VARWIDTH
                   && (getRotateCell(cell) != 0 || align != LYX_ALIGN_LEFT
-                      || valign != LYX_VALIGN_TOP)) {
+                      || valign != LYX_VALIGN_TOP || hasNewlines(cell))) {
                os << "\\begin{cellvarwidth}[";
                switch (valign) {
                case LYX_VALIGN_TOP:
@@ -3056,7 +3056,7 @@ void Tabular::TeXCellPostamble(otexstream & os, idx_type cell,
                os << breakln << "\\end{minipage}";
        else if (getUsebox(cell) == BOX_VARWIDTH
                 && (getRotateCell(cell) != 0 || getAlignment(cell) != LYX_ALIGN_LEFT
-                    || getVAlignment(cell) != LYX_VALIGN_TOP))
+                    || getVAlignment(cell) != LYX_VALIGN_TOP || hasNewlines(cell)))
                os << breakln << "\\end{cellvarwidth}";
        if (getRotateCell(cell) != 0)
                os << breakln << "\\end{turn}";
@@ -4272,6 +4272,21 @@ Tabular::BoxType Tabular::useBox(idx_type cell) const
 }
 
 
+bool Tabular::hasNewlines(idx_type cell) const
+{
+       ParagraphList const & parlist = cellInset(cell)->paragraphs();
+       ParagraphList::const_iterator cit = parlist.begin();
+       ParagraphList::const_iterator end = parlist.end();
+
+       for (; cit != end; ++cit)
+               for (int i = 0; i < cit->size(); ++i)
+                       if (cit->isNewline(i))
+                               return true;
+
+       return false;
+}
+
+
 /////////////////////////////////////////////////////////////////////
 //
 // InsetTableCell
index fcf4c2100f7d07d3dc914eaeb5d39dadf8e7f3f8..6c63cbc1d39d4efdd4ba570beda4c1729ab38f4d 100644 (file)
@@ -919,6 +919,8 @@ public:
        ///
        BoxType useBox(idx_type cell) const;
        ///
+       bool hasNewlines(idx_type cell) const;
+       ///
        bool isValidRow(row_type const row) const;
        ///
        void TeXRow(otexstream &, row_type const row,