Skip to content

Commit 8f917b1

Browse files
authored
Merge pull request #1722 from codidact/0valt/1673/ping-autocomplete
Start comment @-mention autocomplete as soon as at least 1 username char is entered
2 parents d11d22f + 019d99c commit 8f917b1

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

app/assets/javascripts/comments.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,12 @@ $(() => {
267267
$tgt.focus();
268268
};
269269

270-
// If the word the caret is currently in starts with an @, and has at least 3 characters after that, assume it's
271-
// an attempt to ping another user with a username, and kick off suggestions -- unless it starts with @#, in which
272-
// case it's likely an already-selected ping.
273-
if (currentWord.startsWith('@') && !currentWord.startsWith('@#') && currentWord.length >= 4) {
270+
// at least 1 character has to be present to trigger autocomplete (2 is because pings start with @)
271+
const hasReachedAutocompleteThreshold = currentWord.length >= 2;
272+
273+
// If the word the caret is currently in starts with an @, and is reached the autocomplete threshold, assume it's
274+
// a ping attempt and kick off suggestions (unless it starts with @#, meaning it's likely an already-selected ping)
275+
if (currentWord.startsWith('@') && !currentWord.startsWith('@#') && hasReachedAutocompleteThreshold) {
274276
const threadId = $tgt.data('thread');
275277
const postId = $tgt.data('post');
276278

0 commit comments

Comments
 (0)