]> git.lyx.org Git - lyx.git/commitdiff
Fix bug #6936.
authorGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Sun, 25 Mar 2012 09:16:32 +0000 (11:16 +0200)
committerGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Sun, 25 Mar 2012 09:16:32 +0000 (11:16 +0200)
If \hline is entered, do not create an unknown inset, but increase the number
of hlines of the current row if that is allowed. The same idea is applied to
copy-paste (not part of the bug report).
This is also a test for committing via git.

src/mathed/InsetMathGrid.cpp
src/mathed/InsetMathGrid.h
src/mathed/InsetMathNest.cpp
src/mathed/InsetMathNest.h
src/tex2lyx/table.cpp

index 5b58f09a03eb1b746873057d84b00d19f985ac60..ed77f71f851be12a46fa959b5b0f9c7e81d0defc 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "InsetMathGrid.h"
 
+#include "InsetMathUnknown.h"
 #include "MathData.h"
 #include "MathParser.h"
 #include "MathStream.h"
@@ -176,6 +177,22 @@ void InsetMathGrid::setDefaults()
 }
 
 
+bool InsetMathGrid::interpretString(Cursor & cur, docstring const & str)
+{
+       if (str == "\\hline") {
+               FuncRequest fr = FuncRequest(LFUN_INSET_MODIFY, "tabular add-hline-above");
+               FuncStatus status;
+               if (getStatus(cur, fr, status)) {
+                       if (status.enabled()) {
+                               rowinfo_[cur.row()].lines_++;
+                               return true;
+                       }
+               }
+       }
+       return InsetMathNest::interpretString(cur, str);
+}
+
+
 void InsetMathGrid::setHorizontalAlignments(docstring const & hh)
 {
        col_type col = 0;
@@ -1332,11 +1349,25 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
                                mathed_parse_normal(grid, topaste, parseflg | Parse::VERBATIM);
                        }
 
+               bool hline_enabled = false;
+               FuncRequest fr = FuncRequest(LFUN_INSET_MODIFY, "tabular add-hline-above");
+               FuncStatus status;
+               if (getStatus(cur, fr, status))
+                       hline_enabled = status.enabled();
                if (grid.nargs() == 1) {
                        // single cell/part of cell
                        cur.recordUndo();
                        cur.cell().insert(cur.pos(), grid.cell(0));
                        cur.pos() += grid.cell(0).size();
+                       if (hline_enabled)
+                               rowinfo_[cur.row()].lines_ += grid.rowinfo_[0].lines_;
+                       else {
+                               for (unsigned int l = 0; l < grid.rowinfo_[0].lines_; ++l) {
+                                        cur.cell().insert(0,
+                                               MathAtom(new InsetMathUnknown(from_ascii("\\hline"))));
+                                        cur.pos()++;
+                               }
+                       }
                } else {
                        // multiple cells
                        cur.recordUndoInset();
@@ -1349,6 +1380,15 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
                                        idx_type i = index(r + cur.row(), c + col(cur.idx()));
                                        cell(i).insert(0, grid.cell(grid.index(r, c)));
                                }
+                               if (hline_enabled)
+                                       rowinfo_[r].lines_ += grid.rowinfo_[r].lines_;
+                               else {
+                                       for (unsigned int l = 0; l < grid.rowinfo_[r].lines_; ++l) {
+                                               idx_type i = index(r + cur.row(), 0);
+                                               cell(i).insert(0,
+                                                       MathAtom(new InsetMathUnknown(from_ascii("\\hline"))));
+                                       }
+                               }
                                // append the left over horizontal cells to the last column
                                idx_type i = index(r + cur.row(), ncols() - 1);
                                for (InsetMath::col_type c = numcols; c < grid.ncols(); ++c)
@@ -1356,9 +1396,18 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
                        }
                        // append the left over vertical cells to the last _cell_
                        idx_type i = nargs() - 1;
-                       for (row_type r = numrows; r < grid.nrows(); ++r)
+                       for (row_type r = numrows; r < grid.nrows(); ++r) {
                                for (col_type c = 0; c < grid.ncols(); ++c)
                                        cell(i).append(grid.cell(grid.index(r, c)));
+                               if (hline_enabled)
+                                       rowinfo_[r].lines_ += grid.rowinfo_[r].lines_;
+                               else {
+                                       for (unsigned int l = 0; l < grid.rowinfo_[r].lines_; ++l) {
+                                               cell(i).insert(0,
+                                                       MathAtom(new InsetMathUnknown(from_ascii("\\hline"))));
+                                       }
+                               }
+                       }
                }
                cur.clearSelection(); // bug 393
                // FIXME audit setBuffer calls
index bfa286b766a95c34e4d663bb840b2f5b985229f8..7ff533be998e4f978b16d500c3e9cb95c3a39434 100644 (file)
@@ -194,6 +194,8 @@ public:
        virtual char defaultColAlign(col_type) { return 'c'; }
        ///
        void setDefaults();
+       ///
+       virtual bool interpretString(Cursor & cur, docstring const & str);
 
        ///
        virtual int colsep() const;
index bd702464c35da390883f52609dc66f36c97deb08..c2f4fc16ba5deabdc0e1a9ae2d4e610c038e0927 100644 (file)
@@ -872,7 +872,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
                // if relevant. Think typing "\frac<space>".
                if (cmd.argument()[0] == ' '
                    && cur.inMacroMode() && cur.macroName() != "\\"
-                   && cur.macroModeClose()) {
+                   && cur.macroModeClose() && cur.pos() > 0) {
                        MathAtom const atom = cur.prevAtom();
                        if (atom->asNestInset() && atom->isActive()) {
                                cur.posBackward();
index 4e18dbda71e25d787945371e654213922e212474..99537d8a17e0579d48926f72627e62e0603b77c6 100644 (file)
@@ -172,7 +172,7 @@ public:
        /// interpret \p str and insert the result at the current position of
        /// \p cur if it is something known. Return whether \p cur was
        /// inserted.
-       bool interpretString(Cursor & cur, docstring const & str);
+       virtual bool interpretString(Cursor & cur, docstring const & str);
 
 private:
        /// lfun handler
index ca3a84cdae6a879e5dbbc3239c5601923a6ee6fd..7ba5344d1324c9d6ba697ae4444022a26fe7d290 100644 (file)
@@ -1272,7 +1272,7 @@ void handle_tabular(Parser & p, ostream & os, string const & name,
        os << "\n<lyxtabular version=\"3\" rows=\"" << rowinfo.size()
           << "\" columns=\"" << colinfo.size() << "\">\n";
        os << "<features"
-          << write_attribute("rotate", "0")
+          << write_attribute("rotate", false)
           << write_attribute("booktabs", booktabs)
           << write_attribute("islongtable", is_long_tabular);
        if (is_long_tabular) {