What's the easiest way to limit which lines can be edited?

We have an API which exposes functions. We’d like to have the function signature and opening/closing { } to not be editable. Something like this:

int Add(int a, int b)
{
    // user editable code goes here, but not before or after
}

Option 1: We put the opening and closing lines above and below the editor DIV where CodeMirror runs, and indent the div slightly. This would definitely give the effect we want, but on its own it’s invalid C code as it has no opening/closing braces, and the function parameters aren’t visible. Is there some way to inject the lines before/after?

Option 2: We don’t let the cursor/caret move to line 1 or 2, or last line. This should work, but it seems like it would be visually confusing and maybe take too many cycles?

Option 3?

Thanks,
Brett

Maybe a change filter is what you’re looking for?

Thanks for tip. Would that be a weird user experience where they could put the cursor there and try to edit? Or it’s so immediate that form their perspective the cursor can be in that area but the keys don’t seem to do anything?

I don’t know. Depends on the context, maybe. You can use atomic ranges to prevent the cursor from going to some places.

Ok, I’ll look into that. Since I only care about the first 2 lines and last 1 line, could I use scrollMargins to just stop those lines from scrolling into view too?

No. If you don’t want the lines to show up, don’t put them in the editor? Or hide them with replacing decorations.