Merge remote-tracking branch 'upstream/develop' into task/dialogs-ts

This commit is contained in:
Šimon Brandner 2021-09-17 18:41:03 +02:00
commit 3428d83b23
No known key found for this signature in database
GPG key ID: 55C211A1226CB17D

View file

@ -181,16 +181,18 @@ export default class BasicMessageEditor extends React.Component<IProps, IState>
if (data) { if (data) {
const { partCreator } = model; const { partCreator } = model;
const moveStart = emoticonMatch[0][0] === " " ? 1 : 0; const firstMatch = emoticonMatch[0];
const moveEnd = emoticonMatch[0].length - emoticonMatch.length - moveStart; const moveStart = firstMatch[0] === " " ? 1 : 0;
// we need the range to only comprise of the emoticon // we need the range to only comprise of the emoticon
// because we'll replace the whole range with an emoji, // because we'll replace the whole range with an emoji,
// so move the start forward to the start of the emoticon. // so move the start forward to the start of the emoticon.
// Take + 1 because index is reported without the possible preceding space. // Take + 1 because index is reported without the possible preceding space.
range.moveStartForwards(emoticonMatch.index + moveStart); range.moveStartForwards(emoticonMatch.index + moveStart);
// and move end backwards so that we don't replace the trailing space/newline // If the end is a trailing space/newline move end backwards, so that we don't replace it
range.moveEndBackwards(moveEnd); if (["\n", " "].includes(firstMatch[firstMatch.length - 1])) {
range.moveEndBackwards(1);
}
// this returns the amount of added/removed characters during the replace // this returns the amount of added/removed characters during the replace
// so the caret position can be adjusted. // so the caret position can be adjusted.