summaryrefslogtreecommitdiff
path: root/src/client/textanalysis.js
diff options
context:
space:
mode:
authorAlon Levy <alon@pobox.com>2015-03-08 14:24:38 +0200
committerAlon Levy <alon@pobox.com>2015-03-08 14:25:28 +0200
commit60d25c22542160845cd025cfa4368c61963659d3 (patch)
tree3603c524009b18135701a3a792ff5667e5d7387f /src/client/textanalysis.js
parentfc2aa0d574f70897280e26a53d8fb36eed78d715 (diff)
client/textanalysis: add element_at_position__is_link
Diffstat (limited to 'src/client/textanalysis.js')
-rw-r--r--src/client/textanalysis.js30
1 files changed, 28 insertions, 2 deletions
diff --git a/src/client/textanalysis.js b/src/client/textanalysis.js
index d44dfd06..64d7af7c 100644
--- a/src/client/textanalysis.js
+++ b/src/client/textanalysis.js
@@ -20,6 +20,10 @@ util.assert(nodetypes.indexOf(default_nodetype) !== -1);
var _get_lastnode,
get_lastnode = function (editgraph, cursor) {
return undefined !== _get_lastnode ? _get_lastnode(editgraph, cursor) : null;
+ },
+ _element_at_position__is_link,
+ element_at_position__is_link = function(cursor) {
+ return undefined !== _element_at_position__is_link ? _element_at_position__is_link(cursor) : false;
};
var sugg_name = {},
@@ -52,12 +56,21 @@ function even_second(_, i)
function list_first_pred(list, default_, pred)
{
+ var index = list_first_pred__index(list, pred);
+
+ if (undefined === index) {
+ return default_;
+ }
+ return list[index];
+}
+
+function list_first_pred__index(list, pred)
+{
for (var i = 0 ; i < list.length ; ++i) {
if (pred(list[i])) {
- return list[i];
+ return i;
}
}
- return default_;
}
function list_product(l1, l2)
@@ -597,9 +610,20 @@ var textAnalyser = function (spec) {
return node;
}
+ function __element_at_position__is_link(cursor) {
+ var index = list_first_pred__index(thirds, function (d) {
+ return cursor >= d.start && cursor < d.end;
+ });
+ index = undefined === index ? thirds.length - 1 : index;
+ return index % 2 == 1;
+ }
+
+ // FIXME: ugh.
+
_get_lastnode = finalize || tokens.length === 0 ? function () { return null; }
: lookup_node_in_bounds;
+ _element_at_position__is_link = __element_at_position__is_link;
return ret;
};
@@ -617,6 +641,8 @@ return {
ANALYSIS_NODE: ANALYSIS_NODE,
ANALYSIS_LINK:ANALYSIS_LINK,
+ element_at_position__is_link: element_at_position__is_link,
+
//for the external arrow-type changer
lastnode: get_lastnode,
set_type: function(name, nodetype) {