Merge remote-tracking branch 'origin/develop' into develop

This commit is contained in:
Weblate 2018-10-25 15:23:21 +00:00
commit 777587827e

View file

@ -573,29 +573,42 @@ export default class MessageComposerInput extends React.Component {
} }
// emojioneify any emoji // emojioneify any emoji
editorState.document.getTexts().forEach(node => { let foundEmoji;
if (node.text !== '' && HtmlUtils.containsEmoji(node.text)) { do {
let match; foundEmoji = false;
while ((match = EMOJI_REGEX.exec(node.text)) !== null) {
const range = Range.create({ for (const node of editorState.document.getTexts()) {
anchor: { if (node.text !== '' && HtmlUtils.containsEmoji(node.text)) {
key: node.key, let match;
offset: match.index, EMOJI_REGEX.lastIndex = 0;
}, while ((match = EMOJI_REGEX.exec(node.text)) !== null) {
focus: { const range = Range.create({
key: node.key, anchor: {
offset: match.index + match[0].length, key: node.key,
}, offset: match.index,
}); },
const inline = Inline.create({ focus: {
type: 'emoji', key: node.key,
data: { emojiUnicode: match[0] }, offset: match.index + match[0].length,
}); },
change = change.insertInlineAtRange(range, inline); });
editorState = change.value; const inline = Inline.create({
type: 'emoji',
data: { emojiUnicode: match[0] },
});
change = change.insertInlineAtRange(range, inline);
editorState = change.value;
// if we replaced an emoji, start again looking for more
// emoji in the new editor state since doing the replacement
// will change the node structure & offsets so we can't compute
// insertion ranges from node.key / match.index anymore.
foundEmoji = true;
break;
}
} }
} }
}); } while (foundEmoji);
// work around weird bug where inserting emoji via the macOS // work around weird bug where inserting emoji via the macOS
// emoji picker can leave the selection stuck in the emoji's // emoji picker can leave the selection stuck in the emoji's