commit ac3562dbc9f193d0bb924ba9a86caf09779eae0e
Author: Juergen Spitzmueller <[email protected]>
Date:   Tue Oct 11 16:01:29 2022 +0200

    Need cellvarwidth also in left-aligned cells if they use newlines (#12587)
---
 src/insets/InsetTabular.cpp |   19 +++++++++++++++++--
 src/insets/InsetTabular.h   |    2 ++
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp
index e2529a9..082d4d9 100644
--- a/src/insets/InsetTabular.cpp
+++ b/src/insets/InsetTabular.cpp
@@ -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
diff --git a/src/insets/InsetTabular.h b/src/insets/InsetTabular.h
index fcf4c21..6c63cbc 100644
--- a/src/insets/InsetTabular.h
+++ b/src/insets/InsetTabular.h
@@ -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,
-- 
lyx-cvs mailing list
[email protected]
http://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to