Browse Source

fix: add space when inserting emoji

closed-social-glitch-2
欧醚 1 year ago
parent
commit
2dbd322760
1 changed files with 6 additions and 3 deletions
  1. +6
    -3
      app/javascript/flavours/glitch/reducers/compose.js

+ 6
- 3
app/javascript/flavours/glitch/reducers/compose.js View File

@ -293,12 +293,15 @@ const sortHashtagsByUse = (state, tags) => {
}; };
const insertEmoji = (state, position, emojiData) => { const insertEmoji = (state, position, emojiData) => {
const emoji = emojiData.native;
const oldText = state.get('text');
const needSpaceBefore = ![undefined, ' ', '\n'].includes(oldText[position - 1]);
const needSpaceAfter = ![' ', '\n'].includes(oldText[position]);
const emoji = `${needSpaceBefore ? ' ' : ''}${emojiData.native}${needSpaceAfter ? ' ' : ''}`;
return state.withMutations(map => { return state.withMutations(map => {
map.update('text', oldText => `${oldText.slice(0, position)}${emoji}\u200B${oldText.slice(position)}`);
map.update('text', oldText => `${oldText.slice(0, position)}${emoji}${oldText.slice(position)}`);
map.set('focusDate', new Date()); map.set('focusDate', new Date());
map.set('caretPosition', position + emoji.length + 1);
map.set('caretPosition', position + emoji.length);
map.set('idempotencyKey', uuid()); map.set('idempotencyKey', uuid());
}); });
}; };

Loading…
Cancel
Save