You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@corinthia.apache.org by pm...@apache.org on 2015/03/06 08:45:32 UTC
incubator-corinthia git commit: getAdjacentNodeWithType: traverse up,
not back
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 <pe...@uxproductivity.com>
Authored: Fri Mar 6 14:45:07 2015 +0700
Committer: Peter Kelly <pe...@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()