summaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authorAlon Levy <alon@pobox.com>2015-01-11 12:43:16 +0200
committerAlon Levy <alon@pobox.com>2015-01-11 12:43:16 +0200
commitea74876fb9d980b17db1bd504fb5ef28dd75382e (patch)
tree26c3a3ed2bd2f889d42cba7b7b9c43051ca24bcc /src/client
parentd5a68f9f00eef3d65811c3b6233ffc3126a7615c (diff)
client/textanalysis: fix node type change on tab to use cursor correctly (still cannot change type of chained node during editing)
Diffstat (limited to 'src/client')
-rw-r--r--src/client/textanalysis.js25
-rw-r--r--src/client/textanalysis.ui.js24
2 files changed, 26 insertions, 23 deletions
diff --git a/src/client/textanalysis.js b/src/client/textanalysis.js
index 64a0f4e6..3e888d3c 100644
--- a/src/client/textanalysis.js
+++ b/src/client/textanalysis.js
@@ -163,7 +163,6 @@ function auto_suggest__update_from_graph()
var textAnalyser = function (spec) {
var newtext = spec.sentence,
finalize = spec.finalize,
- cursor = spec.cursor,
tokens,
sentence,
@@ -192,7 +191,6 @@ var textAnalyser = function (spec) {
util.assert(spec.sentence !== undefined &&
spec.finalize !== undefined &&
- spec.cursor !== undefined,
"bad input");
function __addNode(name) {
@@ -447,21 +445,34 @@ var textAnalyser = function (spec) {
}
};
- function lookup_node_in_bounds(edit_graph) {
- var i, d, j, name, node;
+ function lookup_node_in_bounds(edit_graph, cursor) {
+ var i, d, d_next, j, name, node;
+ if (nodes.length <= 0) {
+ return null;
+ }
+ if (nodes.length == 1) {
+ return edit_graph.find_node__by_name(nodes[0].name);
+ }
// go forward to find cursor location in tokens
for (i = 0 ; i < tokens.length; ++i) {
d = tokens[i];
- if (cursor >= d.start && cursor < d.end) {
+ d_next = tokens[i + 1];
+ if (cursor >= d.start && (d_next === undefined || cursor < d_next.end)) {
break;
}
}
+ i = Math.min(tokens.length - 1, i);
+ // go forward if on a token
+ for (; tokens[i] !== undefined && tokens[i].token === '#'; ++i) {}
// go back to find token
- for (j = i - 1; j >= 0 && tokens[j].token != '#'; --j) {}
+ for (j = i; j >= 0 && tokens[j] === undefined || tokens[j].token !== '#'; --j) {}
name = tokens[j + 1] ? tokens[j + 1].token : 'new node';
node = edit_graph.find_node__by_name(name);
- util.assert(node !== undefined, "can't find node");
+ if (node === undefined) {
+ // return the first node by default
+ util.assert(node !== undefined, "can't find node");
+ }
return node;
}
diff --git a/src/client/textanalysis.ui.js b/src/client/textanalysis.ui.js
index 2d51efb0..7fe2940f 100644
--- a/src/client/textanalysis.ui.js
+++ b/src/client/textanalysis.ui.js
@@ -55,8 +55,8 @@ var analysisCompleter = completer(element, $('#input-suggestion'), {hideOnTab: f
function analyzeSentence(spec)
{
util.assert(spec.sentence !== undefined &&
- spec.finalize !== undefined &&
- spec.cursor !== undefined, "bad input");
+ spec.finalize !== undefined,
+ "bad input");
var sentence = spec.sentence,
finalize = spec.finalize,
@@ -97,7 +97,7 @@ function textSelect(inp, s, e) {
}
function changeType(arg) {
- var lastnode = textanalysis.lastnode(rz_core.edit_graph),
+ var lastnode = textanalysis.lastnode(rz_core.edit_graph, element_raw.selectionStart),
nodetype,
id,
name;
@@ -110,15 +110,9 @@ function changeType(arg) {
}
nodetype = (arg === 'up'? textanalysis.selected_type_next() : textanalysis.selected_type_prev());
- if (arg === 'up') {
- rz_core.edit_graph.editType(id, null, nodetype);
- typeselection.showChosenType(nodetype);
- rz_core.edit_graph.findCoordinates(id);
- } else {
- rz_core.edit_graph.editType(id, null, nodetype);
- typeselection.showChosenType(nodetype);
- rz_core.edit_graph.findCoordinates(id);
- }
+ rz_core.edit_graph.editType(id, null, nodetype);
+ typeselection.showChosenType(nodetype);
+ rz_core.edit_graph.findCoordinates(id);
textanalysis.set_type(name, nodetype);
}
@@ -145,13 +139,12 @@ return {
analyzeSentence({
sentence: element.val(),
finalize: false,
- cursor: element_raw.selectionStart,
});
}
ret = false;
break;
case 9: //TAB
- if (textanalysis.lastnode(rz_core.edit_graph)) {
+ if (textanalysis.lastnode(rz_core.edit_graph, element_raw.selectionStart)) {
e.preventDefault();
changeType(e.shiftKey ? "up" : "down");
ret = false;
@@ -171,7 +164,7 @@ return {
analyzeSentence({
sentence: text,
finalize: true,
- cursor: element_raw.selectionStart});
+ });
text = "";
}
@@ -194,7 +187,6 @@ return {
analyzeSentence({
sentence: text,
finalize: false,
- cursor: element_raw.selectionStart
});
input.push({where: consts.INPUT_WHERE_TEXTANALYSIS, input: text});
});