Clean prefix of annotation assistant, in case a menu item is chosen
Change-Id: Ic770e707e06ad743dea2f70dd8904d21eb50774f
diff --git a/dev/js/spec/hintSpec.js b/dev/js/spec/hintSpec.js
index 1ff9343..fe96f79 100644
--- a/dev/js/spec/hintSpec.js
+++ b/dev/js/spec/hintSpec.js
@@ -46,7 +46,7 @@
afterEach(function () {
document.getElementsByTagName("body")[0].removeChild(
- input
+ input
);
});
@@ -277,6 +277,50 @@
expect(hint.inputField().container().getElementsByTagName('ul').length).toEqual(0);
});
+
+ it('should open menus depending on the context', function () {
+ var hint = hintClass.create({
+ inputField : input
+ });
+ hint.inputField().reset();
+
+ expect(hint.active()).toBeFalsy();
+
+ // show with context
+ hint.show(false);
+
+ expect(hint.active()).toBeTruthy();
+
+ expect(hint.inputField().container().getElementsByTagName('li')[0].firstChild.innerText).toEqual("Base Annotation");
+
+ // Type in prefix
+ hint.active().prefix("cor").show();
+ expect(hint.active().prefix()).toEqual("cor");
+
+ // Click first step
+ expect(hint.inputField().container().getElementsByTagName('li')[0].firstChild.firstChild.innerText).toEqual("Cor");
+ hint.inputField().container().getElementsByTagName('li')[0].click();
+
+ expect(hint.active()).toBeTruthy();
+
+ // Click second step
+ expect(hint.inputField().container().getElementsByTagName('li')[0].firstChild.innerText).toEqual("Named Entity");
+ hint.inputField().container().getElementsByTagName('li')[0].click()
+
+ // Invisible menu
+ expect(hint.inputField().container().getElementsByTagName('li')[0]).toBeUndefined();
+
+ // Inactive menu
+ expect(hint.active()).toBeFalsy();
+
+ // show with context
+ hint.show(false);
+
+ // No prefix
+ expect(hint.active().prefix()).toEqual("");
+ });
+
+
it('should not view main menu if context is mandatory', function () {
var hint = hintClass.create({
inputField : input
diff --git a/dev/js/src/hint/input.js b/dev/js/src/hint/input.js
index 7145919..adb74b6 100644
--- a/dev/js/src/hint/input.js
+++ b/dev/js/src/hint/input.js
@@ -58,6 +58,14 @@
/**
+ * Reset the input value
+ */
+ reset : function () {
+ this._element.value = "";
+ },
+
+
+ /**
* Update the mirror content.
*/
update : function () {
diff --git a/dev/js/src/hint/item.js b/dev/js/src/hint/item.js
index c39c3c2..47d332b 100644
--- a/dev/js/src/hint/item.js
+++ b/dev/js/src/hint/item.js
@@ -50,12 +50,15 @@
var h = m.hint();
// m.hide();
+ // Reset prefix
+ m.prefix("");
+
// Update input field
var input = h.inputField();
input.insert(this._action).update();
e.halt();
-
+
// show alt
h.show(true);
},
diff --git a/dev/js/src/hint/menu.js b/dev/js/src/hint/menu.js
index dd99d1f..c5c7cc7 100644
--- a/dev/js/src/hint/menu.js
+++ b/dev/js/src/hint/menu.js
@@ -48,12 +48,14 @@
/**
* Hide the menu just for the moment,
- * without cleaning up anything.
+ * without cleaning up anything,
+ /* but resetting the prefix.
*/
hideWithoutDestruction : function () {
this.element().classList.remove("visible");
- if (this._hint)
+ if (this._hint) {
this._hint.inputField().element().focus();
+ };
}
};
});