CodeMirror 只读允许从键盘快捷键和鼠标右键单击选项粘贴
CodeMirror readOnly allow paste from keyboard shortcut and mouse right click option
我正在开发一个应用程序,目的是教 class 学生使用 codemirror 插件。我遇到的问题是,我不希望学生能够更改我在编辑器中为他们显示的代码,所以我遵循文档并将 readOnly
属性 设置为 true,这确实禁用了他们的打字能力。但是一些聪明的学生发现他可以使用 CTRL + V 或单击鼠标右键并从中选择 paste
来粘贴一些东西到编辑器。你知道如何结束这种情况吗?
这是一个实例:
var appCM = CodeMirror.fromTextArea(document.getElementById('app-cm'), {
mode: 'text/html',
theme: "monokai",
styleActiveLine: true,
lineNumbers: true,
matchBrackets: true,
indentUnit: 4,
indentWithTabs: true,
autoCloseTags: true,
autoCloseBrackets: true,
matchTags: false,
extraKeys: {
"Ctrl-Space": "autocomplete",
"Ctrl-Q": function(appCM) {
appCM.foldCode(appCM.getCursor());
}
},
foldGutter: true,
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
readOnly: true
});
我一直在阅读这篇文章,但我没有找到任何有用的东西
这是 5.5 版中的一个错误,几天前已修复(参见 this bug report)。您可以获取当前开发,手动应用从该问题链接的补丁,或等待下一个版本。
我正在开发一个应用程序,目的是教 class 学生使用 codemirror 插件。我遇到的问题是,我不希望学生能够更改我在编辑器中为他们显示的代码,所以我遵循文档并将 readOnly
属性 设置为 true,这确实禁用了他们的打字能力。但是一些聪明的学生发现他可以使用 CTRL + V 或单击鼠标右键并从中选择 paste
来粘贴一些东西到编辑器。你知道如何结束这种情况吗?
这是一个实例:
var appCM = CodeMirror.fromTextArea(document.getElementById('app-cm'), {
mode: 'text/html',
theme: "monokai",
styleActiveLine: true,
lineNumbers: true,
matchBrackets: true,
indentUnit: 4,
indentWithTabs: true,
autoCloseTags: true,
autoCloseBrackets: true,
matchTags: false,
extraKeys: {
"Ctrl-Space": "autocomplete",
"Ctrl-Q": function(appCM) {
appCM.foldCode(appCM.getCursor());
}
},
foldGutter: true,
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
readOnly: true
});
我一直在阅读这篇文章,但我没有找到任何有用的东西
这是 5.5 版中的一个错误,几天前已修复(参见 this bug report)。您可以获取当前开发,手动应用从该问题链接的补丁,或等待下一个版本。