Skip to content

Commit

Permalink
refactor(PastePlugin): improve mention validation logic by consolidat…
Browse files Browse the repository at this point in the history
…ing conditions for username checks
  • Loading branch information
olafsulich committed Jan 15, 2025
1 parent c7fcbf6 commit 8aae236
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,17 @@ export const PastePlugin = ({getMentionCandidates}: PastePluginProps): JSX.Eleme
// Process mentions in the DOM before generating nodes
lexicalMentions.forEach(mention => {
const {isValid, username} = validateMention(mention, availableUsers);
if (!username) {
if (!username || isValid) {
return;
}

if (!isValid) {
const textNode = doc.createTextNode(`@${username}`);
const parent = mention.parentNode;
if (!parent) {
return;
}
parent.replaceChild(textNode, mention);
const parent = mention.parentNode;
if (!parent) {
return;
}

const textNode = doc.createTextNode(`@${username}`);
parent.replaceChild(textNode, mention);
});

const nodes = $generateNodesFromDOM(editor, doc);
Expand Down

0 comments on commit 8aae236

Please sign in to comment.