Divec has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/187889

Change subject: WIP POC: fixup Chromium cursoring
......................................................................

WIP POC: fixup Chromium cursoring

Chromium has extraneous cursoring positions around ce=false images (see
https://code.google.com/p/chromium/issues/detail?id=440877 ); this code is a
fixup that works in certain cases. Note that some other cases are not
practical to fixup, because the cursor does not move at all, and BIDI and
grapheme clustering considerations make it hard to determine in Javascript
where the cursor should have gone.

TODO:
- Decide whether this solves enough trouble to be worth the complexity
- Make this actually work
- Clean up the aesthetically horrible code

Change-Id: Ibca5bf9cc3d227615aa60f6fc627db2b85a6a9e7
---
M src/ce/ve.ce.Surface.js
1 file changed, 51 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor 
refs/changes/89/187889/1

diff --git a/src/ce/ve.ce.Surface.js b/src/ce/ve.ce.Surface.js
index 14b412e..4d1195a 100644
--- a/src/ce/ve.ce.Surface.js
+++ b/src/ce/ve.ce.Surface.js
@@ -1237,8 +1237,8 @@
  * @param {jQuery.Event} e keydown event
  */
 ve.ce.Surface.prototype.afterDocumentKeyDown = function ( e ) {
-       var isArrow, direction, focusableNode, startOffset, endOffset, 
offsetDiff,
-               range, fixupCursorForUnicorn;
+       var isArrow, direction, focusableNode, startOffset, endOffset, 
offsetDiff, veRange,
+               fixupCursorForUnicorn, prevOffset, nextOffset, approachNode, 
domRange;
 
        /**
         * Determine whether a position is editable, and if so which focusable 
node it is in
@@ -1314,6 +1314,49 @@
                        )
                ) || null;
        }
+
+       // If we arrowed up to a focusable node, but the browser erroneously 
did not cross it,
+       // select across it up to the following cursor position.
+       // TODO: This code is aesthetically if-y to say the least
+       if (
+               e.shiftKey &&
+               this.nativeSelection.focusNode &&
+               this.nativeSelection.focusNode.nodeType === Node.ELEMENT_NODE &&
+               ( direction = direction || getDirection( this ) ) &&
+               ( approachNode = this.nativeSelection.focusNode[
+                       this.nativeSelection.focusOffset - ( direction > 0 ? 0 
: 1 )
+               ] ) &&
+               approachNode.nodeType === Node.ELEMENT_NODE &&
+               ( prevOffset = ve.ce.previousCursorOffset( approachNode ) ) &&
+               prevOffset.node.nodeType === Node.TextNode &&
+               ( nextOffset = ve.ce.nextCursorOffset( approachNode ) ) &&
+               nextOffset.node.nodeType === Node.TextNode && (
+                       (
+                               direction > 0 &&
+                               this.misleadingCursorStartSelection.focusNode 
=== prevOffset.node &&
+                               this.misleadingCursorStartSelection.focusOffset 
=== prevOffset.offset
+                       ) ||
+                       (
+                               direction < 0 &&
+                               this.misleadingCursorStartSelection.focusNode 
=== nextOffset.node &&
+                               this.misleadingCursorStartSelection.focusOffset 
=== nextOffset.offset
+                       )
+               ) &&
+               ( focusableNode = approachNode.data( 'view' ) ) &&
+               focusableNode.isFocusable()
+       ) {
+               domRange = this.nativeSelection.getRangeAt( 0 );
+               if ( direction > 0 ) {
+                       domRange.focusNode = nextOffset.node;
+                       domRange.focusOffset = nextOffset.focusOffset;
+               } else {
+                       domRange.focusNode = prevOffset.node;
+                       domRange.focusOffset = prevOffset.focusOffset;
+               }
+               this.nativeSelection.removeAllRanges();
+               this.nativeSelection.addRange( domRange );
+       }
+
        // If we arrowed a collapsed cursor across a focusable node, select the 
node instead
        if (
                isArrow &&
@@ -1322,7 +1365,7 @@
                !e.metaKey &&
                this.misleadingCursorStartSelection.isCollapsed &&
                this.nativeSelection.isCollapsed &&
-               ( direction = getDirection( this ) )
+               ( direction = direction || getDirection( this ) )
        ) {
                focusableNode = getSurroundingFocusableNode(
                        this.nativeSelection.focusNode,
@@ -1355,7 +1398,7 @@
                                );
 
                                if ( focusableNode.isFocusable() ) {
-                                       range = new ve.Range( startOffset, 
endOffset );
+                                       veRange = new ve.Range( startOffset, 
endOffset );
                                } else {
                                        focusableNode = undefined;
                                }
@@ -1363,13 +1406,13 @@
                }
 
                if ( focusableNode ) {
-                       if ( !range ) {
-                               range = focusableNode.getOuterRange();
+                       if ( !veRange ) {
+                               veRange = focusableNode.getOuterRange();
                                if ( direction < 0 ) {
-                                       range = range.flip();
+                                       veRange = veRange.flip();
                                }
                        }
-                       this.model.setLinearSelection( range );
+                       this.model.setLinearSelection( veRange );
                        if ( e.keyCode === OO.ui.Keys.LEFT ) {
                                this.cursorDirectionality = direction > 0 ? 
'rtl' : 'ltr';
                        } else if ( e.keyCode === OO.ui.Keys.RIGHT ) {

-- 
To view, visit https://gerrit.wikimedia.org/r/187889
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibca5bf9cc3d227615aa60f6fc627db2b85a6a9e7
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Divec <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to