commit bb8dca788ea7e0d2d8ec4fdecb92202d826027e2
Author: Daniel Ramoeller <[email protected]>
Date:   Wed Oct 6 05:29:35 2021 +0200

    More intuitive behaviour when adding cells to multicolumn/-row
    
    - Add column depending on where the cursor, e.g. in a multicolumn
    - Properly keep lines on multicolumn
    
    Fix for #12385.
---
 src/insets/InsetTabular.cpp | 34 ++++++++++++++++++++++++++--------
 src/insets/InsetTabular.h   |  4 ++--
 2 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp
index 659f342289..60b94cdd06 100644
--- a/src/insets/InsetTabular.cpp
+++ b/src/insets/InsetTabular.cpp
@@ -1032,25 +1032,42 @@ void Tabular::copyColumn(col_type const col)
 }
 
 
-void Tabular::appendColumn(col_type col)
+void Tabular::appendColumn(col_type col, row_type row)
 {
-       insertColumn(col, false);
+       insertColumn(col, false, row);
 }
 
 
-void Tabular::insertColumn(col_type const col, bool copy)
+void Tabular::insertColumn(col_type col, bool copy, row_type row)
 {
        bool const ct = buffer().params().track_changes;
-       column_info.insert(column_info.begin() + col + 1, column_info[col]);
+
+       // insert column after last cell of multicolumn
+       idx_type cspan = columnSpan(cellIndex(row, col));
+       col += cspan - 1;
+       column_info.insert(column_info.begin() + col + 1,
+                                          ColumnData(column_info[col]));
 
        for (row_type r = 0; r < nrows(); ++r) {
                cell_info[r].insert(cell_info[r].begin() + col + 1,
                        copy ? cell_info[r][col] : CellData(buffer_));
-               if (cell_info[r][col].multicolumn == CELL_BEGIN_OF_MULTICOLUMN)
+               // make new cell part of multicolumn if old cell was at the 
beginning
+               // or middle of a multicolumn
+               if (cell_info[r][col].multicolumn == CELL_BEGIN_OF_MULTICOLUMN
+                       || (col + 1 < ncols()
+                               && cell_info[r][col].multicolumn == 
CELL_PART_OF_MULTICOLUMN
+                               && cell_info[r][col + 2].multicolumn == 
CELL_PART_OF_MULTICOLUMN
+                       ))
                        cell_info[r][col + 1].multicolumn = 
CELL_PART_OF_MULTICOLUMN;
        }
        updateIndexes();
        for (row_type r = 0; r < nrows(); ++r) {
+               // arguably, if the new cell is (hidden) part multicol, no 
lines need to
+               // be set. note: if that is to be changed, which might be a 
good idea,
+               // this needs to be done directly on cell_info because 
cellIndex is
+               // ignorant about parts of multicolumn
+               if (isPartOfMultiColumn(r, col + 1))
+                       continue;
                // inherit line settings
                idx_type const i = cellIndex(r, col + 1);
                idx_type const j = cellIndex(r, col);
@@ -1058,9 +1075,10 @@ void Tabular::insertColumn(col_type const col, bool copy)
                setTopLine(i, topLine(j));
                setLeftLine(i, leftLine(j));
                setRightLine(i, rightLine(j));
-               if (rightLine(i) && rightLine(j)) {
+               // avoid creating double lines in between old and new cell, 
leaving
+               // only the left line in berween (the default when creating a 
table)
+               if (leftLine(i) && cell_info[r][col + 1].multicolumn == 
CELL_NORMAL)
                        setRightLine(j, false);
-               }
        }
        if (ct) {
                column_info[col + 1].change.setInserted();
@@ -7321,7 +7339,7 @@ void InsetTabular::tabularFeatures(Cursor & cur,
 
        case Tabular::APPEND_COLUMN:
                // append the column into the tabular
-               tabular.appendColumn(column);
+               tabular.appendColumn(column, row);
                cur.idx() = tabular.cellIndex(row, column);
                break;
 
diff --git a/src/insets/InsetTabular.h b/src/insets/InsetTabular.h
index c20b6c014c..b385ba8346 100644
--- a/src/insets/InsetTabular.h
+++ b/src/insets/InsetTabular.h
@@ -643,13 +643,13 @@ public:
        void moveRow(row_type row_start, row_type row_end,
                     RowDirection direction);
        ///
-       void appendColumn(col_type column);
+       void appendColumn(col_type column, row_type row = 0);
        ///
        void deleteColumn(col_type column, bool const force = false);
        ///
        void copyColumn(col_type column);
        ///
-       void insertColumn(col_type column, bool copy);
+       void insertColumn(col_type column, bool copy, row_type row = 0);
        ///
        idx_type getFirstCellInRow(row_type row, bool const ct = false) const;
        ///
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to