Fix hint specific Line appearing in general containermenu
Change-Id: I6a6a14c5b89f14d9e4e8ccaf27d4e3c7243a74db
diff --git a/dev/js/spec/containerMenuSpec.js b/dev/js/spec/containerMenuSpec.js
index a3283a3..36d12fe 100644
--- a/dev/js/spec/containerMenuSpec.js
+++ b/dev/js/spec/containerMenuSpec.js
@@ -1,7 +1,56 @@
define(
['containermenu', 'menu/item', 'menu/prefix', 'menu/lengthField','container/containeritem','container/container'],
function (containerMenuClass, menuItemClass, prefixClass, lengthFieldClass, containerItemClass, containerClass) {
-
+ function emitKeyboardEvent (element, type, letter, keyCode) {
+ // ORIGINAL FROM hintSpec.js !!!
+ // event type : keydown, keyup, keypress
+ // http://stackoverflow.com/questions/596481/simulate-javascript-key-events
+ // http://stackoverflow.com/questions/961532/firing-a-keyboard-event-in-javascript
+ /**
+ * Nils Version. Does not work due to bug noted below
+ var keyboardEvent = document.createEvent("KeyboardEvent",);
+ var initMethod = typeof keyboardEvent.initKeyboardEvent !== 'undefined' ?
+ "initKeyboardEvent" : "initKeyEvent";
+ keyboardEvent[initMethod](
+
+
+
+ type,
+ true, // bubbles
+ true, // cancelable
+ window, // viewArg: should be window
+ false, // ctrlKeyArg
+ false, // altKeyArg
+ false, // shiftKeyArg
+ false, // metaKeyArg
+ keyCode, // keyCodeArg : unsigned long the virtual key code, else 0
+ charCode || 0 // charCodeArgs : unsigned long the Unicode character
+ // associated with the depressed key, else 0
+
+ );
+ element.dispatchEvent(keyboardEvent);
+ */
+ //Leos Version
+ //https://stackoverflow.com/a/59113178
+
+ //might not work on Chromium
+ element.dispatchEvent(new KeyboardEvent(type, {
+ key: letter,
+ keyCode: keyCode,
+ code: "Key"+letter,
+ which: keyCode, //This is a hack
+ shiftKey: false,
+ ctrlKey: false,
+ metaKey: false,
+ bubbles: true,
+ view: window,
+ charCode: keyCode //This is a hack https://bugs.webkit.org/show_bug.cgi?id=16735
+ // charCodeArgs : unsigned long the Unicode character
+ // associated with the depressed key, else 0
+ }));
+ // ORIGINAL FROM hintSpec.js !!!
+ };
+
// The OwnMenu item
const OwnMenuItem = {
create : function (params) {
@@ -2045,10 +2094,10 @@
xit('should scroll to a chosen value after prefixing, if the chosen value is live');
it('should be extendable', function () {
- var menu = OwnContainerMenu.create([],ExampleItemList);
- let entryData = 'empty';
- menu._itemClass = menuItemClass;
- menu.readItems([
+ var menu = OwnContainerMenu.create([],ExampleItemList);
+ let entryData = 'empty';
+ menu._itemClass = menuItemClass;
+ menu.readItems([
['a', '', function () { entryData = 'a' }],
['bb', '', function () { entryData = 'bb' }],
['ccc', '', function () { entryData = 'ccc' }],
@@ -2150,6 +2199,26 @@
expect(menu.container().item()).toEqual(menu.container()._cItemPrefix);
expect(menu.container()._prefixPosition).toEqual(menu.container().items.indexOf(menu.container()._cItemPrefix));
});
+
+ it('should highlight the prefix if no item matches.', function () {
+ var menu = OwnContainerMenu.create(demolist,ExampleItemList);
+ expect(menu.limit(3).show(3)).toBe(true);
+ menu.element().focus();
+
+ emitKeyboardEvent(menu.element(), 'keypress', "E", 69);
+ emitKeyboardEvent(menu.element(), 'keypress', "E", 69);
+ emitKeyboardEvent(menu.element(), 'keypress', "E", 69);
+ expect(menu.container()._cItemPrefix.active()).toBeTruthy();
+ expect(menu.prefix()).toEqual("EEE");
+ expect(menu.element().classList.contains("visible")).toBeTruthy();
+ expect(menu.container().element().classList.contains("visible")).toBeTruthy();
+ emitKeyboardEvent(menu.element(),'keydown'," ",13);
+ //Should call reset() and hide()
+ // hint containermenu should do something different.
+ expect(menu.prefix()).toEqual("EEE");
+ expect(menu.element().classList.contains("visible")).toBeTruthy();
+ expect(menu.container().element().classList.contains("visible")).toBeTruthy();
+ });
});
describe('KorAP.ContainerMenu.Container', function () {
diff --git a/dev/js/spec/hintSpec.js b/dev/js/spec/hintSpec.js
index e81033d..5c7a1c7 100644
--- a/dev/js/spec/hintSpec.js
+++ b/dev/js/spec/hintSpec.js
@@ -2,14 +2,19 @@
define(['hint', 'hint/input', 'hint/contextanalyzer', 'hint/menu', 'hint/item'], function (hintClass, inputClass, contextClass, menuClass, menuItemClass) {
- function emitKeyboardEvent (element, type, keyCode) {
+ function emitKeyboardEvent (element, type, letter, keyCode) {
// event type : keydown, keyup, keypress
// http://stackoverflow.com/questions/596481/simulate-javascript-key-events
// http://stackoverflow.com/questions/961532/firing-a-keyboard-event-in-javascript
- var keyboardEvent = document.createEvent("KeyboardEvent");
+ /**
+ * Nils Version. Does not work due to bug noted below
+ var keyboardEvent = document.createEvent("KeyboardEvent",);
var initMethod = typeof keyboardEvent.initKeyboardEvent !== 'undefined' ?
"initKeyboardEvent" : "initKeyEvent";
keyboardEvent[initMethod](
+
+
+
type,
true, // bubbles
true, // cancelable
@@ -19,10 +24,30 @@
false, // shiftKeyArg
false, // metaKeyArg
keyCode, // keyCodeArg : unsigned long the virtual key code, else 0
- 0 // charCodeArgs : unsigned long the Unicode character
+ charCode || 0 // charCodeArgs : unsigned long the Unicode character
// associated with the depressed key, else 0
+
);
element.dispatchEvent(keyboardEvent);
+ */
+ //Leos Version
+ //https://stackoverflow.com/a/59113178
+
+ //might not work on Chromium
+ element.dispatchEvent(new KeyboardEvent(type, {
+ key: letter,
+ keyCode: keyCode,
+ code: "Key"+letter,
+ which: keyCode, //This is a hack
+ shiftKey: false,
+ ctrlKey: false,
+ metaKey: false,
+ bubbles: true,
+ view: window,
+ charCode: keyCode //This is a hack https://bugs.webkit.org/show_bug.cgi?id=16735
+ // charCodeArgs : unsigned long the Unicode character
+ // associated with the depressed key, else 0
+ }));
};
var afterAllFunc = function () {
@@ -125,13 +150,13 @@
expect(inputField.context()).toEqual("abcde");
});
- /*
+
it('should be correctly triggerable', function () {
// https://developer.mozilla.org/samples/domref/dispatchEvent.html
var hint = KorAP.Hint.create({ "inputField" : input });
- emitKeyboardEvent(hint.inputField.element, "keypress", 20);
+ emitKeyboardEvent(hint.inputField()._el, "keypress", "E", 69);
});
- */
+
});
@@ -438,6 +463,41 @@
});
+
+ it('should highlight the prefix if no item matches.', function () {
+ const hint = hintClass.create({
+ inputField : input
+ });
+ hint.inputField().reset();
+
+ expect(hint.active()).toBeFalsy();
+
+ // show with context
+ hint.show(false);
+
+ expect(hint.active()).toBeTruthy();
+
+ const menu = hint.active();
+ expect(menu.limit(3).show(3)).toBe(true);
+ menu.element().focus();
+
+
+
+ emitKeyboardEvent(menu.element(), 'keypress', "E", 69);
+ emitKeyboardEvent(menu.element(), 'keypress', "E", 69);
+ emitKeyboardEvent(menu.element(), 'keypress', "E", 69);
+ expect(menu.container()._cItemPrefix.active()).toBeTruthy();
+ expect(menu.prefix()).toEqual("EEE");
+ expect(menu.element().classList.contains("visible")).toBeTruthy();
+ expect(menu.container().element().classList.contains("visible")).toBeTruthy();
+
+ emitKeyboardEvent(menu.element(),'keydown'," ",13);
+ //Should call reset() and hide()
+ // hint containermenu should do something different.
+ expect(menu.prefix()).toEqual("");
+ expect(menu.element().classList.contains("visible")).toBeFalsy();
+ expect(menu.container().element().classList.contains("visible")).toBeFalsy();
+ });
xit('should remove all menus on escape');
diff --git a/dev/js/src/containermenu.js b/dev/js/src/containermenu.js
index 83e3dc6..5d3f5f3 100644
--- a/dev/js/src/containermenu.js
+++ b/dev/js/src/containermenu.js
@@ -130,9 +130,9 @@
t.container().enter(e);
//NEW: reset some things. These are reset for hint menu style items
// so I believe we need to do the same when pressing on items in the container
- t.reset("");
- t.hide();
- t.hint().unshow();
+ //t.reset("");
+ //t.hide();
+ //t.hint().unshow(); Moved this line into hint/menu.js because it is hint containermenu specific!
//for clicking this is done in container.js with an eventListener for click.
} else { // Click on item
t.liveItem(t.position).onclick(e);
diff --git a/dev/js/src/hint/menu.js b/dev/js/src/hint/menu.js
index ecd0b51..ebbdd68 100644
--- a/dev/js/src/hint/menu.js
+++ b/dev/js/src/hint/menu.js
@@ -51,7 +51,7 @@
obj.container().element().addEventListener("click", function (e) {
this.reset("");
this.element().blur();
- this.hint().unshow(); //hide the containermenu, not with hide but with blur, because blur would usually happen in default mousedown behaviour
+ //NOW IN RESET: this.hint().unshow(); //hide the containermenu, not with hide but with blur, because blur would usually happen in default mousedown behaviour
e.halt(); // Question: my impression is that this click event handler is called after all the others and thus this should be absolutely no problem.
// Are we sure there are no things that do not happen now thanks to this?
@@ -87,6 +87,7 @@
reset : function (action) {
this.prefix("");
this.hint().inputField().insert(action).update();
+ this.hint().unshow()
},
};
});