Initial work on showing all options on @

This commit is contained in:
JC Brand 2018-08-14 18:44:08 +02:00
parent b6f5cd2cc9
commit cc3a158b57
4 changed files with 25 additions and 4 deletions

View File

@ -100,7 +100,7 @@
'target': textarea,
'preventDefault': _.noop,
'stopPropagation': _.noop,
'keyCode': 13
'keyCode': 13 // Enter
});
expect(textarea.value).toBe('hello s some2');
@ -123,6 +123,18 @@
view.keyPressed(tab_event);
view.keyUp(tab_event);
expect(textarea.value).toBe('hello z3r0');
// Test that pressing @ brings up all options
const at_event = {
'target': textarea,
'preventDefault': _.noop,
'stopPropagation': _.noop,
'keyCode': 50
};
view.keyPressed(at_event);
view.keyUp(at_event);
textarea.value = 'hello z3r0 and @';
done();
}).catch(_.partial(console.error, _));
}));

View File

@ -74,6 +74,7 @@
_.assignIn(this, {
'match_current_word': false, // Match only the current word, otherwise all input is matched
'match_on_tab': false, // Whether matching should only start when tab's pressed
'trigger_on_at': false, // Whether @ should trigger autocomplete
'min_chars': 2,
'max_items': 10,
'auto_evaluate': true,
@ -294,6 +295,8 @@
if (this.match_on_tab && ev.keyCode === _converse.keycodes.TAB) {
ev.preventDefault();
this.auto_completing = true;
} else if (this.trigger_on_at && ev.keyCode === _converse.keycodes.AT) {
this.auto_completing = true;
}
}
@ -309,10 +312,14 @@
let value = this.input.value;
if (this.match_current_word) {
value = u.getCurrentWord(this.input);
}
}
const list = typeof this._list === "function" ? this._list() : this._list;
if (value.length >= this.min_chars && list.length > 0) {
if (list.length > 0 && (
(value.length >= this.min_chars) ||
(this.trigger_on_at && ev.keyCode === value.startsWith('@'))
)) {
this.index = -1;
// Populate list with options that match
this.ul.innerHTML = "";

View File

@ -117,6 +117,7 @@
UP_ARROW: 38,
DOWN_ARROW: 40,
FORWARD_SLASH: 47,
AT: 50,
META: 91,
META_RIGHT: 93
};

View File

@ -618,7 +618,8 @@
'match_current_word': true,
'match_on_tab': true,
'list': () => this.model.occupants.map(o => ({'label': o.get('nick'), 'value': o.get('nick')})),
'filter': _converse.FILTER_STARTSWITH
'filter': _converse.FILTER_STARTSWITH,
'trigger_on_at': true
});
this.auto_complete.on('suggestion-box-selectcomplete', () => (this.auto_completing = false));
},