I am trying 2 alternatives:
This is my code:>
If you do not want to block highlighting or want to allow user to only copy a limited number of characters :
function anticopy(event: ClipboardEvent) {
// @ts-ignore
const clipboardData = event.originalEvent.clipboardData || window.clipboardData || event.originalEvent.clipboardData;
const txt = window.getSelection().toString() || editor.getWin().getSelection().toString();
if (txt.length > 200) {
const no = 'You cannot copy more than 200 characters.';
clipboardData.setData('text', no);
clipboardData.setData('text/html', `${no}
`);
} else {
const html = ` ${txt}
`;
clipboardData.setData('text', txt);
clipboardData.setData('text/html', html);
}
event.preventDefault();
}