Commit 13c9612a authored by JC Brand's avatar JC Brand

Let an additional tab select the currently highlighted element

parent 2abd1c1d
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
const tab_event = { const tab_event = {
'target': textarea, 'target': textarea,
'preventDefault': _.noop, 'preventDefault': _.noop,
'stopPropagation': _.noop,
'keyCode': 9 'keyCode': 9
} }
view.keyPressed(tab_event); view.keyPressed(tab_event);
...@@ -102,6 +103,26 @@ ...@@ -102,6 +103,26 @@
'keyCode': 13 'keyCode': 13
}); });
expect(textarea.value).toBe('hello s some2'); expect(textarea.value).toBe('hello s some2');
// Test that pressing tab twice selects
presence = $pres({
'to': 'dummy@localhost/resource',
'from': 'lounge@localhost/z3r0'
})
.c('x', {xmlns: Strophe.NS.MUC_USER})
.c('item', {
'affiliation': 'none',
'jid': 'z3r0@localhost/resource',
'role': 'participant'
});
_converse.connection._dataRecv(test_utils.createRequest(presence));
textarea.value = "hello z";
view.keyPressed(tab_event);
view.keyUp(tab_event);
view.keyPressed(tab_event);
view.keyUp(tab_event);
expect(textarea.value).toBe('hello z3r0');
done(); done();
}).catch(_.partial(console.error, _)); }).catch(_.partial(console.error, _));
})); }));
......
...@@ -116,7 +116,6 @@ ...@@ -116,7 +116,6 @@
while (li && !(/li/i).test(li.nodeName)) { while (li && !(/li/i).test(li.nodeName)) {
li = li.parentNode; li = li.parentNode;
} }
if (li && evt.button === 0) { // Only select on left click if (li && evt.button === 0) { // Only select on left click
evt.preventDefault(); evt.preventDefault();
this.select(li, evt.target); this.select(li, evt.target);
...@@ -267,19 +266,19 @@ ...@@ -267,19 +266,19 @@
keyPressed (ev) { keyPressed (ev) {
if (this.opened) { if (this.opened) {
if (ev.keyCode === _converse.keycodes.ENTER && this.selected) { if (_.includes([_converse.keycodes.ENTER, _converse.keycodes.TAB], ev.keyCode) && this.selected) {
ev.preventDefault(); ev.preventDefault();
ev.stopPropagation(); ev.stopPropagation();
this.select(); this.select();
return false; return true;
} else if (ev.keyCode === _converse.keycodes.ESCAPE) { } else if (ev.keyCode === _converse.keycodes.ESCAPE) {
this.close({'reason': 'esc'}); this.close({'reason': 'esc'});
return false; return true;
} else if (ev.keyCode === _converse.keycodes.UP_ARROW || ev.keyCode === _converse.keycodes.DOWN_ARROW) { } else if (_.includes([_converse.keycodes.UP_ARROW, _converse.keycodes.DOWN_ARROW], ev.keyCode)) {
ev.preventDefault(); ev.preventDefault();
ev.stopPropagation(); ev.stopPropagation();
this[ev.keyCode === _converse.keycodes.UP_ARROW ? "previous" : "next"](); this[ev.keyCode === _converse.keycodes.UP_ARROW ? "previous" : "next"]();
return false; return true;
} }
} }
...@@ -327,6 +326,7 @@ ...@@ -327,6 +326,7 @@
} }
this.suggestions = this.suggestions.slice(0, this.max_items); this.suggestions = this.suggestions.slice(0, this.max_items);
this.suggestions.forEach((text) => this.ul.appendChild(this.item(text, value))); this.suggestions.forEach((text) => this.ul.appendChild(this.item(text, value)));
this.next();
if (this.ul.children.length === 0) { if (this.ul.children.length === 0) {
this.close({'reason': 'nomatches'}); this.close({'reason': 'nomatches'});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment