summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--index.html8
-rw-r--r--src/main.js26
-rw-r--r--src/textanalysis.ui.js24
-rw-r--r--src/view/completer.js62
4 files changed, 70 insertions, 50 deletions
diff --git a/index.html b/index.html
index 1c9d4ee3..ccfc30f8 100644
--- a/index.html
+++ b/index.html
@@ -31,9 +31,11 @@
</div>
</div>
<div class="search-bar">
- <form class="search-input">
+ <div class="search-input">
<input id="search" placeholder="Search for nodes and relationships"/>
- </form>
+ </div>
+ <div id="search-suggestion" class="suggestion" style="display: none">
+ </div>
<div class="export">
<a href="#">Export</a>
</div>
@@ -49,7 +51,7 @@
<input class="input-bar" id="textanalyser" placeholder="Add nodes and relationships"/>
<button class="add-button"></button>
</form>
- <div class="suggestion" style="display: none">
+ <div id="input-suggestion" class="suggestion" style="display: none">
</div>
</div>
<div class="info-container">
diff --git a/src/main.js b/src/main.js
index 14bdf10e..863d0440 100644
--- a/src/main.js
+++ b/src/main.js
@@ -1,5 +1,5 @@
-define(['textanalysis.ui', 'textanalysis', 'buttons', 'history', 'drag_n_drop', 'robot', 'model/core', 'rz_config', 'rz_core', 'view/selection', 'util'],
-function(textanalysis_ui, textanalysis, buttons, history, drag_n_drop, robot, model_core, rz_config, rz_core, selection, util) {
+define(['textanalysis.ui', 'textanalysis', 'buttons', 'history', 'drag_n_drop', 'robot', 'model/core', 'rz_config', 'rz_core', 'view/selection', 'util', 'view/completer'],
+function(textanalysis_ui, textanalysis, buttons, history, drag_n_drop, robot, model_core, rz_config, rz_core, selection, util, completer) {
function expand(obj){
if (!obj.savesize) {
@@ -9,9 +9,13 @@ function(textanalysis_ui, textanalysis, buttons, history, drag_n_drop,
}
this.main = function() {
- var json;
+ var json,
+ search = $('#search'),
+ search_completer = completer(search, $('#search-suggestion'),
+ {triggerStart:' ', triggerEnd:' '});
console.log('Rhizi main started');
+ search_completer.options.plug(textanalysis.suggestions_options);
drag_n_drop.init();
$('#editname').onkeyup = function() { expand(this); };
$('#editlinkname').onkeyup = function() { expand(this); };
@@ -36,15 +40,15 @@ function(textanalysis_ui, textanalysis, buttons, history, drag_n_drop,
$('#textanalyser').focus();
}
if (e.altKey && e.ctrlKey && key == 'o') {
- $('#search').focus();
+ search.focus();
}
if (e.ctrlKey && key == 'z' && e.target.nodeName !== 'INPUT') {
// TODO: rz_core.graph.undo();
}
};
// TODO: move me somewhere
- $('#search').on('input', function(e) {
- var text = this.value.trim(),
+ function search_on_submit() {
+ var text = search[0].value.trim(),
r;
try {
@@ -58,10 +62,12 @@ function(textanalysis_ui, textanalysis, buttons, history, drag_n_drop,
selection.clear();
}
rz_core.update_view__graph(false);
- e.preventDefault();
- });
- $('#search').on('keypress', function(e) {
- if (e.which == 13) {
+ };
+ search.on('input', search_on_submit);
+ search.on('keydown', function(e) {
+ if (e.which == 13 && !search_completer.handleEnter()) {
+ e.preventDefault();
+ search_on_submit(e);
return false;
}
return undefined;
diff --git a/src/textanalysis.ui.js b/src/textanalysis.ui.js
index 4f4ec261..8fff0d64 100644
--- a/src/textanalysis.ui.js
+++ b/src/textanalysis.ui.js
@@ -50,7 +50,7 @@ var typeselection = function TypeSelectionDialog() {
return typeselection;
}();
-var analysisCompleter = completer(element, $('.suggestion'));
+var analysisCompleter = completer(element, $('#input-suggestion'));
function analyzeSentence(sentence, finalize)
{
@@ -140,32 +140,10 @@ return {
ret = false;
}
break;
- case 38: //UP
- case 40: //DOWN
- ret = false;
- break;
}
document_keydown.push({where: consts.KEYSTROKE_WHERE_TEXTANALYSIS, keys: [e.keyCode]});
return ret;
});
- element.keyup(function(e) {
- var ret = undefined;
- switch (e.keyCode) {
- case 38: //UP
- analysisCompleter.prev_option();
- ret = false;
- break;
- case 40: //DOWN
- analysisCompleter.next_option();
- ret = false;
- break;
- default:
- // This catches cursor move due to keyboard events. no event for cursor movement itself
- // below we catch cursor moves due to mouse click
- analysisCompleter.oninput(element_raw.value, element_raw.selectionStart);
- }
- return ret;
- });
element.bind('input selectionchange click', function() {
analysisCompleter.oninput(element_raw.value, element_raw.selectionStart);
});
diff --git a/src/view/completer.js b/src/view/completer.js
index b4099b01..d5e9ec39 100644
--- a/src/view/completer.js
+++ b/src/view/completer.js
@@ -24,9 +24,8 @@ function setCaret(e, num)
e.selectionStart = e.selectionEnd = num;
}
-var completer = (function (input_element, dropdown) {
- var triggerStart = '#',
- triggerEnd = ' ',
+var completer = (function (input_element, dropdown, base_config) {
+ var config = get_config(base_config),
dropdown_raw = dropdown[0],
options_bus = new Bacon.Bus(),
options = [],
@@ -44,6 +43,39 @@ var completer = (function (input_element, dropdown) {
options = new_options;
});
+ input_element.keyup(function(e) {
+ var ret = undefined;
+ switch (e.keyCode) {
+ case 38: //UP
+ prev_option();
+ ret = false;
+ break;
+ case 40: //DOWN
+ next_option();
+ ret = false;
+ break;
+ default:
+ // This catches cursor move due to keyboard events. no event for cursor movement itself
+ // below we catch cursor moves due to mouse click
+ oninput(input_element_raw.value, input_element_raw.selectionStart);
+ }
+ return ret;
+ });
+ input_element.keydown(function(e) {
+ switch (e.keyCode) {
+ case 38:
+ case 40:
+ return false;
+ }
+ });
+
+ function get_config(base) {
+ return {
+ triggerStart: base && base.triggerStart || '#',
+ triggerEnd: base && base.triggerEnd || ' ',
+ };
+ }
+
function completions(text)
{
var ret = [],
@@ -57,24 +89,26 @@ var completer = (function (input_element, dropdown) {
return ret;
}
+ /***
+ * #this is a #
+ * ^
+ *
+ * #this is a #t
+ * ^
+ *
+ * #this and #that then #he
+ * ^
+ */
function oninput(text, cursor) {
- // #this is a #
- // ^
- //
- // #this is a #t
- // ^
- //
- // #this and #that then #he
- // ^
- var hash = text.slice(0, cursor).lastIndexOf(triggerStart);
+ var hash = text.slice(0, cursor).lastIndexOf(config.triggerStart);
// TODO check if current completion has been invalidated
_invalidateSelection();
dropdown.hide();
dropdown_raw.innerHTML = ""; // remove all elements
- if (hash == -1) {
+ if (hash == -1 && config.triggerStart != ' ') { // space matches start of string too
return;
}
- var space = text.slice(hash).indexOf(triggerEnd);
+ var space = text.slice(hash + 1).indexOf(config.triggerEnd);
space = space == -1 ? text.length : space;
if (space < cursor) {
return;