最近因工作需要,在项目中使用了CodeMirror代码编辑器,以下是使用笔记。
首先,看下最终的效果
引入基本的需要资源
<script
src="<%=request.getContextPath()%>/resources/js/codemirror/codemirror.js"
type="text/javascript"></script>
<link rel="stylesheet"
href="<%=request.getContextPath()%>/resources/css/codemirror/codemirror.css" />
创建编辑器
var editor = CodeMirror.fromTextArea(document.getElementById('sql'), {
mode : 'sql',
indentWithTabs : true,
lineNumbers : true,
smartIndent : true,
theme : 'dracula',
matchBrackets : true,
line : true,
lineWiseCopyCut : true,
readOnly : false,
showCursorWhenSelecting : true,
extraKeys : {
"Alt" : "autocomplete"
},
styleSelectedText : true
});
在我们的实际