Skip to content

Commit

Permalink
Fixed current format being lost on an inserted emoji
Browse files Browse the repository at this point in the history
no issue

- apply the current selection's format to the newly inserted emoji to avoid formatting ending and restarting around the emoji
  • Loading branch information
kevinansfield committed Nov 1, 2023
1 parent 6686422 commit 79adedf
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/koenig-lexical/src/plugins/EmojiPickerPlugin.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ export function EmojiPickerPlugin() {
}

const currentNode = selection.anchor.getNode();

// need to replace the last text matching the :test: pattern with a single emoji
const shortcodeLength = emoji.id.length + 1; // +1 for the end colon
currentNode.spliceText(selection.anchor.offset - shortcodeLength, shortcodeLength, emoji.skins[0].native, true);
const textNode = currentNode.spliceText(selection.anchor.offset - shortcodeLength, shortcodeLength, emoji.skins[0].native, true);
textNode.setFormat(selection.format);
});
}, [editor]);

Expand Down Expand Up @@ -118,7 +118,10 @@ export function EmojiPickerPlugin() {
nodeToRemove.remove();
}

selection.insertNodes([$createTextNode(selectedOption.skins[0].native)]);
const emojiNode = $createTextNode(selectedOption.skins[0].native);
emojiNode.setFormat(selection.format);

selection.insertNodes([emojiNode]);

closeMenu();
});
Expand Down

0 comments on commit 79adedf

Please sign in to comment.