-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into chore-migrate-to-hooks-messages-view
- Loading branch information
Showing
76 changed files
with
1,474 additions
and
971 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
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
51 changes: 51 additions & 0 deletions
51
app/containers/MessageComposer/helpers/insertEmojiAtCursor.test.ts
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,51 @@ | ||
import { insertEmojiAtCursor } from './insertEmojiAtCursor'; | ||
|
||
describe('insertEmojiAtCursor', () => { | ||
it('should insert emoji at the beginning of the text', () => { | ||
const result = insertEmojiAtCursor('Hello world', ':test2:', 0); | ||
expect(result).toEqual({ | ||
updatedText: ':test2: Hello world', | ||
updatedCursor: 8 | ||
}); | ||
}); | ||
|
||
it('should insert emoji at the end of the text', () => { | ||
const result = insertEmojiAtCursor('Hello world', ':test2:', 11); | ||
expect(result).toEqual({ | ||
updatedText: 'Hello world :test2:', | ||
updatedCursor: 19 | ||
}); | ||
}); | ||
|
||
it('should insert emoji in the middle of the text with spaces', () => { | ||
const result = insertEmojiAtCursor('Hello world', ':test2:', 5); | ||
expect(result).toEqual({ | ||
updatedText: 'Hello :test2: world', | ||
updatedCursor: 13 | ||
}); | ||
}); | ||
|
||
it('should add a space before the emoji if missing', () => { | ||
const result = insertEmojiAtCursor('Hello', ':test2:', 5); | ||
expect(result).toEqual({ | ||
updatedText: 'Hello :test2:', | ||
updatedCursor: 13 | ||
}); | ||
}); | ||
|
||
it('should add a space after the emoji if missing', () => { | ||
const result = insertEmojiAtCursor('Hello', ':test2:', 0); | ||
expect(result).toEqual({ | ||
updatedText: ':test2: Hello', | ||
updatedCursor: 8 | ||
}); | ||
}); | ||
|
||
it('should not add extra spaces if they are already present', () => { | ||
const result = insertEmojiAtCursor('Hello ', ':test2:', 6); | ||
expect(result).toEqual({ | ||
updatedText: 'Hello :test2:', | ||
updatedCursor: 13 | ||
}); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
app/containers/MessageComposer/helpers/insertEmojiAtCursor.ts
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,18 @@ | ||
export const insertEmojiAtCursor = (text: string, emojiText: string, cursor: number) => { | ||
let updatedCursor = cursor + emojiText.length; | ||
|
||
const firstPart = text.substr(0, cursor); | ||
const lastPart = text.substr(cursor); | ||
|
||
const spaceBefore = firstPart.endsWith(' ') || firstPart.length === 0 ? '' : ' '; | ||
const spaceAfter = lastPart.startsWith(' ') || lastPart.length === 0 ? '' : ' '; | ||
|
||
const updatedText = `${firstPart}${spaceBefore}${emojiText}${spaceAfter}${lastPart}`; | ||
updatedCursor += spaceBefore ? 1 : 0; | ||
updatedCursor += spaceAfter ? 1 : 0; | ||
|
||
return { | ||
updatedCursor, | ||
updatedText | ||
}; | ||
}; |
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
Oops, something went wrong.