Fix hint helper for chrome
diff --git a/dev/js/src/hint.js b/dev/js/src/hint.js
index 6aed544..885e1ea 100644
--- a/dev/js/src/hint.js
+++ b/dev/js/src/hint.js
@@ -1,5 +1,6 @@
/**
* Hint menu for Kalamar.
+ * Based on menu object.
*
* @author Nils Diewald
*/
@@ -76,7 +77,7 @@
// Add event listener for key pressed down
inputFieldElement.addEventListener(
- "keypress", function (e) {
+ "keydown", function (e) {
var code = _codeFromEvent(e);
if (code === 40) {
that.show(false);
@@ -85,13 +86,20 @@
}, false
);
- // Move infobox
- inputFieldElement.addEventListener(
- "keyup", function (e) {
- var input = that._inputField;
- input.update();
- }
- );
+ this._inputField.container().addEventListener('click', function (e) {
+ if (!this.classList.contains('active')) {
+ that.show(false);
+ };
+ });
+
+ var _up = function (e) {
+ var input = that._inputField;
+ input.update();
+ };
+
+ // Move infobox
+ inputFieldElement.addEventListener("keyup", _up);
+ inputFieldElement.addEventListener("click", _up);
// Set Analyzer for context
this._analyzer = analyzerClass.create(
@@ -105,25 +113,6 @@
},
/**
- * A new update by keypress
- */
- /*
-updateKeyPress : function (e) {
- if (!this._active)
- return;
-
- var character = String.fromCharCode(_codeFromEvent(e));
-
- e.halt(); // No event propagation
-
- // Only relevant for key down
- console.log("TODO: filter view");
- },
- */
-
- // updateKeyDown : function (e) {},
-
- /**
* Return hint menu and probably init based on an action
*/
menu : function (action) {
@@ -187,13 +176,6 @@
c.appendChild(menu.element());
menu.show('');
menu.focus();
-// Update bounding box
-/*
- }
- else if (!ifContext) {
- // this.hide();
- };
-*/
// Focus on input field
// this.inputField.element.focus();
};
diff --git a/dev/js/src/hint/item.js b/dev/js/src/hint/item.js
index f23cabc..4b879f8 100644
--- a/dev/js/src/hint/item.js
+++ b/dev/js/src/hint/item.js
@@ -8,6 +8,7 @@
.upgradeTo(this)
._init(params);
},
+
_init : function (params) {
if (params[0] === undefined ||
params[1] === undefined)
@@ -32,7 +33,7 @@
return this._content;
},
- onclick : function () {
+ onclick : function (e) {
var m = this.menu();
var h = m.hint();
m.hide();
@@ -43,8 +44,12 @@
input.update();
h.active = false;
+
+ e.halt();
+
h.show(true);
},
+
name : function () {
return this._name;
},
diff --git a/dev/js/src/menu.js b/dev/js/src/menu.js
index 0d5e6ac..2bc356b 100644
--- a/dev/js/src/menu.js
+++ b/dev/js/src/menu.js
@@ -75,7 +75,7 @@
},
// Arrow key and prefix treatment
- _keypress : function (e) {
+ _keydown : function (e) {
var code = _codeFromEvent(e);
switch (code) {
@@ -126,17 +126,19 @@
this.show();
e.halt();
break;
- default:
- if (e.key !== undefined &&
- e.key.length != 1)
- return;
+ };
+ },
- // Add prefix
- this._prefix.add(e.key.toLowerCase());
+ // Add characters to prefix
+ _keypress : function (e) {
+ var c = String.fromCharCode(_codeFromEvent(e)).toLowerCase();
- if (!this.show()) {
- this.prefix('').show();
- };
+ // Add prefix
+ this._prefix.add(c);
+
+ if (!this.show()) {
+ this.prefix('').show();
+ e.halt();
};
},
@@ -165,6 +167,15 @@
// Arrow keys
e.addEventListener(
+ 'keydown',
+ function (ev) {
+ that._keydown(ev)
+ },
+ false
+ );
+
+ // Strings
+ e.addEventListener(
'keypress',
function (ev) {
that._keypress(ev)