jenkins-bot has submitted this change and it was merged.
Change subject: Make caption tool available when caption selected
......................................................................
Make caption tool available when caption selected
Currently is only available on table selection. Add in node
traversal logic to check if linear selection is in a caption
so captions can be removed when the cursor is inside them.
Change-Id: Ib1d8ad574886ce83f1fee782367b2697ab696d2d
---
M src/ui/actions/ve.ui.TableAction.js
M src/ui/tools/ve.ui.TableTool.js
M src/ui/ve.ui.CommandRegistry.js
3 files changed, 43 insertions(+), 7 deletions(-)
Approvals:
Catrope: Looks good to me, approved
jenkins-bot: Verified
diff --git a/src/ui/actions/ve.ui.TableAction.js
b/src/ui/actions/ve.ui.TableAction.js
index 8e47a2d..35f4302 100644
--- a/src/ui/actions/ve.ui.TableAction.js
+++ b/src/ui/actions/ve.ui.TableAction.js
@@ -233,19 +233,42 @@
* Toggle the existence of a caption node on the table
*/
ve.ui.TableAction.prototype.caption = function () {
- var fragment, captionNode,
+ var fragment, captionNode, nodes, node, tableFragment,
surfaceModel = this.surface.getModel(),
selection = surfaceModel.getSelection();
- if ( !( selection instanceof ve.dm.TableSelection ) ) {
+ if ( selection instanceof ve.dm.TableSelection ) {
+ captionNode = selection.getTableNode().getCaptionNode();
+ } else if ( selection instanceof ve.dm.LinearSelection ) {
+ nodes = surfaceModel.getFragment().getSelectedLeafNodes();
+
+ node = nodes[0];
+ while ( node ) {
+ if ( node instanceof ve.dm.TableCaptionNode ) {
+ captionNode = node;
+ break;
+ }
+ node = node.getParent();
+ }
+ if ( !captionNode ) {
+ return;
+ }
+ tableFragment = surfaceModel.getFragment( new
ve.dm.TableSelection(
+ surfaceModel.getDocument(),
+ captionNode.getParent().getOuterRange(),
+ 0, 0, 0, 0,
+ true
+ ) );
+ } else {
return;
}
-
- captionNode = selection.getTableNode().getCaptionNode();
if ( captionNode ) {
fragment = surfaceModel.getLinearFragment(
captionNode.getOuterRange(), true );
fragment.removeContent();
+ if ( tableFragment ) {
+ tableFragment.select();
+ }
} else {
fragment = surfaceModel.getLinearFragment( new ve.Range(
selection.tableRange.start + 1 ), true );
diff --git a/src/ui/tools/ve.ui.TableTool.js b/src/ui/tools/ve.ui.TableTool.js
index 4d71f9b..daeb97a 100644
--- a/src/ui/tools/ve.ui.TableTool.js
+++ b/src/ui/tools/ve.ui.TableTool.js
@@ -157,10 +157,23 @@
// Parent method
ve.ui.TableCaptionTool.super.prototype.onUpdateState.apply( this,
arguments );
- var selection = fragment.getSelection();
+ var i, len, nodes, hasCaptionNode,
+ selection = fragment.getSelection();
if ( selection instanceof ve.dm.TableSelection ) {
- this.setActive( !!selection.getTableNode().getCaptionNode() );
+ hasCaptionNode = !!selection.getTableNode().getCaptionNode();
+ } else {
+ nodes = fragment.getSelectedLeafNodes();
+ hasCaptionNode = !!nodes.length;
+
+ for ( i = 0, len = nodes.length; i < len; i++ ) {
+ if ( !nodes[i].hasMatchingAncestor( 'tableCaption' ) ) {
+ hasCaptionNode = false;
+ break;
+ }
+ }
+ this.setDisabled( !hasCaptionNode );
}
+ this.setActive( hasCaptionNode );
};
ve.ui.toolFactory.register( ve.ui.TableCaptionTool );
diff --git a/src/ui/ve.ui.CommandRegistry.js b/src/ui/ve.ui.CommandRegistry.js
index 4d6398f..1cf895a 100644
--- a/src/ui/ve.ui.CommandRegistry.js
+++ b/src/ui/ve.ui.CommandRegistry.js
@@ -299,5 +299,5 @@
new ve.ui.Command( 'mergeCells', 'table', 'mergeCells', {
supportedSelections: ['table'] } )
);
ve.ui.commandRegistry.register(
- new ve.ui.Command( 'tableCaption', 'table', 'caption', {
supportedSelections: ['table'] } )
+ new ve.ui.Command( 'tableCaption', 'table', 'caption', {
supportedSelections: ['linear', 'table'] } )
);
--
To view, visit https://gerrit.wikimedia.org/r/172249
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib1d8ad574886ce83f1fee782367b2697ab696d2d
Gerrit-PatchSet: 3
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Esanders <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits