jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/381805 )
Change subject: ce.Surface: handle table-adjacent observed selection changes
better
......................................................................
ce.Surface: handle table-adjacent observed selection changes better
Moving to the closest cursorable location produces better results, and means
clicking to the left of a table no longer vanishes the cursor.
There's a remaining bug when a table is the very first node in a document, and
you click to the left of it *twice*, which deselects the block slug and places
the cursor in an invalid position. This needs more changes to various
optimizations selection-changes try to make to avoid, however.
Bug: T148679
Bug: T176936
Change-Id: I8a3dde56d52342316c00a909ac9369b2a9f6b409
---
M src/ce/ve.ce.Surface.js
M src/dm/ve.dm.Document.js
2 files changed, 23 insertions(+), 9 deletions(-)
Approvals:
Esanders: Looks good to me, approved
jenkins-bot: Verified
Jforrester: Looks good to me, but someone else must approve
diff --git a/src/ce/ve.ce.Surface.js b/src/ce/ve.ce.Surface.js
index 63c056f..d93b3a2 100644
--- a/src/ce/ve.ce.Surface.js
+++ b/src/ce/ve.ce.Surface.js
@@ -2808,13 +2808,21 @@
) ) {
if ( newState.veRange ) {
if ( newState.veRange.isCollapsed() ) {
- // If we're placing the cursor, make sure it
winds up in a
- // cursorable location. Failure to do this can
result in
- // strange behavior when inserting content
immediately after
- // clicking on the surface.
- newSelection = new ve.dm.LinearSelection(
dmDoc, new ve.Range(
- dmDoc.getNearestCursorOffset(
newState.veRange.from, 1 )
- ) );
+ if ( dmDoc.data.getNearestContentOffset(
newState.veRange.from ) === -1 ) {
+ // First, if we're in a document which
outright doesn't
+ // have any content to select, don't
try to set one. These
+ // would be niche documents, since
slugs normally exist
+ // and catch those cases.
+ newSelection = new ve.dm.NullSelection(
dmDoc );
+ } else {
+ newSelection = new
ve.dm.LinearSelection( dmDoc, new ve.Range(
+ // If we're placing the cursor,
make sure it winds up in a
+ // cursorable location. Failure
to do this can result in
+ // strange behavior when
inserting content immediately after
+ // clicking on the surface.
+ dmDoc.getNearestCursorOffset(
newState.veRange.from, 0 )
+ ) );
+ }
} else {
newSelection = new ve.dm.LinearSelection(
dmDoc, newState.veRange );
}
diff --git a/src/dm/ve.dm.Document.js b/src/dm/ve.dm.Document.js
index 6087c9b..a75b1aa 100644
--- a/src/dm/ve.dm.Document.js
+++ b/src/dm/ve.dm.Document.js
@@ -920,11 +920,17 @@
*
* @method
* @param {number} offset Offset to start looking at
- * @param {number} [direction=-1] Direction to look in, +1 or -1
+ * @param {number} [direction=-1] Direction to look in, +1 or -1; if 0, find
the closest offset
* @return {number} Nearest offset a cursor can be placed at
*/
ve.dm.Document.prototype.getNearestCursorOffset = function ( offset, direction
) {
- var contentOffset, structuralOffset;
+ var contentOffset, structuralOffset, left, right;
+
+ if ( direction === 0 ) {
+ left = this.getNearestCursorOffset( offset, -1 );
+ right = this.getNearestCursorOffset( offset, 1 );
+ return offset - left < right - offset ? left : right;
+ }
direction = direction > 0 ? 1 : -1;
if (
--
To view, visit https://gerrit.wikimedia.org/r/381805
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I8a3dde56d52342316c00a909ac9369b2a9f6b409
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: Divec <[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