CodeMirrors全屏模式的文档似乎有点稀疏。例如,我如何告诉它听激活全屏的键?或者如何使用按钮切换全屏?
为了给别人带来好处,我发现了解决方案。
答案 0 :(得分:7)
这将获得选项值:
editor.getOption("fullScreen")
这会将全屏选项设置为true:
editor.setOption("fullScreen", true)
(编辑器是您实例化的实例) 这是一个实例化用coffeescript编写的新CodeMirror对象的工作示例:
$(document).ready ->
editor = CodeMirror.fromTextArea(code_area,
name: 'htmlmixed'
htmlMode: true
theme: 'default'
lineNumbers: true
indentUnit: 4
keyMap: 'sublime'
extraKeys:
"Ctrl-Enter": (cm) ->
cm.setOption "fullScreen", !cm.getOption("fullScreen")
return
Esc: (cm) ->
cm.setOption "fullScreen", false
return
)
基于此javascript:
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
lineNumbers: true,
theme: "night",
extraKeys: {
"F11": function(cm) {
cm.setOption("fullScreen", !cm.getOption("fullScreen"));
},
"Esc": function(cm) {
if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false);
}
}
});
从这里采取:https://github.com/marijnh/CodeMirror/blob/master/demo/fullscreen.html