It was discussed here, for CM5: About the character length of codemirror input limit
Is there a good way to limit the total characters in CM6?
It was discussed here, for CM5: About the character length of codemirror input limit
Is there a good way to limit the total characters in CM6?
Yes, use a changeFilter
to block changes that take the document length over the limit.
Thanks.
I feel like there is a better way to do this. Any tips?
function lengthLimit(tr: Transaction): boolean {
return (tr.startState?.doc?.length + tr.changes?.inserted?.length) < MAX_LENGTH;
}
Yeah, that’s not correct (changes.inserted
is some internal array, and its length is the amount of inserted ranges, not their total length). But tr.newDoc.length < MAX_LENGTH
should work.
Thank you. I appreciate the help.