mirror of
https://github.com/zulip/zulip.git
synced 2025-11-01 12:33:40 +00:00
composebox_typeahead: Extract autocomplete_checks.
This commit is contained in:
@@ -174,6 +174,23 @@ function select_on_focus(field_id) {
|
||||
});
|
||||
}
|
||||
|
||||
function autocomplete_checks(q, char) {
|
||||
// Don't autocomplete more than this many characters.
|
||||
var max_chars = 30;
|
||||
var last_at = q.lastIndexOf(char);
|
||||
if (last_at === -1 || last_at < q.length-1 - max_chars) {
|
||||
return false; // char doesn't appear, or too far back
|
||||
}
|
||||
|
||||
// Only match if the char follows a space, various punctuation,
|
||||
// or is at the beginning of the string.
|
||||
if (last_at > 0 && "\n\t \"'(){}[]".indexOf(q[last_at-1]) === -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
exports.split_at_cursor = function (query, input) {
|
||||
var cursor = input.caret();
|
||||
return [query.slice(0, cursor), query.slice(cursor)];
|
||||
@@ -207,19 +224,11 @@ exports.compose_content_begins_typeahead = function (query) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Don't autocomplete more than this many characters.
|
||||
var max_chars = 30;
|
||||
var last_at = q.lastIndexOf('@');
|
||||
if (last_at === -1 || last_at < q.length-1 - max_chars) {
|
||||
return false; // No '@', or too far back
|
||||
}
|
||||
|
||||
// Only match if the @ follows a space, various punctuation,
|
||||
// or is at the beginning of the string.
|
||||
if (last_at > 0 && "\n\t \"'(){}[]".indexOf(q[last_at-1]) === -1) {
|
||||
if (!autocomplete_checks(q, '@')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var last_at = q.lastIndexOf('@');
|
||||
current_token = q.substring(last_at + 1);
|
||||
if (current_token.length < 1 || current_token.lastIndexOf('*') !== -1) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user