summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Levy <alon@pobox.com>2015-05-04 20:02:08 +0300
committerAlon Levy <alon@pobox.com>2015-05-04 20:02:08 +0300
commit5565dc1b1421807f242d0e402895aecbd0749851 (patch)
tree1b6bf70783f5771058dceb20f3c1076cd4c82719 /src
parent630fc2c06e774806920ac8a5ec94bce1d49651e4 (diff)
client: update selected type prompt based on cursor
Diffstat (limited to 'src')
-rw-r--r--src/client/textanalysis.js12
-rw-r--r--src/client/textanalysis.ui.js12
-rw-r--r--src/client/view/textanalyser_input.js4
3 files changed, 23 insertions, 5 deletions
diff --git a/src/client/textanalysis.js b/src/client/textanalysis.js
index 354ac760..22a11527 100644
--- a/src/client/textanalysis.js
+++ b/src/client/textanalysis.js
@@ -12,10 +12,8 @@ var separator_string = rz_config.separator_string;
var typeindex = 0,
nodetypes = model_types.nodetypes,
nodetypes_count = nodetypes.length,
- default_nodetype = nodetypes[0],
- node_name_to_type = {};
-
-util.assert(nodetypes.indexOf(default_nodetype) !== -1);
+ node_name_to_type = {},
+ nodetype_to_index = _.object(nodetypes, _.range(nodetypes.length));
var _get_lastnode,
get_lastnode = function (editgraph, cursor) {
@@ -619,6 +617,11 @@ function init(main_graph)
.onValue(auto_suggest__update_from_graph);
}
+function selected_type_set(typename)
+{
+ typeindex = nodetype_to_index[typename] || 0;
+}
+
return {
init:init,
textAnalyser:textAnalyser,
@@ -643,6 +646,7 @@ return {
typeindex = (typeindex + nodetypes_count - 1) % nodetypes_count;
return selectedType();
},
+ selected_type_set: selected_type_set,
selected_type: selectedType,
};
});
diff --git a/src/client/textanalysis.ui.js b/src/client/textanalysis.ui.js
index 0e126d9b..13c861d0 100644
--- a/src/client/textanalysis.ui.js
+++ b/src/client/textanalysis.ui.js
@@ -118,7 +118,8 @@ function analyzeSentence(spec)
function changeType(up)
{
- var lastnode = textanalysis.lastnode(rz_core.edit_graph, input.selectionStart()),
+ var cursor = input.selectionStart(),
+ lastnode = textanalysis.lastnode(rz_core.edit_graph, cursor),
nodetype,
id,
name;
@@ -145,6 +146,15 @@ var main = function ()
finalize: false,
}));
});
+ input.on_cursor.onValue(function (cursor) {
+ var lastnode = textanalysis.lastnode(rz_core.edit_graph, cursor);
+
+ if (lastnode === null) {
+ return;
+ }
+ textanalysis.selected_type_set(lastnode.type);
+ typeselection.showChosenType(lastnode.id, lastnode.type);
+ });
input.on_type.onValue(function (up) {
if (textanalysis.lastnode(rz_core.edit_graph, input.selectionStart())) {
changeType(up);
diff --git a/src/client/view/textanalyser_input.js b/src/client/view/textanalyser_input.js
index bf96db1b..89602008 100644
--- a/src/client/view/textanalyser_input.js
+++ b/src/client/view/textanalyser_input.js
@@ -74,6 +74,7 @@ function textanalyser_input(spec) {
spec: spec,
on_analysis__input: new Bacon.Bus(),
on_analysis__output: new Bacon.Bus(),
+ on_cursor: new Bacon.Bus(),
on_resize: new Bacon.Bus(),
element: $(element_name),
selectionStart: selectionStart,
@@ -149,6 +150,9 @@ function textanalyser_input(spec) {
e.preventDefault();
});
+ ta.on_cursor.plug(element.asEventStream('input keyup click selectionchange').map(function() {
+ return selectionStart();}).skipDuplicates());
+
ta.on_analysis__input.plug(element.asEventStream('input').map(current_value).map(function (val) {
return update_element(val);
}));