I’m trying to add a transactionFilter
that will create a markdown link with the selected text during a paste event. What would be the proper way to get the selected text and the pasted text? I think that I’ve got the selected text figured out, but I’m not sure about the pasted text. This is what I’ve got so far:
function pasteTransactionFilter(t: Transaction): TransactionSpec {
if (t.isUserEvent("input.paste")) {
const {startState} = t;
const {from, to} = startState.selection.ranges[0];
const selectedText = startState.sliceDoc(from, to);
return startState.replaceSelection(
`[${selectedText}](${t.changes.inserted.at(-1)})`
);
}
return t;
}