Limit on the number of characters entered
Hello! Thanks for this great project!
It's not so clear how to set a limit on the number of characters entered? Isn’t there any built-in solution? Simple example: https://codesandbox.io/s/react-codemirror-example-codemirror-6-forked-kylrmk?file=/src/App.tsx
Thanks a lot.
@Nonsmokers https://discuss.codemirror.net/t/how-to-enable-and-disable-specific-lines-in-v6/4521
@Nonsmokers https://discuss.codemirror.net/t/content-length-limit-codemirror6/4183/3
function lengthLimit(tr: Transaction): boolean {
return (tr.startState?.doc?.length + tr.newDoc.length) < 200;
}
function lengthLimit(tr: Transaction): boolean { return (tr.startState?.doc?.length + tr.newDoc.length) < 200; }
Thanks for the answer, works correctly, but if you insert a value and it is more than the given limit (for example: 97 characters entered and paste 4 characters -> 101/100), the editor becomes uneditable.