Esanders has uploaded a new change for review.
https://gerrit.wikimedia.org/r/167631
Change subject: Merge cells tool
......................................................................
Merge cells tool
Change-Id: If0ee115468c13412c52e5dba122105cdaca28e3e
---
M i18n/en.json
M i18n/qqq.json
M src/ui/actions/ve.ui.TableAction.js
A src/ui/styles/images/icons/table-merge-cells.svg
M src/ui/styles/ve.ui.Icons.css
M src/ui/tools/ve.ui.TableTool.js
M src/ui/ve.ui.CommandRegistry.js
7 files changed, 85 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor
refs/changes/31/167631/1
diff --git a/i18n/en.json b/i18n/en.json
index 8e1e609..3c96705 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -103,6 +103,7 @@
"visualeditor-table-insert-row-after": "Insert below",
"visualeditor-table-insert-row-before": "Insert above",
"visualeditor-table-insert-table": "Table",
+ "visualeditor-table-merge-cells": "Merge cells",
"visualeditor-toolbar-format-tooltip": "Format paragraph",
"visualeditor-toolbar-history": "History",
"visualeditor-toolbar-insert": "Insert",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 22b1569..f0c9bb0 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -108,6 +108,7 @@
"visualeditor-table-insert-row-after": "Label for insert row below tool",
"visualeditor-table-insert-row-before": "Label for insert row above tool",
"visualeditor-table-insert-table": "Label for table insertion menu in the
toolbar, for inserting parts of a table",
+ "visualeditor-table-merge-cells": "Label for merge cells tool",
"visualeditor-toolbar-format-tooltip": "Tooltip text for the paragraph
formatting menu which contains the following items:\n*
{{msg-mw|Visualeditor-formatdropdown-format-paragraph}}\n*
{{msg-mw|Visualeditor-formatdropdown-format-mw-heading1}}\n*
{{msg-mw|Visualeditor-formatdropdown-format-mw-heading2}}\n*
{{msg-mw|Visualeditor-formatdropdown-format-mw-heading3}}\n*
{{msg-mw|Visualeditor-formatdropdown-format-mw-heading4}}\n*
{{msg-mw|Visualeditor-formatdropdown-format-mw-heading5}}\n*
{{msg-mw|Visualeditor-formatdropdown-format-mw-heading6}}\n*
{{msg-mw|Visualeditor-formatdropdown-format-preformatted}}",
"visualeditor-toolbar-history": "Label text for the 'history' menu in
the toolbar of the undo and redo tools.\n\nSee also:\n*
{{msg-mw|visualeditor-toolbar-insert}}\n*
{{msg-mw|visualeditor-toolbar-paragraph-format}}\n*
{{msg-mw|visualeditor-toolbar-structure}}\n*
{{msg-mw|visualeditor-toolbar-text-style}}\n{{Identical|History}}",
"visualeditor-toolbar-insert": "Label text for the 'insert' menu in the
toolbar of tools that let you add items, like images.\n\nSee also:\n*
{{msg-mw|visualeditor-toolbar-history}}\n*
{{msg-mw|visualeditor-toolbar-paragraph-format}}\n*
{{msg-mw|visualeditor-toolbar-structure}}\n*
{{msg-mw|visualeditor-toolbar-text-style}}\n{{Identical|Insert}}",
diff --git a/src/ui/actions/ve.ui.TableAction.js
b/src/ui/actions/ve.ui.TableAction.js
index 17791ee..9c1f658 100644
--- a/src/ui/actions/ve.ui.TableAction.js
+++ b/src/ui/actions/ve.ui.TableAction.js
@@ -32,7 +32,7 @@
* @static
* @property
*/
-ve.ui.TableAction.static.methods = [ 'create', 'insert', 'delete',
'toggleCellHeader' ];
+ve.ui.TableAction.static.methods = [ 'create', 'insert', 'delete',
'toggleCellHeader', 'mergeCells' ];
/* Methods */
@@ -178,6 +178,56 @@
surfaceModel.change( txs );
};
+/**
+ * Merge multiple cells into one, or split a merged cell.
+ */
+ve.ui.TableAction.prototype.mergeCells = function () {
+ var i, cells,
+ txs = [],
+ surfaceModel = this.surface.getModel(),
+ selection = surfaceModel.getSelection();
+
+ if ( !( selection instanceof ve.dm.TableSelection ) ) {
+ return;
+ }
+
+ if ( selection.isSingleCell() ) {
+ // Split
+ cells = selection.getMatrixCells( true );
+ txs.push(
+ ve.dm.Transaction.newFromAttributeChanges(
+ surfaceModel.getDocument(),
cells[0].node.getOuterRange().start,
+ { colspan: 1, rowspan: 1 }
+ )
+ );
+ for ( i = cells.length - 1; i >= 1; i-- ) {
+ txs.push(
+ this.replacePlaceholder(
selection.getTableNode().getMatrix(), cells[i] )
+ );
+ }
+ } else {
+ // Merge
+ cells = selection.getMatrixCells();
+ txs.push(
+ ve.dm.Transaction.newFromAttributeChanges(
+ surfaceModel.getDocument(),
cells[0].node.getOuterRange().start,
+ {
+ colspan: 1 + selection.endCol -
selection.startCol,
+ rowspan: 1 + selection.endRow -
selection.startRow
+ }
+ )
+ );
+ for ( i = cells.length - 1; i >= 1; i-- ) {
+ txs.push(
+ ve.dm.Transaction.newFromRemoval(
+ surfaceModel.getDocument(),
cells[i].node.getOuterRange()
+ )
+ );
+ }
+ }
+ surfaceModel.change( txs );
+};
+
/* Low-level API */
// TODO: This API does only depends on the model so it should possibly be moved
diff --git a/src/ui/styles/images/icons/table-merge-cells.svg
b/src/ui/styles/images/icons/table-merge-cells.svg
new file mode 100644
index 0000000..6a208c7
--- /dev/null
+++ b/src/ui/styles/images/icons/table-merge-cells.svg
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24
24">
+ <g id="table-merge-cells">
+ <g id="merge-cell-left">
+ <path id="cell-border" d="m 4,7 0,9 7,0 0,-3 -1,0.834 L 10,15 5,15 5,8
10,8 10,9.167 11,10 11,7 z" />
+ <path id="arrow" d="m 8,9 0,2 -2,0 0,1 2,0 0,2 3,-2.5 z" />
+ </g>
+ <use id="merge-cell-right" xlink:href="#merge-cell-left"
transform="matrix(-1,0,0,1,24,0)" />
+ </g>
+</svg>
diff --git a/src/ui/styles/ve.ui.Icons.css b/src/ui/styles/ve.ui.Icons.css
index 398cdde..ae903e2 100644
--- a/src/ui/styles/ve.ui.Icons.css
+++ b/src/ui/styles/ve.ui.Icons.css
@@ -295,3 +295,8 @@
background-image: /* @embed */
url(images/icons/table-insert-column-after.svg);
background-position: center;
}
+
+.oo-ui-icon-table-merge-cells {
+ background-image: /* @embed */ url(images/icons/table-merge-cells.svg);
+ background-position: center;
+}
diff --git a/src/ui/tools/ve.ui.TableTool.js b/src/ui/tools/ve.ui.TableTool.js
index c384d27..c44c0b7 100644
--- a/src/ui/tools/ve.ui.TableTool.js
+++ b/src/ui/tools/ve.ui.TableTool.js
@@ -115,3 +115,17 @@
ve.ui.DeleteColumnTool.static.commandName = 'deleteColumn';
ve.ui.DeleteColumnTool.static.requiresSelection = [ 'table' ];
ve.ui.toolFactory.register( ve.ui.DeleteColumnTool );
+
+ve.ui.MergeCellsTool = function VeUiDeleteColumnTool( toolGroup, config ) {
+ ve.ui.Tool.call( this, toolGroup, config );
+};
+OO.inheritClass( ve.ui.MergeCellsTool, ve.ui.Tool );
+ve.ui.MergeCellsTool.static.name = 'mergeCells';
+ve.ui.MergeCellsTool.static.group = 'table';
+ve.ui.MergeCellsTool.static.autoAddToCatchall = false;
+ve.ui.MergeCellsTool.static.icon = 'table-merge-cells';
+ve.ui.MergeCellsTool.static.title =
+ OO.ui.deferMsg( 'visualeditor-table-merge-cells' );
+ve.ui.MergeCellsTool.static.commandName = 'mergeCells';
+ve.ui.MergeCellsTool.static.requiresSelection = [ 'table' ];
+ve.ui.toolFactory.register( ve.ui.MergeCellsTool );
diff --git a/src/ui/ve.ui.CommandRegistry.js b/src/ui/ve.ui.CommandRegistry.js
index 916721c..94b59b0 100644
--- a/src/ui/ve.ui.CommandRegistry.js
+++ b/src/ui/ve.ui.CommandRegistry.js
@@ -177,3 +177,6 @@
ve.ui.commandRegistry.register(
new ve.ui.Command( 'toggleCellHeader', 'table', 'toggleCellHeader' )
);
+ve.ui.commandRegistry.register(
+ new ve.ui.Command( 'mergeCells', 'table', 'mergeCells' )
+);
--
To view, visit https://gerrit.wikimedia.org/r/167631
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If0ee115468c13412c52e5dba122105cdaca28e3e
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