Commit cc3a158b authored by JC Brand's avatar JC Brand

Initial work on showing all options on @

parent b6f5cd2c
...@@ -100,7 +100,7 @@ ...@@ -100,7 +100,7 @@
'target': textarea, 'target': textarea,
'preventDefault': _.noop, 'preventDefault': _.noop,
'stopPropagation': _.noop, 'stopPropagation': _.noop,
'keyCode': 13 'keyCode': 13 // Enter
}); });
expect(textarea.value).toBe('hello s some2'); expect(textarea.value).toBe('hello s some2');
...@@ -123,6 +123,18 @@ ...@@ -123,6 +123,18 @@
view.keyPressed(tab_event); view.keyPressed(tab_event);
view.keyUp(tab_event); view.keyUp(tab_event);
expect(textarea.value).toBe('hello z3r0'); 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(); done();
}).catch(_.partial(console.error, _)); }).catch(_.partial(console.error, _));
})); }));
......
...@@ -74,6 +74,7 @@ ...@@ -74,6 +74,7 @@
_.assignIn(this, { _.assignIn(this, {
'match_current_word': false, // Match only the current word, otherwise all input is matched '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 'match_on_tab': false, // Whether matching should only start when tab's pressed
'trigger_on_at': false, // Whether @ should trigger autocomplete
'min_chars': 2, 'min_chars': 2,
'max_items': 10, 'max_items': 10,
'auto_evaluate': true, 'auto_evaluate': true,
...@@ -294,6 +295,8 @@ ...@@ -294,6 +295,8 @@
if (this.match_on_tab && ev.keyCode === _converse.keycodes.TAB) { if (this.match_on_tab && ev.keyCode === _converse.keycodes.TAB) {
ev.preventDefault(); ev.preventDefault();
this.auto_completing = true; this.auto_completing = true;
} else if (this.trigger_on_at && ev.keyCode === _converse.keycodes.AT) {
this.auto_completing = true;
} }
} }
...@@ -309,10 +312,14 @@ ...@@ -309,10 +312,14 @@
let value = this.input.value; let value = this.input.value;
if (this.match_current_word) { if (this.match_current_word) {
value = u.getCurrentWord(this.input); value = u.getCurrentWord(this.input);
} }
const list = typeof this._list === "function" ? this._list() : this._list; 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; this.index = -1;
// Populate list with options that match // Populate list with options that match
this.ul.innerHTML = ""; this.ul.innerHTML = "";
......
...@@ -117,6 +117,7 @@ ...@@ -117,6 +117,7 @@
UP_ARROW: 38, UP_ARROW: 38,
DOWN_ARROW: 40, DOWN_ARROW: 40,
FORWARD_SLASH: 47, FORWARD_SLASH: 47,
AT: 50,
META: 91, META: 91,
META_RIGHT: 93 META_RIGHT: 93
}; };
......
...@@ -618,7 +618,8 @@ ...@@ -618,7 +618,8 @@
'match_current_word': true, 'match_current_word': true,
'match_on_tab': true, 'match_on_tab': true,
'list': () => this.model.occupants.map(o => ({'label': o.get('nick'), 'value': o.get('nick')})), '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)); this.auto_complete.on('suggestion-box-selectcomplete', () => (this.auto_completing = false));
}, },
......
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