Skip to content

Commit

Permalink
Merge pull request Expensify#42985 from bernhardoj/fix/42664-cursor-m…
Browse files Browse the repository at this point in the history
…oves-back-one-char

Fix the cursor moves one space backward when inserting text after an emoji
  • Loading branch information
MonilBhavsar authored Jun 6, 2024
2 parents 21e1901 + 99d401e commit 4c86fbf
Showing 1 changed file with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -414,11 +414,8 @@ function ComposerWithSuggestions(
raiseIsScrollLikelyLayoutTriggered();
const {startIndex, endIndex, diff} = findNewlyAddedChars(lastTextRef.current, commentValue);
const isEmojiInserted = diff.length && endIndex > startIndex && diff.trim() === diff && EmojiUtils.containsOnlyEmojis(diff);
const {
text: newComment,
emojis,
cursorPosition,
} = EmojiUtils.replaceAndExtractEmojis(isEmojiInserted ? ComposerUtils.insertWhiteSpaceAtIndex(commentValue, endIndex) : commentValue, preferredSkinTone, preferredLocale);
const commentWithSpaceInserted = isEmojiInserted ? ComposerUtils.insertWhiteSpaceAtIndex(commentValue, endIndex) : commentValue;
const {text: newComment, emojis, cursorPosition} = EmojiUtils.replaceAndExtractEmojis(commentWithSpaceInserted, preferredSkinTone, preferredLocale);
if (emojis.length) {
const newEmojis = EmojiUtils.getAddedEmojis(emojis, emojisPresentBefore.current);
if (newEmojis.length) {
Expand All @@ -443,7 +440,7 @@ function ComposerWithSuggestions(
if (commentValue !== newComment) {
const position = Math.max(selection.end + (newComment.length - commentRef.current.length), cursorPosition ?? 0);

if (isIOSNative) {
if (commentWithSpaceInserted !== newComment && isIOSNative) {
syncSelectionWithOnChangeTextRef.current = {position, value: newComment};
}

Expand Down

0 comments on commit 4c86fbf

Please sign in to comment.