Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ internal class TypingSuggester(private val options: TypingSuggestionOptions) {
return null
}

// Only show typing suggestions after a space, or at the start of the input
// valid examples: "@user", "Hello @user"
// invalid examples: "Hello@user"
val isValidPosition = firstSymbolBeforeCaret == 0 || text[firstSymbolBeforeCaret - 1].isWhitespace()
// The symbol must not be glued to a letter or digit.
// valid: "@user", "Hello @user", "@user,@user2"
// invalid: "Hello@user"
val charBeforeSymbol = text.getOrNull(firstSymbolBeforeCaret - 1)
val isValidPosition = charBeforeSymbol?.isLetterOrDigit() != true
if (!isValidPosition) {
return null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ internal class TypingSuggesterTest {
Arguments.of("@ ", null),
Arguments.of("@ john", null),
Arguments.of("Hello@john", null),
Arguments.of("@john,@jane", TypingSuggestion("jane", 7 until 11)),
Arguments.of("@john, @jane", TypingSuggestion("jane", 8 until 12)),
Arguments.of("(@john", TypingSuggestion("john", 2 until 6)),
Arguments.of("john@example.com", null),
)
}
}
Loading