-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display suggestions popover when at-mentioning
- Loading branch information
Showing
6 changed files
with
256 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* Returns the "word" right before a specific position in an input string. | ||
* | ||
* In this context, a word is anything between a space or newline, and provided | ||
* position. | ||
*/ | ||
export function termBeforePosition(text: string, position: number): string { | ||
return text.slice(0, position).match(/\S+$/)?.[0] ?? ''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { termBeforePosition } from '../term-before-position'; | ||
|
||
describe('term-before-position', () => { | ||
// To make these tests more predictable, we place the `$` sign in the position | ||
// to be checked. That way it's easier to see what is the "word" preceding it. | ||
// The test will then get the `$` sign index and remove it from the text | ||
// before passing it to `termBeforePosition`. | ||
[ | ||
// First and last positions | ||
{ | ||
text: '$Hello world', | ||
expectedTerm: '', | ||
}, | ||
{ | ||
text: 'Hello world$', | ||
expectedTerm: 'world', | ||
}, | ||
|
||
// Position in the middle of words | ||
{ | ||
text: 'Hell$o world', | ||
expectedTerm: 'Hell', | ||
}, | ||
{ | ||
text: 'Hello wor$ld', | ||
expectedTerm: 'wor', | ||
}, | ||
|
||
// Position preceded by "empty space" | ||
{ | ||
text: 'Hello $world', | ||
expectedTerm: '', | ||
}, | ||
{ | ||
text: `Text with | ||
multiple | ||
$ | ||
lines | ||
`, | ||
expectedTerm: '', | ||
}, | ||
|
||
// Position preceded by/in the middle of a word for multi-line text | ||
{ | ||
text: `Text with$ | ||
multiple | ||
lines | ||
`, | ||
expectedTerm: 'with', | ||
}, | ||
{ | ||
text: `Text with | ||
multiple | ||
li$nes | ||
`, | ||
expectedTerm: 'li', | ||
}, | ||
].forEach(({ text, expectedTerm }) => { | ||
it('returns the term right before provided position', () => { | ||
// Get the position of the `$` sign in the text, then remove it | ||
const position = text.indexOf('$'); | ||
const textWithoutDollarSign = text.replace('$', ''); | ||
|
||
assert.equal( | ||
termBeforePosition(textWithoutDollarSign, position), | ||
expectedTerm, | ||
); | ||
}); | ||
}); | ||
}); |