]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetTabular.cpp
Reset cur.pit() when pasting into tables.
[lyx.git] / src / insets / InsetTabular.cpp
index 14f8e4a0f4f2f62279e00bf5db5b4c3001ef5fca..f9503c7124d8e23bff0629da8dbffb019d3d02ee 100644 (file)
@@ -33,6 +33,7 @@
 #include "DispatchResult.h"
 #include "FuncRequest.h"
 #include "FuncStatus.h"
+#include "InsetIterator.h"
 #include "InsetList.h"
 #include "Language.h"
 #include "LaTeXFeatures.h"
@@ -1860,7 +1861,7 @@ int Tabular::getRotateCell(idx_type cell) const
 
 bool Tabular::needRotating() const
 {
-       if (rotate)
+       if (rotate && !is_long_tabular)
                return true;
        for (row_type r = 0; r < nrows(); ++r)
                for (col_type c = 0; c < ncols(); ++c)
@@ -2652,6 +2653,17 @@ void Tabular::TeXRow(otexstream & os, row_type row,
                                tail.setMacrocontextPositionRecursive(dit);
                                tail.latex(os, newrp);
                        }
+               } else if (ltCaption(row)) {
+                       // Inside longtable caption rows, we must only output the caption inset
+                       // with its content and omit anything outside of that (see #10791)
+                       InsetIterator it = inset_iterator_begin(*const_cast<InsetTableCell *>(inset));
+                       InsetIterator i_end = inset_iterator_end(*const_cast<InsetTableCell *>(inset));
+                       for (; it != i_end; ++it) {
+                               if (it->lyxCode() != CAPTION_CODE)
+                                       continue;
+                               it->latex(os, runparams);
+                               break;
+                       }
                } else if (!isPartOfMultiRow(row, c)) {
                        if (!runparams.nice)
                                os.texrow().start(par.id(), 0);
@@ -2719,7 +2731,7 @@ void Tabular::latex(otexstream & os, OutputParams const & runparams) const
        if (!TexRow::isNone(pos))
                os.texrow().start(pos);
 
-       if (rotate != 0)
+       if (rotate != 0 && !is_long_tabular)
                os << "\\begin{turn}{" << convert<string>(rotate) << "}\n";
 
        if (is_long_tabular) {
@@ -2870,7 +2882,7 @@ void Tabular::latex(otexstream & os, OutputParams const & runparams) const
                        os << "\\end{tabular}";
        }
 
-       if (rotate != 0)
+       if (rotate != 0 && !is_long_tabular)
                os << breakln << "\\end{turn}";
 
        if (!TexRow::isNone(pos))
@@ -3427,7 +3439,7 @@ void Tabular::validate(LaTeXFeatures & features) const
                // Tell footnote that we need a savenote
                // environment in non-long tables or
                // longtable headers/footers
-               if (!is_long_tabular)
+               else if (!is_long_tabular && !features.inFloat())
                        features.saveNoteEnv("tabular");
                else if (!isValidRow(cellRow(cell)))
                        features.saveNoteEnv("longtable");
@@ -3678,7 +3690,7 @@ void InsetTabular::metrics(MetricsInfo & mi, Dimension & dim) const
                        MetricsInfo m = mi;
                        Length const p_width = tabular.getPWidth(cell);
                        if (!p_width.zero())
-                               m.base.textwidth = p_width.inPixels(mi.base);
+                               m.base.textwidth = mi.base.inPixels(p_width);
                        tabular.cellInset(cell)->metrics(m, dim);
                        if (!p_width.zero())
                                dim.wid = m.base.textwidth;
@@ -3738,12 +3750,12 @@ void InsetTabular::metrics(MetricsInfo & mi, Dimension & dim) const
                        maxdes = max(maxdes, dim.des + offset);
                }
                int const top_space = tabular.row_info[r].top_space_default ?
-                       default_line_space :
-                       tabular.row_info[r].top_space.inPixels(mi.base);
+                   default_line_space :
+                   mi.base.inPixels(tabular.row_info[r].top_space);
                tabular.setRowAscent(r, maxasc + ADD_TO_HEIGHT + top_space);
                int const bottom_space = tabular.row_info[r].bottom_space_default ?
-                       default_line_space :
-                       tabular.row_info[r].bottom_space.inPixels(mi.base);
+                   default_line_space :
+                   mi.base.inPixels(tabular.row_info[r].bottom_space);
                tabular.setRowDescent(r, maxdes + ADD_TO_HEIGHT + bottom_space);
        }
 
@@ -6162,6 +6174,7 @@ bool InsetTabular::pasteClipboard(Cursor & cur)
                        inset->setChange(Change(buffer().params().track_changes ?
                                                Change::INSERTED : Change::UNCHANGED));
                        cur.pos() = 0;
+                       cur.pit() = 0;
                }
        }
        return true;