Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #6823 from SimonBrandner/fix/emoji-dupe/19073
Browse files Browse the repository at this point in the history
Fix last character duplication with `Automatically replace plain text emoji` on
  • Loading branch information
turt2live authored Sep 17, 2021
2 parents b91ece1 + 9a2d61b commit 05971e0
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/components/views/rooms/BasicMessageComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,18 @@ export default class BasicMessageEditor extends React.Component<IProps, IState>

if (data) {
const { partCreator } = model;
const moveStart = emoticonMatch[0][0] === " " ? 1 : 0;
const moveEnd = emoticonMatch[0].length - emoticonMatch.length - moveStart;
const firstMatch = emoticonMatch[0];
const moveStart = firstMatch[0] === " " ? 1 : 0;

// we need the range to only comprise of the emoticon
// because we'll replace the whole range with an emoji,
// so move the start forward to the start of the emoticon.
// Take + 1 because index is reported without the possible preceding space.
range.moveStartForwards(emoticonMatch.index + moveStart);
// and move end backwards so that we don't replace the trailing space/newline
range.moveEndBackwards(moveEnd);
// If the end is a trailing space/newline move end backwards, so that we don't replace it
if (["\n", " "].includes(firstMatch[firstMatch.length - 1])) {
range.moveEndBackwards(1);
}

// this returns the amount of added/removed characters during the replace
// so the caret position can be adjusted.
Expand Down

0 comments on commit 05971e0

Please sign in to comment.