summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Levy <alon@pobox.com>2015-03-08 14:55:15 +0200
committerAlon Levy <alon@pobox.com>2015-03-08 14:55:16 +0200
commit59c23de887c2938533b735f0dedbb788e22d0f6f (patch)
tree0433b8b943ba13d599e7978bb861113706f4d9d9
parent84cf1a4f50ef5b5094b4e250b664fb0e7089ee10 (diff)
client/completion: support links as well
the suggestions from textanalysis now come as a dictionary with {nodes: {name: id}, links: {name: id}} (before it was a single dictionary, {name:id}) And the options bus for the textanalyser and search completion have been updated accordingly. textanalyser also takes into account the cursor position to determine which of the option dictionaries to use.
-rw-r--r--src/client/textanalysis.js26
-rw-r--r--src/client/view/search.js2
-rw-r--r--src/client/view/textanalyser_input.js15
3 files changed, 20 insertions, 23 deletions
diff --git a/src/client/textanalysis.js b/src/client/textanalysis.js
index 64d7af7c..215c3fa8 100644
--- a/src/client/textanalysis.js
+++ b/src/client/textanalysis.js
@@ -27,11 +27,10 @@ var _get_lastnode,
};
var sugg_name = {},
- id_to_name_map = {},
suggestions_bus = new Bacon.Bus(),
suggestions_options = suggestions_bus.toProperty();
-suggestions_bus.push([]);
+suggestions_bus.push({nodes:{}, links:{}});
var ANALYSIS_NODE_START = 'ANALYSIS_NODE_START';
var ANALYSIS_NODE = 'ANALYSIS_NODE';
@@ -305,27 +304,14 @@ function tokenize(text, node_token, quote)
}
-/*
- * id - undefined | node id
- *
- */
-function auto_suggest__update_name(name, id)
-{
- if (id !== undefined && id_to_name_map[id] !== undefined) {
- delete sugg_name[id_to_name_map[id]];
- id_to_name_map[id] = name;
- }
- /* note that name can contain spaces - this is ok. We might want to limit this though? */
- sugg_name[name] = 1;
- suggestions_bus.push(sugg_name);
-}
-
function auto_suggest__update_from_graph()
{
- sugg_name = {};
- id_to_name_map = {};
+ sugg_name = {nodes:{}, links:{}};
rz_core.main_graph.nodes().forEach(function (node) {
- auto_suggest__update_name(node.name, node.id);
+ sugg_name.nodes[node.name] = node.id;
+ });
+ rz_core.main_graph.links().forEach(function (link) {
+ sugg_name.links[link.name] = link.id;
});
suggestions_bus.push(sugg_name);
}
diff --git a/src/client/view/search.js b/src/client/view/search.js
index c6203c34..29e702d1 100644
--- a/src/client/view/search.js
+++ b/src/client/view/search.js
@@ -17,7 +17,7 @@ function init() {
matchStartOfString: true,
});
- search_completer.options.plug(textanalysis.suggestions_options);
+ search_completer.options.plug(textanalysis.suggestions_options.map('.nodes'));
search.on('input', search_on_submit);
search.on('keydown', function(e) {
if (e.which == 13 && !search_completer.handleEnter()) {
diff --git a/src/client/view/textanalyser_input.js b/src/client/view/textanalyser_input.js
index 184402b1..5ac72a72 100644
--- a/src/client/view/textanalyser_input.js
+++ b/src/client/view/textanalyser_input.js
@@ -89,9 +89,20 @@ function textanalyser_input(spec) {
},
analysisCompleter = completer(element, $(spec.completer_name), completer_spec),
document_keydown = new Bacon.Bus(),
- input_bus = new Bacon.Bus();
+ input_bus = new Bacon.Bus(),
+ selectionBus = element.asEventStream('selectstart input keyup').map(selectionStart).skipDuplicates();
- analysisCompleter.options.plug(textanalysis.suggestions_options);
+ analysisCompleter.options.plug(
+ textanalysis.suggestions_options
+ .combine(selectionBus, function (options, cursor) { return [options, cursor]; })
+ .combine(ta.on_analysis__output, function (both, output) { return both; })
+ .map(
+ function (both) {
+ var options = both[0],
+ cursor = both[1],
+ is_link = textanalysis.element_at_position__is_link(cursor);
+ return options[is_link ? 'links' : 'nodes'];
+ }));
util.assert(1 === element.length);