jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/362229 )
Change subject: ui.FormatAction: fixup selection for empty conversions
......................................................................
ui.FormatAction: fixup selection for empty conversions
Converting an empty node needs a small selection fixup afterwards, otherwise
the selection will be displayed outside the new empty node. This causes issues
with the display of the current format in the toolbar, and with hitting enter
if no content is entered. Don't always reapply the selection, because the
automatic behavior is better if isolateAndUnwrap has actually acted.
Bug: T151594
Change-Id: Ibf143e7954919d0d9efacd53205d5451461a3115
---
M src/ui/actions/ve.ui.FormatAction.js
M tests/ui/actions/ve.ui.FormatAction.test.js
2 files changed, 24 insertions(+), 1 deletion(-)
Approvals:
Bartosz Dziewoński: Looks good to me, approved
jenkins-bot: Verified
Jforrester: Looks good to me, but someone else must approve
diff --git a/src/ui/actions/ve.ui.FormatAction.js
b/src/ui/actions/ve.ui.FormatAction.js
index eb4fdce..a808e6d 100644
--- a/src/ui/actions/ve.ui.FormatAction.js
+++ b/src/ui/actions/ve.ui.FormatAction.js
@@ -51,9 +51,10 @@
var selected, i, length, contentBranch,
surfaceModel = this.surface.getModel(),
fragment = surfaceModel.getFragment(),
+ fragmentSelection = fragment.getSelection(),
fragments = [];
- if ( !( fragment.getSelection() instanceof ve.dm.LinearSelection ) ) {
+ if ( !( fragmentSelection instanceof ve.dm.LinearSelection ) ) {
return;
}
@@ -73,6 +74,15 @@
}
fragment.convertNodes( type, attributes );
+ if ( fragmentSelection.isCollapsed() ) {
+ // Converting an empty node needs a small selection fixup
afterwards,
+ // otherwise the selection will be displayed outside the new
empty
+ // node. This causes issues with the display of the current
format in
+ // the toolbar, and with hitting enter if no content is
entered. Don't
+ // always reapply the selection, because the automatic behavior
is
+ // better if isolateAndUnwrap has actually acted. (T151594)
+ surfaceModel.setSelection( fragmentSelection );
+ }
this.surface.getView().focus();
return true;
};
diff --git a/tests/ui/actions/ve.ui.FormatAction.test.js
b/tests/ui/actions/ve.ui.FormatAction.test.js
index 359fccc..9472d01 100644
--- a/tests/ui/actions/ve.ui.FormatAction.test.js
+++ b/tests/ui/actions/ve.ui.FormatAction.test.js
@@ -96,6 +96,19 @@
},
undo: true,
msg: 'converting preformatted in list item to
paragraph'
+ },
+ {
+ html: '<p>a</p><p></p>',
+ rangeOrSelection: new ve.Range( 4, 4 ),
+ type: 'heading',
+ attributes: { level: 2 },
+ expectedRangeOrSelection: new ve.Range( 4, 4 ),
+ expectedData: function ( data ) {
+ data.splice( 3, 1, { type: 'heading',
attributes: { level: 2 } } );
+ data.splice( 4, 1, { type: '/heading' }
);
+ },
+ undo: true,
+ msg: 'converting empty paragraph to heading'
}
];
--
To view, visit https://gerrit.wikimedia.org/r/362229
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ibf143e7954919d0d9efacd53205d5451461a3115
Gerrit-PatchSet: 3
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: DLynch <[email protected]>
Gerrit-Reviewer: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: DLynch <[email protected]>
Gerrit-Reviewer: Esanders <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits