如何禁用 CodeMirror 中的默认插入键行为?

How to disable default Insert key behaviour in CodeMirror?

我正在使用 CodeMirror 进行代码编辑,当我按下 INS(插入键)时,它的行为就像在任何普通文本编辑器中一样,在改写和插入模式之间切换,但我不希望那样。

我希望它像正常一样<textarea>,实际上没有任何变化。

我能以某种方式做到吗?

我没有用过 CodeMirror,但是文档中有一个函数可以切换 overwrite/normal 插入模式 (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).

您可以侦听用户按下 insert 键并覆盖传递给该函数的值以使其保持正常插入模式。