Esanders has uploaded a new change for review.
https://gerrit.wikimedia.org/r/99419
Change subject: Prevent content selections ending up inside handlesOwnChildren
nodes
......................................................................
Prevent content selections ending up inside handlesOwnChildren nodes
The delete logic sees the caption inside the image as a valid place to
put a cursor and therefore a valid range to delete up to. This means
paragraphs can be merged into image captions by backspacing them in.
Add in a flag that keeps track of whether we are in a handlesOwnChildren
node so we can skip over them.
Bug: 57927
Change-Id: I19e91d2d3a871806d207cbd419f4a45e41d69dc0
---
M modules/ve-mw/test/ce/ve.ce.Surface.test.js
M modules/ve/dm/lineardata/ve.dm.ElementLinearData.js
2 files changed, 34 insertions(+), 5 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor
refs/changes/19/99419/1
diff --git a/modules/ve-mw/test/ce/ve.ce.Surface.test.js
b/modules/ve-mw/test/ce/ve.ce.Surface.test.js
index 58dd4e8..6570e49 100644
--- a/modules/ve-mw/test/ce/ve.ce.Surface.test.js
+++ b/modules/ve-mw/test/ce/ve.ce.Surface.test.js
@@ -46,6 +46,17 @@
'expectedData': function () { },
'expectedRange': new ve.Range( 5, 14 ),
'msg': 'Block image is focused not deleted'
+ },
+ {
+ 'html':
+ ve.dm.mwExample.MWBlockImage.html +
+
'<ul><li><p>Foo</p></li><li><p>Bar</p></li></ul>',
+ 'range': new ve.Range( 12 ),
+ 'operations': ['backspace'],
+ // TODO: This action should probably unwrap the
list item as
+ 'expectedData': function () {},
+ 'expectedRange': new ve.Range( 12 ),
+ 'msg': 'Backspace in a list next to a block
image doesn\'t merge into the caption'
}
];
diff --git a/modules/ve/dm/lineardata/ve.dm.ElementLinearData.js
b/modules/ve/dm/lineardata/ve.dm.ElementLinearData.js
index 846c3e8..4d5c68b 100644
--- a/modules/ve/dm/lineardata/ve.dm.ElementLinearData.js
+++ b/modules/ve/dm/lineardata/ve.dm.ElementLinearData.js
@@ -509,10 +509,12 @@
*/
ve.dm.ElementLinearData.prototype.getRelativeOffset = function ( offset,
distance, callback ) {
var i, direction,
+ dataOffset,
args = Array.prototype.slice.call( arguments, 3 ),
start = offset,
steps = 0,
- turnedAround = false;
+ turnedAround = false,
+ inHandlesOwnChildren = false;
// If offset is already a structural offset and distance is zero than
no further work is needed,
// otherwise distance should be 1 so that we can get out of the invalid
starting offset
if ( distance === 0 ) {
@@ -535,11 +537,26 @@
offset = -1;
// Iteration
while ( i >= 0 && i <= this.getLength() ) {
+ // Detect when the search for a valid offset enters a node
which handles its own
+ // children, and don't return an offset inside such a node.
This clearly won't work
+ // if you start inside such a node, but you shouldn't be doing
that to being with
+ dataOffset = i + ( direction > 0 ? -1 : 0 );
+ if (
+ this.isElementData( dataOffset ) &&
+ ve.dm.nodeFactory.doesNodeHandleOwnChildren(
this.getType( dataOffset ) )
+ ) {
+ // We have entered a node if we step right over an
open, or left over a close
+ inHandlesOwnChildren =
+ ( direction > 0 && this.isOpenElementData(
dataOffset ) ) ||
+ ( direction < 0 && this.isCloseElementData(
dataOffset ) );
+ }
if ( callback.apply( this, [i].concat( args ) ) ) {
- steps++;
- offset = i;
- if ( distance === steps ) {
- return offset;
+ if ( !inHandlesOwnChildren ) {
+ steps++;
+ offset = i;
+ if ( distance === steps ) {
+ return offset;
+ }
}
} else if (
// Don't keep turning around over and over
@@ -559,6 +576,7 @@
i = start;
distance = 1;
turnedAround = true;
+ inHandlesOwnChildren = false;
}
i += direction;
}
--
To view, visit https://gerrit.wikimedia.org/r/99419
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I19e91d2d3a871806d207cbd419f4a45e41d69dc0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits