Esanders has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/183510

Change subject: Remove redundant rows/cols after cell merge
......................................................................

Remove redundant rows/cols after cell merge

If two full rows are selected and merged into a single cell
then the second row consists entirely of placeholders and should
be discarded.

Bug: T86160
Change-Id: Ie77320441a110cf7e0e906bff3573da94cc92598
---
M src/ui/actions/ve.ui.TableAction.js
1 file changed, 34 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor 
refs/changes/10/183510/1

diff --git a/src/ui/actions/ve.ui.TableAction.js 
b/src/ui/actions/ve.ui.TableAction.js
index 5964d4c..e57a79c 100644
--- a/src/ui/actions/ve.ui.TableAction.js
+++ b/src/ui/actions/ve.ui.TableAction.js
@@ -190,10 +190,11 @@
  * @return {boolean} Action was executed
  */
 ve.ui.TableAction.prototype.mergeCells = function () {
-       var i, cells,
+       var i, r, c, cell, cells, hasNonPlaceholders,
                txs = [],
                surfaceModel = this.surface.getModel(),
-               selection = surfaceModel.getSelection();
+               selection = surfaceModel.getSelection(),
+               matrix = selection.getTableNode().getMatrix();
 
        if ( !( selection instanceof ve.dm.TableSelection ) ) {
                return false;
@@ -211,12 +212,13 @@
                for ( i = cells.length - 1; i >= 1; i-- ) {
                        txs.push(
                                this.replacePlaceholder(
-                                       selection.getTableNode().getMatrix(),
+                                       matrix,
                                        cells[i],
                                        { style: cells[0].node.getStyle() }
                                )
                        );
                }
+               surfaceModel.change( txs );
        } else {
                // Merge
                cells = selection.getMatrixCells();
@@ -236,8 +238,36 @@
                                )
                        );
                }
+               surfaceModel.change( txs );
+
+               // Check for rows filled with entirely placeholders. If such a 
row exists, delete it.
+               for ( r = selection.endRow; r >= selection.startRow; r-- ) {
+                       hasNonPlaceholders = false;
+                       for ( c = 0; ( cell = matrix.getCell( r, c ) ) !== 
undefined; c++ ) {
+                               if ( cell && !cell.isPlaceholder() ) {
+                                       hasNonPlaceholders = true;
+                                       break;
+                               }
+                       }
+                       if ( !hasNonPlaceholders ) {
+                               this.deleteRowsOrColumns( matrix, 'row', r, r );
+                       }
+               }
+
+               // Check for columns filled with entirely placeholders. If such 
a column exists, delete it.
+               for ( c = selection.endCol; c >= selection.startCol; c-- ) {
+                       hasNonPlaceholders = false;
+                       for ( r = 0; ( cell = matrix.getCell( r, c ) ) !== 
undefined; r++ ) {
+                               if ( cell && !cell.isPlaceholder() ) {
+                                       hasNonPlaceholders = true;
+                                       break;
+                               }
+                       }
+                       if ( !hasNonPlaceholders ) {
+                               this.deleteRowsOrColumns( matrix, 'col', c, c );
+                       }
+               }
        }
-       surfaceModel.change( txs );
        return true;
 };
 

-- 
To view, visit https://gerrit.wikimedia.org/r/183510
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie77320441a110cf7e0e906bff3573da94cc92598
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to