Fixed particular lines for read only

Hi, I would like to have a codemirror editor that the first 3 lines are read-only, and the last line is also read-only.
Users can input the code in the middle as many lines as they want.
but they can not remove the first 3 lines and the last line.
Can anyone tell me how to do that?

many thanks!

The way to implement something like that is the "beforeChange" event, which allows you to filter and block changes as they happen.

Check the answer below. There is an extension that easily handles with read-only ranges on CodeMirror6.

Great, thank you for your contributing!

1 Like