javascriptcodemirror

How to disable default Insert key behaviour in CodeMirror?


I'am using CodeMirror for code editing and when I press INS (insert key) it behaves like in any normal text editor, switching between overtype and insert mode, but I don't want that.

I want it to be like in normal <textarea>, without any change actually.

Can I do that somehow?


Solution

  • I haven't used CodeMirror, but there is a function in the documentation that toggles overwrite/normal insert mode (https://codemirror.net/doc/manual.html#usage):

    cm.toggleOverwrite(?value: boolean)
        Switches between overwrite and normal insert mode (when not given an argument), or sets the overwrite mode to a specific state (when given an argument).
    

    You could listen for the user to press the insert key and override the value passed into that function to make it stay as normal insert mode.