From: Edwin Leuven Date: Mon, 15 Mar 2010 18:08:38 +0000 (+0000) Subject: avoid invalidated indexes with multicol/row X-Git-Tag: 2.0.0~3794 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=62b0691b3cd7cab8fa1ad0369dff0eaf21018f8d;p=features.git avoid invalidated indexes with multicol/row git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33751 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index 25bd686196..d689b63dad 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -1504,17 +1504,20 @@ Tabular::CellData & Tabular::cellInfo(idx_type cell) const } -void Tabular::setMultiColumn(idx_type cell, idx_type number) +Tabular::idx_type Tabular::setMultiColumn(idx_type cell, idx_type number) { idx_type const col = cellColumn(cell); idx_type const row = cellRow(cell); for (idx_type i = 0; i < number; ++i) unsetMultiRow(cellIndex(row, col + i)); + // unsetting of multirow may have invalidated cell index + cell = cellIndex(row, col); CellData & cs = cellInfo(cell); cs.multicolumn = CELL_BEGIN_OF_MULTICOLUMN; - cs.alignment = column_info[cellColumn(cell)].alignment; - setRightLine(cell, rightLine(cell + number - 1)); + cs.alignment = column_info[col].alignment; + if (col > 0) + setRightLine(cell, rightLine(cellIndex(row, col - 1))); for (idx_type i = 1; i < number; ++i) { CellData & cs1 = cellInfo(cell + i); @@ -1523,6 +1526,7 @@ void Tabular::setMultiColumn(idx_type cell, idx_type number) cs1.inset->clear(); } updateIndexes(); + return cell; } @@ -1533,13 +1537,15 @@ bool Tabular::isMultiRow(idx_type cell) const } -void Tabular::setMultiRow(idx_type cell, idx_type number) +Tabular::idx_type Tabular::setMultiRow(idx_type cell, idx_type number) { idx_type const col = cellColumn(cell); idx_type const row = cellRow(cell); for (idx_type i = 0; i < number; ++i) unsetMultiColumn(cellIndex(row + i, col)); + // unsetting of multicol may have invalidated cell index + cell = cellIndex(row, col); CellData & cs = cellInfo(cell); cs.multirow = CELL_BEGIN_OF_MULTIROW; cs.valignment = LYX_VALIGN_MIDDLE; @@ -1554,6 +1560,7 @@ void Tabular::setMultiRow(idx_type cell, idx_type number) cs1.inset->clear(); } updateIndexes(); + return cell; } @@ -4958,8 +4965,7 @@ void InsetTabular::tabularFeatures(Cursor & cur, idx_type const s_start = cur.selBegin().idx(); row_type const col_start = tabular.cellColumn(s_start); row_type const col_end = tabular.cellColumn(cur.selEnd().idx()); - tabular.setMultiColumn(s_start, col_end - col_start + 1); - cur.idx() = s_start; + cur.idx() = tabular.setMultiColumn(s_start, col_end - col_start + 1); cur.pit() = 0; cur.pos() = 0; cur.setSelection(false); @@ -4981,8 +4987,7 @@ void InsetTabular::tabularFeatures(Cursor & cur, idx_type const s_start = cur.selBegin().idx(); row_type const row_start = tabular.cellRow(s_start); row_type const row_end = tabular.cellRow(cur.selEnd().idx()); - tabular.setMultiRow(s_start, row_end - row_start + 1); - cur.idx() = s_start; + cur.idx() = tabular.setMultiRow(s_start, row_end - row_start + 1); cur.pit() = 0; cur.pos() = 0; cur.setSelection(false); diff --git a/src/insets/InsetTabular.h b/src/insets/InsetTabular.h index 7605bff095..598242a0cf 100644 --- a/src/insets/InsetTabular.h +++ b/src/insets/InsetTabular.h @@ -379,7 +379,7 @@ public: /// bool isMultiColumn(idx_type cell) const; /// - void setMultiColumn(idx_type cell, idx_type number); + idx_type setMultiColumn(idx_type cell, idx_type number); /// void unsetMultiColumn(idx_type cell); /// @@ -389,7 +389,7 @@ public: /// bool isMultiRow(idx_type cell) const; /// - void setMultiRow(idx_type cell, idx_type number); + idx_type setMultiRow(idx_type cell, idx_type number); /// void unsetMultiRow(idx_type cell); ///