Inez has uploaded a new change for review.
https://gerrit.wikimedia.org/r/71353
Change subject: (bug 47947) Allow creating lists while selection is collapsed
and in block slug
......................................................................
(bug 47947) Allow creating lists while selection is collapsed and in block slug
Change-Id: I596ea9bc553f563e3dc7689c518c7d1319ac1dc3
---
M modules/ve/ui/actions/ve.ui.ListAction.js
1 file changed, 59 insertions(+), 33 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor
refs/changes/53/71353/1
diff --git a/modules/ve/ui/actions/ve.ui.ListAction.js
b/modules/ve/ui/actions/ve.ui.ListAction.js
index 38b26d9..7db95fa 100644
--- a/modules/ve/ui/actions/ve.ui.ListAction.js
+++ b/modules/ve/ui/actions/ve.ui.ListAction.js
@@ -47,46 +47,72 @@
surfaceModel = this.surface.getModel(),
documentModel = surfaceModel.getDocument(),
selection = surfaceModel.getSelection(),
- groups = documentModel.getCoveredSiblingGroups( selection );
+ groups;
surfaceModel.breakpoint();
- for ( i = 0; i < groups.length; i++ ) {
- group = groups[i];
- if ( group.grandparent && group.grandparent.getType() ===
'list' ) {
- if ( group.grandparent !== previousList ) {
- // Change the list style
+
+ // TODO: Would be good to refactor at some point and avoid/abstract
path split for block slug
+ // and not block slug.
+
+ if (
+ selection.isCollapsed() &&
+ !documentModel.data.isContentOffset( selection.to ) &&
+ !!this.surface.view.documentView.getSlugAtOffset( selection.to )
+ ) {
+ // Inside block level slug
+ surfaceModel.change( ve.dm.Transaction.newFromInsertion(
+ documentModel,
+ selection.from,
+ [
+ { 'type': 'list', 'attributes': { 'style':
style } },
+ { 'type': 'listItem' },
+ { 'type': 'paragraph' },
+ { 'type': '/paragraph' },
+ { 'type': '/listItem' },
+ { 'type': '/list' }
+
+ ]
+ ), new ve.Range( selection.to + 3 ) );
+ } else {
+ groups = documentModel.getCoveredSiblingGroups( selection );
+ for ( i = 0; i < groups.length; i++ ) {
+ group = groups[i];
+ if ( group.grandparent && group.grandparent.getType()
=== 'list' ) {
+ if ( group.grandparent !== previousList ) {
+ // Change the list style
+ surfaceModel.change(
+
ve.dm.Transaction.newFromAttributeChanges(
+ documentModel,
group.grandparent.getOffset(), { 'style': style }
+ ),
+ selection
+ );
+ // Skip this one next time
+ previousList = group.grandparent;
+ }
+ } else {
+ // Get a range that covers the whole group
+ groupRange = new ve.Range(
+ group.nodes[0].getOuterRange().start,
+ group.nodes[group.nodes.length -
1].getOuterRange().end
+ );
+ // Convert everything to paragraphs first
surfaceModel.change(
-
ve.dm.Transaction.newFromAttributeChanges(
- documentModel,
group.grandparent.getOffset(), { 'style': style }
+
ve.dm.Transaction.newFromContentBranchConversion(
+ documentModel, groupRange,
'paragraph'
),
selection
);
- // Skip this one next time
- previousList = group.grandparent;
+ // Wrap everything in a list and each content
branch in a listItem
+ tx = ve.dm.Transaction.newFromWrap(
+ documentModel,
+ groupRange,
+ [],
+ [{ 'type': 'list', 'attributes': {
'style': style } }],
+ [],
+ [{ 'type': 'listItem' }]
+ );
+ surfaceModel.change( tx, tx.translateRange(
selection ) );
}
- } else {
- // Get a range that covers the whole group
- groupRange = new ve.Range(
- group.nodes[0].getOuterRange().start,
- group.nodes[group.nodes.length -
1].getOuterRange().end
- );
- // Convert everything to paragraphs first
- surfaceModel.change(
-
ve.dm.Transaction.newFromContentBranchConversion(
- documentModel, groupRange, 'paragraph'
- ),
- selection
- );
- // Wrap everything in a list and each content branch in
a listItem
- tx = ve.dm.Transaction.newFromWrap(
- documentModel,
- groupRange,
- [],
- [{ 'type': 'list', 'attributes': { 'style':
style } }],
- [],
- [{ 'type': 'listItem' }]
- );
- surfaceModel.change( tx, tx.translateRange( selection )
);
}
}
surfaceModel.breakpoint();
--
To view, visit https://gerrit.wikimedia.org/r/71353
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I596ea9bc553f563e3dc7689c518c7d1319ac1dc3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Inez <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits