From 5565dc1b1421807f242d0e402895aecbd0749851 Mon Sep 17 00:00:00 2001 From: Alon Levy Date: Mon, 4 May 2015 20:02:08 +0300 Subject: client: update selected type prompt based on cursor --- src/client/textanalysis.js | 12 ++++++++---- src/client/textanalysis.ui.js | 12 +++++++++++- src/client/view/textanalyser_input.js | 4 ++++ 3 files changed, 23 insertions(+), 5 deletions(-) (limited to 'src/client') 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); })); -- cgit v1.3.1