summaryrefslogtreecommitdiffstats
path: root/src/gui/text
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/text')
-rw-r--r--src/gui/text/qtexttable.cpp26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/gui/text/qtexttable.cpp b/src/gui/text/qtexttable.cpp
index 64b28811e5..cfbf426ab4 100644
--- a/src/gui/text/qtexttable.cpp
+++ b/src/gui/text/qtexttable.cpp
@@ -757,10 +757,30 @@ void QTextTable::insertColumns(int pos, int num)
QList<int> extendedSpans;
for (int i = 0; i < d->nRows; ++i) {
int cell;
- if (i == d->nRows - 1 && pos == d->nCols)
+ if (i == d->nRows - 1 && pos == d->nCols) {
cell = d->fragment_end;
- else
- cell = d->grid[i*d->nCols + pos];
+ } else {
+ int logicalGridIndexBeforePosition = pos > 0
+ ? d->findCellIndex(d->grid[i*d->nCols + pos - 1])
+ : -1;
+
+ // Search for the logical insertion point by skipping past cells which are not the first
+ // cell in a rowspan. This means any cell for which the logical grid index is
+ // less than the logical cell index of the cell before the insertion.
+ int logicalGridIndex;
+ int gridArrayOffset = i*d->nCols + pos;
+ do {
+ cell = d->grid[gridArrayOffset];
+ logicalGridIndex = d->findCellIndex(cell);
+ gridArrayOffset++;
+ } while (logicalGridIndex < logicalGridIndexBeforePosition
+ && gridArrayOffset < d->nRows*d->nCols);
+
+ if (logicalGridIndex < logicalGridIndexBeforePosition
+ && gridArrayOffset == d->nRows*d->nCols)
+ cell = d->fragment_end;
+ }
+
if (pos > 0 && pos < d->nCols && cell == d->grid[i*d->nCols + pos - 1]) {
// cell spans the insertion place, extend it
if (!extendedSpans.contains(cell)) {