corinthia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject [26/31] incubator-corinthia git commit: Fix selection hit test after footnotes/endnotes
Date Mon, 23 Feb 2015 11:39:29 GMT
Fix selection hit test after footnotes/endnotes

Hit testing in Position_atPoint is a bit more complicated when we have
selection spans in the tree. When looking for "special" nodes like empty
footnotes or endnotes, we have to take into account the possibility that
they might be contained within a selection span. Additionally, we also
have to consider that the result of document.caretRangeFromPoint might
also be inside a selection span, in which case the previous/next nodes
we want to look at are that of the span, not the node inside it.

The newly-added posOutsideSelection function checks a given position to
see if it's at the very beginning or end of a selection span. If so, it
returns a position that is directly before or after the span. Otherwise,
if the position is part-way through the span (e.g. within a text node),
the original position is returned.

We call this function with the result of document.caretRangeFromPoint,
but *only* for the purposes of checking the previous and next nodes to
see if they are images or empty footnotes/endnotes. We do *not* use it
for other purposes, as doing so results in an odd flickering effect
where consecutive touch movements result in the selection end boundary
alternately jumping before and after the character that is touched.


Project: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/commit/c2ab40b2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/tree/c2ab40b2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/diff/c2ab40b2

Branch: refs/heads/experimentzip
Commit: c2ab40b29c372418fc9fa42b9018d9168864449c
Parents: 9262c46
Author: Peter Kelly <peter@uxproductivity.com>
Authored: Wed Feb 18 19:21:44 2015 +0700
Committer: Peter Kelly <peter@uxproductivity.com>
Committed: Wed Feb 18 16:47:38 2015 +0700

----------------------------------------------------------------------
 Editor/src/Position.js | 39 +++++++++++++++++++++++++++++++++------
 1 file changed, 33 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/c2ab40b2/Editor/src/Position.js
----------------------------------------------------------------------
diff --git a/Editor/src/Position.js b/Editor/src/Position.js
index 9eb03f3..e767a46 100644
--- a/Editor/src/Position.js
+++ b/Editor/src/Position.js
@@ -935,6 +935,21 @@ var Position_atPoint;
     // intended if the document's last text node is a direct child of the body (as it may
be in some
     // HTML documents that users open).
 
+    function posOutsideSelection(pos)
+    {
+        pos = Position_preferElementPosition(pos);
+
+        if (!isSelectionSpan(pos.node))
+            return pos;
+
+        if (pos.offset == 0)
+            return new Position(pos.node.parentNode,DOM_nodeOffset(pos.node));
+        else if (pos.offset == pos.node.childNodes.length)
+            return new Position(pos.node.parentNode,DOM_nodeOffset(pos.node)+1);
+        else
+            return pos;
+    }
+
     Position_atPoint = function(x,y)
     {
         // In general, we can use document.caretRangeFromPoint(x,y) to determine the location
of the
@@ -966,8 +981,9 @@ var Position_atPoint;
         pos = Position_preferElementPosition(pos);
 
         if (pos.node.nodeType == Node.ELEMENT_NODE) {
-            var prev = pos.node.childNodes[pos.offset-1];
-            var next = pos.node.childNodes[pos.offset];
+            var outside = posOutsideSelection(pos);
+            var prev = outside.node.childNodes[outside.offset-1];
+            var next = outside.node.childNodes[outside.offset];
 
             if ((prev != null) && nodeMayContainPos(prev) && elementContainsPoint(prev,x,y))
                 return new Position(prev,0);
@@ -975,10 +991,21 @@ var Position_atPoint;
             if ((next != null) && nodeMayContainPos(next) && elementContainsPoint(next,x,y))
                 return new Position(next,0);
 
-            if ((next != null) && isEmptyNoteNode(next)) {
-                var rect = next.getBoundingClientRect();
-                if (x > rect.right)
-                    return new Position(pos.node,pos.offset+1);
+            if (next != null) {
+                var nextNode = outside.node;
+                var nextOffset = outside.offset+1;
+
+                if (isSelectionSpan(next) && (next.firstChild != null)) {
+                    nextNode = next;
+                    nextOffset = 1;
+                    next = next.firstChild;
+                }
+
+                if ((next != null) && isEmptyNoteNode(next)) {
+                    var rect = next.getBoundingClientRect();
+                    if (x > rect.right)
+                        return new Position(nextNode,nextOffset);
+                }
             }
         }
 


Mime
View raw message