corinthia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmke...@apache.org
Subject incubator-corinthia git commit: getAdjacentNodeWithType: traverse up, not back
Date Fri, 06 Mar 2015 07:45:32 GMT
Repository: incubator-corinthia
Updated Branches:
  refs/heads/master aa2436c2d -> dd3e2374e


getAdjacentNodeWithType: traverse up, not back

In Cursor_getAdjacentNodeWithType, traverse the DOM tree upwards
starting from the current position, instead of backwards one position at
a time. This is slightly more efficient, and also ensures that we catch
elements of the requested type that appear either before or after the
current position.


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

Branch: refs/heads/master
Commit: dd3e2374e588cdbcc595838bf4874e2b98f98341
Parents: aa2436c
Author: Peter Kelly <peter@uxproductivity.com>
Authored: Fri Mar 6 14:45:07 2015 +0700
Committer: Peter Kelly <peter@uxproductivity.com>
Committed: Fri Mar 6 14:45:07 2015 +0700

----------------------------------------------------------------------
 Editor/src/Cursor.js | 31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/dd3e2374/Editor/src/Cursor.js
----------------------------------------------------------------------
diff --git a/Editor/src/Cursor.js b/Editor/src/Cursor.js
index 377ca2a..7362a9e 100644
--- a/Editor/src/Cursor.js
+++ b/Editor/src/Cursor.js
@@ -871,16 +871,31 @@ var Cursor_insertEndnote;
     Cursor_getAdjacentNodeWithType = function(type)
     {
         var selRange = Selection_get();
-        var position = selRange.start;
-        while (position != null) {
-            var node = Position_closestActualNode(position);
-            for (; node != null; node = node.parentNode) {
-                if (node._type == type)
-                    return node;
+        var pos = Position_preferElementPosition(selRange.start);
+        var node = pos.node;
+        var offset = pos.offset;
+
+        while (true) {
+
+            if (node._type == type)
+                return node;
+
+            if (node.nodeType == Node.ELEMENT_NODE) {
+                var before = node.childNodes[offset-1];
+                if ((before != null) && (before._type == type))
+                    return before;
+
+                var after = node.childNodes[offset];
+                if ((after != null) && (after._type == type))
+                    return after;
             }
-            position = Position_prev(position);
+
+            if (node.parentNode == null)
+                return null;
+
+            offset = DOM_nodeOffset(node);
+            node = node.parentNode;
         }
-        return null;
     }
 
     Cursor_getLinkProperties = function()


Mime
View raw message