-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0efffbb
commit 6d53198
Showing
4 changed files
with
46 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,52 @@ | ||
import { Plugin } from 'prosemirror-state'; | ||
|
||
/** | ||
* Provides a feature to unmention when text with mention formatting is partially deleted. | ||
*/ | ||
export const edimMentionUnsetPlugins = () => { | ||
const mentionPlugin: Plugin = | ||
new Plugin({ | ||
appendTransaction: (transactions, oldState, newState) => { | ||
const tr = newState.tr; | ||
let modified = false; | ||
const mentionPlugin: Plugin = new Plugin({ | ||
appendTransaction: (transactions, oldState, newState) => { | ||
const tr = newState.tr; | ||
let modified = false; | ||
|
||
if (!transactions.some((transaction) => transaction.docChanged)) { | ||
if (!transactions.some((transaction) => transaction.docChanged)) { | ||
return; | ||
} | ||
|
||
newState.doc.descendants((node, pos) => { | ||
const hasMention = node.marks.some( | ||
(mark) => mark.type.name === 'mention', | ||
); | ||
if (!node.isText || !hasMention) { | ||
return; | ||
} | ||
|
||
newState.doc.descendants((node, pos) => { | ||
const hasMention = node.marks.some( | ||
try { | ||
const oldNode = oldState.doc.nodeAt(pos); | ||
const oldNodeHasMention = oldNode?.marks.some( | ||
(mark) => mark.type.name === 'mention', | ||
); | ||
if (!node.isText || !hasMention) { | ||
return; | ||
} | ||
try { | ||
const oldNode = oldState.doc.nodeAt(pos); | ||
const oldNodeHasMention = oldNode?.marks.some( | ||
(mark) => mark.type.name === 'mention', | ||
); | ||
|
||
if ( | ||
oldNode && | ||
oldNodeHasMention && | ||
oldNode.isText && | ||
node.text !== oldNode.text | ||
) { | ||
tr.removeMark( | ||
pos, | ||
pos + node.nodeSize, | ||
newState.schema.marks['mention'], | ||
); | ||
modified = true; | ||
} | ||
} catch (error) { | ||
console.warn('mention not found'); | ||
if ( | ||
oldNode && | ||
oldNodeHasMention && | ||
oldNode.isText && | ||
node.text !== oldNode.text | ||
) { | ||
tr.removeMark( | ||
pos, | ||
pos + node.nodeSize, | ||
newState.schema.marks['mention'], | ||
); | ||
modified = true; | ||
} | ||
}); | ||
} catch (error) { | ||
console.warn('mention not found'); | ||
} | ||
}); | ||
|
||
return modified ? tr : null; | ||
}, | ||
}); | ||
return modified ? tr : null; | ||
}, | ||
}); | ||
|
||
return [mentionPlugin]; | ||
}; |