Sublime Forum

Making a scope read-only

#1

Is it possible to mark a region with a scope and disable all edits for that scope?
I can think of creating a keymap that remaps every key to a no-op when the context matches this special scope, but that would not be easy to maintain and error-prone.
Is there an “idiomatic” way of doing this?

0 Likes

#2

You could bind a key on <character> which would handle all direct inputs, then maybe create an EventListener which will intercept commands (iirc it’s the on_pre_command method - no time to look it up right now, sorry) - the tricky thing there would be blocking only commands that alter the buffer.
An alternative could be to automatically undo any changes made while the caret was within that scope, though its always possible a command could i.e. append text to the end of the file, which may not have that scope to which you want the read-only logic applied.
I’m not sure there is a truly idiomatic solution, it may not have been done before

0 Likes